Feat: Informe de Ventas Por Usuario
This commit is contained in:
parent
f05acd6484
commit
535befbf4b
@ -16,6 +16,7 @@ def register():
|
||||
production.Production,
|
||||
report_close_statement.ReportCloseStatementStart,
|
||||
report.ReportSaleProduct,
|
||||
report.ReportSaleByUser,
|
||||
report.ReportSaleContext,
|
||||
module='sale_fast_food', type_='model')
|
||||
Pool.register(
|
||||
|
32
locale/es.po
32
locale/es.po
@ -74,6 +74,14 @@ msgctxt "model:ir.ui.menu,name:menu_sale_fast_food_pizza"
|
||||
msgid "Pizzas Sold by Product"
|
||||
msgstr "Pizzas Vendidas Por Producto"
|
||||
|
||||
msgctxt "model:ir.action,name:act_report_sale_fast_food_by_user"
|
||||
msgid "Sales by User"
|
||||
msgstr "Ventas Por Usuario"
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:menu_sale_fast_food_by_user"
|
||||
msgid "Sales by User"
|
||||
msgstr "Ventas Por Usuario"
|
||||
|
||||
msgctxt "field:sale_fast_food.reporting.product,product_pizza:"
|
||||
msgid "Product"
|
||||
msgstr "Pizza"
|
||||
@ -82,6 +90,30 @@ msgctxt "field:sale_fast_food.reporting.product,quantity:"
|
||||
msgid "Quantity"
|
||||
msgstr "Cantidad"
|
||||
|
||||
msgctxt "field:sale_fast_food.reporting.by_user,user:"
|
||||
msgid "User"
|
||||
msgstr "Usuario"
|
||||
|
||||
msgctxt "field:sale_fast_food.reporting.by_user,completed_sales:"
|
||||
msgid "Completed Sales"
|
||||
msgstr "# Ventas"
|
||||
|
||||
msgctxt "field:sale_fast_food.reporting.by_user,untaxed_amount:"
|
||||
msgid "Untaxed Amount"
|
||||
msgstr "Base Imponible"
|
||||
|
||||
msgctxt "field:sale_fast_food.reporting.by_user,tax_amount:"
|
||||
msgid "Tax Amount"
|
||||
msgstr "Impuestos"
|
||||
|
||||
msgctxt "field:sale_fast_food.reporting.by_user,total_amount:"
|
||||
msgid "Total Amount"
|
||||
msgstr "Total"
|
||||
|
||||
msgctxt "field:sale_fast_food.reporting.by_user,total_tip_amount:"
|
||||
msgid "Total Tip Amount"
|
||||
msgstr "Propinas"
|
||||
|
||||
msgctxt "wizard_button:sale.print_cash_register,start,end:"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancelar"
|
||||
|
59
report.py
59
report.py
@ -2,7 +2,7 @@ from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import If, Eval
|
||||
from sql import Literal, Null
|
||||
from sql.aggregate import Min, Sum
|
||||
from sql.aggregate import Min, Sum, Count
|
||||
from sql.functions import CurrentTimestamp
|
||||
from trytond.transaction import Transaction
|
||||
import datetime
|
||||
@ -149,3 +149,60 @@ class ReportSaleProduct(ReportSaleAbstract, ModelView):
|
||||
where &= product_template.pizza == Literal(True)
|
||||
|
||||
return where
|
||||
|
||||
|
||||
class ReportSaleByUser(ReportSaleAbstract, ModelView):
|
||||
"""Report Sale Group by User"""
|
||||
__name__ = 'sale_fast_food.reporting.by_user'
|
||||
|
||||
user = fields.Many2One('res.user', "User")
|
||||
completed_sales = fields.Integer("Completed Sales")
|
||||
untaxed_amount = fields.Numeric(
|
||||
"Untaxed Amount", digits='currency', readonly=True)
|
||||
tax_amount = fields.Numeric(
|
||||
"Tax Amount", digits='currency', readonly=True)
|
||||
total_amount = fields.Numeric(
|
||||
"Total Amount", digits='currency', readonly=True)
|
||||
total_tip_amount = fields.Numeric(
|
||||
"Total Tip Amount", digits='currency', readonly=True)
|
||||
currency = fields.Many2One(
|
||||
'currency.currency', 'Currency', required=True)
|
||||
|
||||
@classmethod
|
||||
def _joins(cls):
|
||||
pool = Pool()
|
||||
tables = {}
|
||||
|
||||
Sale = pool.get('sale.sale')
|
||||
tables['sale.sale'] = sale = Sale.__table__()
|
||||
|
||||
from_item = sale
|
||||
|
||||
return from_item, tables
|
||||
|
||||
@classmethod
|
||||
def _columns(cls, tables):
|
||||
sale = tables['sale.sale']
|
||||
return super(ReportSaleByUser, cls)._columns(tables) + [
|
||||
sale.create_uid.as_('user'),
|
||||
Count(Literal(1)).as_('completed_sales'),
|
||||
Sum(sale.untaxed_amount_cache).as_('untaxed_amount'),
|
||||
Sum(sale.tax_amount_cache).as_('tax_amount'),
|
||||
Sum(sale.total_amount_cache).as_('total_amount'),
|
||||
Sum(sale.total_tip_cache).as_('total_tip_amount'),
|
||||
sale.currency.as_('currency'),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _group_by(cls, tables):
|
||||
sale = tables['sale.sale']
|
||||
|
||||
return [
|
||||
sale.create_uid,
|
||||
sale.currency
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _column_id(cls, tables):
|
||||
sale = tables['sale.sale']
|
||||
return Min(sale.id)
|
||||
|
33
report.xml
33
report.xml
@ -9,7 +9,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="name">sale_fast_food_report_context_form</field>
|
||||
</record>
|
||||
|
||||
<!-- Family Members Per State -->
|
||||
<!-- Report by Product-->
|
||||
<record model="ir.ui.view" id="report_sale_fast_food_product_pizza_view_list">
|
||||
<field name="model">sale_fast_food.reporting.product</field>
|
||||
<field name="type">tree</field>
|
||||
@ -27,16 +27,47 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="view" ref="report_sale_fast_food_product_pizza_view_list"/>
|
||||
<field name="act_window" ref="act_report_sale_fast_food_product_pizza"/>
|
||||
</record>
|
||||
|
||||
<!-- Report by Product-->
|
||||
<record model="ir.ui.view" id="report_sale_fast_food_by_user_view_list">
|
||||
<field name="model">sale_fast_food.reporting.by_user</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">sales_by_user_list</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_report_sale_fast_food_by_user">
|
||||
<field name="name">Sales by User</field>
|
||||
<field name="res_model">sale_fast_food.reporting.by_user</field>
|
||||
<field name="context_model">sale_fast_food.report.context</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window.view" id="act_report_sale_fast_food_by_user_view1">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="report_sale_fast_food_by_user_view_list"/>
|
||||
<field name="act_window" ref="act_report_sale_fast_food_by_user"/>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Pizzas Sold by Product"
|
||||
parent="sale.menu_reporting"
|
||||
sequence="10"
|
||||
id="menu_sale_fast_food_pizza"
|
||||
icon="tryton-graph"/>
|
||||
<menuitem
|
||||
name="Sales by User"
|
||||
parent="sale.menu_reporting"
|
||||
sequence="20"
|
||||
id="menu_sale_fast_food_by_user"
|
||||
icon="tryton-graph"/>
|
||||
<record model="ir.action.keyword" id="act_report_sale_fast_food_product_pizza_keyword1">
|
||||
<field name="keyword">tree_open</field>
|
||||
<field name="model" ref="menu_sale_fast_food_pizza"/>
|
||||
<field name="action" ref="act_report_sale_fast_food_product_pizza"/>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="act_report_sale_fast_food_by_user_keyword1">
|
||||
<field name="keyword">tree_open</field>
|
||||
<field name="model" ref="menu_sale_fast_food_by_user"/>
|
||||
<field name="action" ref="act_report_sale_fast_food_by_user"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
@ -205,3 +205,17 @@ Sale Fast Food Pizzas Sell by Product::
|
||||
|
||||
>>> actual_report = {(r.product_pizza, r.quantity) for r in reports}
|
||||
>>> assert expected_report == actual_report, f"\n Expect: {expected_report} \n Actual: {actual_report}"
|
||||
|
||||
Sale Fast Food Sales by User::
|
||||
>>> User = Model.get('res.user')
|
||||
>>> user = User(config.user)
|
||||
|
||||
>>> ReportSalesByUser = Model.get('sale_fast_food.reporting.by_user')
|
||||
>>> reports = ReportSalesByUser.find([])
|
||||
|
||||
>>> expected_report = {
|
||||
... (user, 1)
|
||||
... }
|
||||
|
||||
>>> actual_report = {(r.user, r.completed_sales) for r in reports}
|
||||
>>> assert expected_report == actual_report, f"\n Expect: {expected_report} \n Actual: {actual_report}"
|
||||
|
11
view/sales_by_user_list.xml
Normal file
11
view/sales_by_user_list.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree>
|
||||
<field name="user"/>
|
||||
<field name="completed_sales" sum="1"/>
|
||||
<field name="untaxed_amount" sum="1"/>
|
||||
<field name="tax_amount" sum="1"/>
|
||||
<field name="total_amount" sum="1"/>
|
||||
<field name="total_tip_amount" sum="1"/>
|
||||
</tree>
|
Loading…
Reference in New Issue
Block a user