From 535befbf4b0e7820518a80f9d1745e6db6f54058 Mon Sep 17 00:00:00 2001 From: sinergia Date: Mon, 21 Oct 2024 12:16:07 -0500 Subject: [PATCH] Feat: Informe de Ventas Por Usuario --- __init__.py | 1 + locale/es.po | 32 ++++++++++++++++++ report.py | 59 ++++++++++++++++++++++++++++++++- report.xml | 35 +++++++++++++++++-- tests/scenario_report_pizza.rst | 14 ++++++++ view/sales_by_user_list.xml | 11 ++++++ 6 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 view/sales_by_user_list.xml diff --git a/__init__.py b/__init__.py index 41d39e3..5412125 100644 --- a/__init__.py +++ b/__init__.py @@ -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( diff --git a/locale/es.po b/locale/es.po index ca7aefd..8749141 100644 --- a/locale/es.po +++ b/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" diff --git a/report.py b/report.py index c28c8fe..5509608 100644 --- a/report.py +++ b/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) diff --git a/report.xml b/report.xml index 9035c5e..bf47690 100644 --- a/report.xml +++ b/report.xml @@ -9,7 +9,7 @@ this repository contains the full copyright notices and license terms. --> sale_fast_food_report_context_form - + sale_fast_food.reporting.product tree @@ -27,16 +27,47 @@ this repository contains the full copyright notices and license terms. --> + + + + sale_fast_food.reporting.by_user + tree + sales_by_user_list + + + + Sales by User + sale_fast_food.reporting.by_user + sale_fast_food.report.context + + + + + + + + - + + tree_open + + + tree_open + + diff --git a/tests/scenario_report_pizza.rst b/tests/scenario_report_pizza.rst index e4b802c..8b77fbd 100644 --- a/tests/scenario_report_pizza.rst +++ b/tests/scenario_report_pizza.rst @@ -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}" diff --git a/view/sales_by_user_list.xml b/view/sales_by_user_list.xml new file mode 100644 index 0000000..d93a658 --- /dev/null +++ b/view/sales_by_user_list.xml @@ -0,0 +1,11 @@ + + + + + + + + + +