From 83dcdddf1f6e0411a8a1ba35c16d2132570d73ff Mon Sep 17 00:00:00 2001 From: sinergia Date: Mon, 21 Oct 2024 14:01:03 -0500 Subject: [PATCH] Feat: Report Sale by Zone --- __init__.py | 1 + locale/es.po | 36 +++++++++++++++++ report.py | 72 +++++++++++++++++++++++++++++++++ report.xml | 30 ++++++++++++++ tests/scenario_report_pizza.rst | 37 +++++++++++++++++ view/sales_by_zone_list.xml | 12 ++++++ 6 files changed, 188 insertions(+) create mode 100644 view/sales_by_zone_list.xml diff --git a/__init__.py b/__init__.py index 5412125..50b208d 100644 --- a/__init__.py +++ b/__init__.py @@ -17,6 +17,7 @@ def register(): report_close_statement.ReportCloseStatementStart, report.ReportSaleProduct, report.ReportSaleByUser, + report.ReportSaleByZone, report.ReportSaleContext, module='sale_fast_food', type_='model') Pool.register( diff --git a/locale/es.po b/locale/es.po index 8749141..1b8e810 100644 --- a/locale/es.po +++ b/locale/es.po @@ -82,6 +82,14 @@ msgctxt "model:ir.ui.menu,name:menu_sale_fast_food_by_user" msgid "Sales by User" msgstr "Ventas Por Usuario" +msgctxt "model:ir.action,name:act_report_sale_fast_food_zone" +msgid "Sales by User" +msgstr "Ventas Por Usuario" + +msgctxt "model:ir.ui.menu,name:menu_sale_fast_food_zone" +msgid "Sales by Zone" +msgstr "Ventas Por Zona" + msgctxt "field:sale_fast_food.reporting.product,product_pizza:" msgid "Product" msgstr "Pizza" @@ -114,6 +122,34 @@ msgctxt "field:sale_fast_food.reporting.by_user,total_tip_amount:" msgid "Total Tip Amount" msgstr "Propinas" +msgctxt "field:sale_fast_food.reporting.zone,zone:" +msgid "Zone" +msgstr "Zona" + +msgctxt "field:sale_fast_food.reporting.zone,table:" +msgid "Table" +msgstr "Mesa" + +msgctxt "field:sale_fast_food.reporting.zone,completed_sales:" +msgid "Completed Sales" +msgstr "# Ventas" + +msgctxt "field:sale_fast_food.reporting.zone,untaxed_amount:" +msgid "Untaxed Amount" +msgstr "Base Imponible" + +msgctxt "field:sale_fast_food.reporting.zone,tax_amount:" +msgid "Tax Amount" +msgstr "Impuestos" + +msgctxt "field:sale_fast_food.reporting.zone,total_amount:" +msgid "Total Amount" +msgstr "Total" + +msgctxt "field:sale_fast_food.reporting.zone,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 5509608..0755ef1 100644 --- a/report.py +++ b/report.py @@ -206,3 +206,75 @@ class ReportSaleByUser(ReportSaleAbstract, ModelView): def _column_id(cls, tables): sale = tables['sale.sale'] return Min(sale.id) + + +class ReportSaleByZone(ReportSaleAbstract, ModelView): + """Report Sale Group by Zone""" + __name__ = 'sale_fast_food.reporting.zone' + + zone = fields.Many2One('sale.zone', "Zone") + table = fields.Many2One('sale.table', "Table") + 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__() + + Table = pool.get('sale.table') + tables['sale.table'] = table = Table.__table__() + + Zone = pool.get('sale.zone') + tables['sale.table'] = zone = Zone.__table__() + + from_item = sale.left_join( + table, + condition=table.id == sale.table + ).left_join( + zone, + condition=zone.id == table.zone + ) + + return from_item, tables + + @classmethod + def _columns(cls, tables): + sale = tables['sale.sale'] + return super(ReportSaleByZone, cls)._columns(tables) + [ + sale.zone.as_('zone'), + sale.table.as_('table'), + 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.zone, + sale.table, + 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 bf47690..681e2e0 100644 --- a/report.xml +++ b/report.xml @@ -47,6 +47,25 @@ this repository contains the full copyright notices and license terms. --> + + + sale_fast_food.reporting.zone + tree + sales_by_zone_list + + + + Sales by Zone + sale_fast_food.reporting.zone + sale_fast_food.report.context + + + + + + + + sequence="20" id="menu_sale_fast_food_by_user" icon="tryton-graph"/> + tree_open @@ -69,5 +94,10 @@ this repository contains the full copyright notices and license terms. --> + + tree_open + + + diff --git a/tests/scenario_report_pizza.rst b/tests/scenario_report_pizza.rst index 8b77fbd..5b81c8d 100644 --- a/tests/scenario_report_pizza.rst +++ b/tests/scenario_report_pizza.rst @@ -157,6 +157,11 @@ Create Sale Shop:: >>> shop = create_shop(payment_term, product_price_list) >>> shop.save() + >>> Device = Model.get('sale.device') + >>> device = Device() + >>> device.name = "SE Device" + >>> device.shop = shop + >>> device.save() Save Sale Shop User:: @@ -167,11 +172,32 @@ Save Sale Shop User:: >>> user.save() >>> set_user(user) + +Crear Una Zona de Venta:: + >>> Zone = Model.get('sale.zone') + >>> zone = Zone() + >>> zone.name = "Main" + >>> zone.save() + >>> zone1 = Zone() + >>> zone1.name = "SE" + >>> zone1.shop = shop + >>> zone1.device = device + >>> zone1.parent = zone + >>> zone1.save() + >>> table1 = zone1.tables.new() + >>> table1.name = "CH1" + >>> table1.save() + >>> table2 = zone1.tables.new() + >>> table2.name = "CH1" + >>> table2.save() + Sale 5 products:: >>> sale = Sale() >>> sale.party = customer >>> sale.payment_term = payment_term + >>> sale.zone = zone1 + >>> sale.table = table1 >>> sale.invoice_method = 'order' >>> sale_line = SaleLine() @@ -219,3 +245,14 @@ Sale Fast Food Sales by User:: >>> 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}" + +Sale Fast Food Sales by Zone:: + >>> ReportSalesByZone = Model.get('sale_fast_food.reporting.zone') + >>> reports = ReportSalesByZone.find([]) + + >>> expected_report = { + ... (table1, zone) + ... } + + >>> actual_report = {(r.table, r.zone) for r in reports} + >>> assert expected_report == actual_report, f"\n Expect: {expected_report} \n Actual: {actual_report}" diff --git a/view/sales_by_zone_list.xml b/view/sales_by_zone_list.xml new file mode 100644 index 0000000..f5d306e --- /dev/null +++ b/view/sales_by_zone_list.xml @@ -0,0 +1,12 @@ + + + + + + + + + + +