Feat: Report Sale by Zone

This commit is contained in:
sinergia 2024-10-21 14:01:03 -05:00
parent 535befbf4b
commit 83dcdddf1f
6 changed files with 188 additions and 0 deletions

View File

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

View File

@ -82,6 +82,14 @@ msgctxt "model:ir.ui.menu,name:menu_sale_fast_food_by_user"
msgid "Sales by User" msgid "Sales by User"
msgstr "Ventas Por Usuario" 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:" msgctxt "field:sale_fast_food.reporting.product,product_pizza:"
msgid "Product" msgid "Product"
msgstr "Pizza" msgstr "Pizza"
@ -114,6 +122,34 @@ msgctxt "field:sale_fast_food.reporting.by_user,total_tip_amount:"
msgid "Total Tip Amount" msgid "Total Tip Amount"
msgstr "Propinas" 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:" msgctxt "wizard_button:sale.print_cash_register,start,end:"
msgid "Cancel" msgid "Cancel"
msgstr "Cancelar" msgstr "Cancelar"

View File

@ -206,3 +206,75 @@ class ReportSaleByUser(ReportSaleAbstract, ModelView):
def _column_id(cls, tables): def _column_id(cls, tables):
sale = tables['sale.sale'] sale = tables['sale.sale']
return Min(sale.id) 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)

View File

@ -47,6 +47,25 @@ this repository contains the full copyright notices and license terms. -->
<field name="act_window" ref="act_report_sale_fast_food_by_user"/> <field name="act_window" ref="act_report_sale_fast_food_by_user"/>
</record> </record>
<!-- Report by Zone-->
<record model="ir.ui.view" id="report_sale_fast_food_zone_view_list">
<field name="model">sale_fast_food.reporting.zone</field>
<field name="type">tree</field>
<field name="name">sales_by_zone_list</field>
</record>
<record model="ir.action.act_window" id="act_report_sale_fast_food_zone">
<field name="name">Sales by Zone</field>
<field name="res_model">sale_fast_food.reporting.zone</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_zone_view1">
<field name="sequence" eval="20"/>
<field name="view" ref="report_sale_fast_food_zone_view_list"/>
<field name="act_window" ref="act_report_sale_fast_food_zone"/>
</record>
<menuitem <menuitem
name="Pizzas Sold by Product" name="Pizzas Sold by Product"
parent="sale.menu_reporting" parent="sale.menu_reporting"
@ -59,6 +78,12 @@ this repository contains the full copyright notices and license terms. -->
sequence="20" sequence="20"
id="menu_sale_fast_food_by_user" id="menu_sale_fast_food_by_user"
icon="tryton-graph"/> icon="tryton-graph"/>
<menuitem
name="Sales by Zone"
parent="sale.menu_reporting"
sequence="30"
id="menu_sale_fast_food_zone"
icon="tryton-graph"/>
<record model="ir.action.keyword" id="act_report_sale_fast_food_product_pizza_keyword1"> <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"/>
@ -69,5 +94,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="model" ref="menu_sale_fast_food_by_user"/> <field name="model" ref="menu_sale_fast_food_by_user"/>
<field name="action" ref="act_report_sale_fast_food_by_user"/> <field name="action" ref="act_report_sale_fast_food_by_user"/>
</record> </record>
<record model="ir.action.keyword" id="act_report_sale_fast_food_zone_keyword1">
<field name="keyword">tree_open</field>
<field name="model" ref="menu_sale_fast_food_zone"/>
<field name="action" ref="act_report_sale_fast_food_zone"/>
</record>
</data> </data>
</tryton> </tryton>

View File

@ -157,6 +157,11 @@ Create Sale Shop::
>>> shop = create_shop(payment_term, product_price_list) >>> shop = create_shop(payment_term, product_price_list)
>>> shop.save() >>> shop.save()
>>> Device = Model.get('sale.device')
>>> device = Device()
>>> device.name = "SE Device"
>>> device.shop = shop
>>> device.save()
Save Sale Shop User:: Save Sale Shop User::
@ -167,11 +172,32 @@ Save Sale Shop User::
>>> user.save() >>> user.save()
>>> set_user(user) >>> 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 5 products::
>>> sale = Sale() >>> sale = Sale()
>>> sale.party = customer >>> sale.party = customer
>>> sale.payment_term = payment_term >>> sale.payment_term = payment_term
>>> sale.zone = zone1
>>> sale.table = table1
>>> sale.invoice_method = 'order' >>> sale.invoice_method = 'order'
>>> sale_line = SaleLine() >>> sale_line = SaleLine()
@ -219,3 +245,14 @@ Sale Fast Food Sales by User::
>>> actual_report = {(r.user, r.completed_sales) for r in reports} >>> 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}" >>> 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}"

View File

@ -0,0 +1,12 @@
<?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="zone"/>
<field name="table"/>
<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>