Feat: Informe de Ventas Por Usuario

This commit is contained in:
sinergia 2024-10-21 12:16:07 -05:00
parent f05acd6484
commit 535befbf4b
6 changed files with 149 additions and 3 deletions

View File

@ -16,6 +16,7 @@ def register():
production.Production, production.Production,
report_close_statement.ReportCloseStatementStart, report_close_statement.ReportCloseStatementStart,
report.ReportSaleProduct, report.ReportSaleProduct,
report.ReportSaleByUser,
report.ReportSaleContext, report.ReportSaleContext,
module='sale_fast_food', type_='model') module='sale_fast_food', type_='model')
Pool.register( Pool.register(

View File

@ -74,6 +74,14 @@ msgctxt "model:ir.ui.menu,name:menu_sale_fast_food_pizza"
msgid "Pizzas Sold by Product" msgid "Pizzas Sold by Product"
msgstr "Pizzas Vendidas Por Producto" 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:" msgctxt "field:sale_fast_food.reporting.product,product_pizza:"
msgid "Product" msgid "Product"
msgstr "Pizza" msgstr "Pizza"
@ -82,6 +90,30 @@ msgctxt "field:sale_fast_food.reporting.product,quantity:"
msgid "Quantity" msgid "Quantity"
msgstr "Cantidad" 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:" msgctxt "wizard_button:sale.print_cash_register,start,end:"
msgid "Cancel" msgid "Cancel"
msgstr "Cancelar" msgstr "Cancelar"

View File

@ -2,7 +2,7 @@ from trytond.model import ModelSQL, ModelView, fields
from trytond.pool import Pool from trytond.pool import Pool
from trytond.pyson import If, Eval from trytond.pyson import If, Eval
from sql import Literal, Null from sql import Literal, Null
from sql.aggregate import Min, Sum from sql.aggregate import Min, Sum, Count
from sql.functions import CurrentTimestamp from sql.functions import CurrentTimestamp
from trytond.transaction import Transaction from trytond.transaction import Transaction
import datetime import datetime
@ -149,3 +149,60 @@ class ReportSaleProduct(ReportSaleAbstract, ModelView):
where &= product_template.pizza == Literal(True) where &= product_template.pizza == Literal(True)
return where 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)

View File

@ -9,7 +9,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">sale_fast_food_report_context_form</field> <field name="name">sale_fast_food_report_context_form</field>
</record> </record>
<!-- Family Members Per State --> <!-- Report by Product-->
<record model="ir.ui.view" id="report_sale_fast_food_product_pizza_view_list"> <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="model">sale_fast_food.reporting.product</field>
<field name="type">tree</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="view" ref="report_sale_fast_food_product_pizza_view_list"/>
<field name="act_window" ref="act_report_sale_fast_food_product_pizza"/> <field name="act_window" ref="act_report_sale_fast_food_product_pizza"/>
</record> </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 <menuitem
name="Pizzas Sold by Product" name="Pizzas Sold by Product"
parent="sale.menu_reporting" parent="sale.menu_reporting"
sequence="10" sequence="10"
id="menu_sale_fast_food_pizza" id="menu_sale_fast_food_pizza"
icon="tryton-graph"/> icon="tryton-graph"/>
<record model="ir.action.keyword" id="act_report_sale_fast_food_product_pizza_keyword1"> <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="keyword">tree_open</field>
<field name="model" ref="menu_sale_fast_food_pizza"/> <field name="model" ref="menu_sale_fast_food_pizza"/>
<field name="action" ref="act_report_sale_fast_food_product_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> </record>
</data> </data>
</tryton> </tryton>

View File

@ -205,3 +205,17 @@ Sale Fast Food Pizzas Sell by Product::
>>> actual_report = {(r.product_pizza, r.quantity) for r in reports} >>> 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}" >>> 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}"

View 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>