feat: Se crea reporte de extracto de ventas
This commit is contained in:
parent
cb12fe5e0c
commit
f45043af7e
@ -1,5 +1,5 @@
|
||||
from trytond.pool import Pool
|
||||
from . import product, sale, production, invoice, user
|
||||
from . import product, sale, production, invoice, user, report_close_statement
|
||||
|
||||
__all__ = ['register']
|
||||
|
||||
@ -12,8 +12,11 @@ def register():
|
||||
sale.Line,
|
||||
user.User,
|
||||
production.Production,
|
||||
report_close_statement.ReportCloseStatementStart,
|
||||
module='sale_fast_food', type_='model')
|
||||
Pool.register(
|
||||
report_close_statement.PrintReportCloseStatement,
|
||||
module='sale_fast_food', type_='wizard')
|
||||
Pool.register(
|
||||
report_close_statement.CashRegister,
|
||||
module='sale_fast_food', type_='report')
|
||||
|
2328
report/close_statement.fodt
Normal file
2328
report/close_statement.fodt
Normal file
File diff suppressed because it is too large
Load Diff
99
report_close_statement.py
Normal file
99
report_close_statement.py
Normal file
@ -0,0 +1,99 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.wizard import Wizard, StateView, Button, StateTransition, StateReport
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.report import Report
|
||||
from datetime import date
|
||||
|
||||
__all__ = ['ReportCloseStatementStart', 'PrintReportCloseStatement', 'CashRegister']
|
||||
|
||||
class ReportCloseStatementStart(ModelView):
|
||||
"Vista inicial de reporte de extracto"
|
||||
__name__ = 'sale.print_cash_register.start'
|
||||
|
||||
date = fields.Date('Date', required=True)
|
||||
shop = fields.Many2One('sale.shop', 'Shop', required=True)
|
||||
|
||||
@classmethod
|
||||
def default_date(cls):
|
||||
return date.today()
|
||||
|
||||
@classmethod
|
||||
def default_shop(cls):
|
||||
context = Transaction().context
|
||||
shop = context['shop']
|
||||
|
||||
if shop:
|
||||
return shop
|
||||
|
||||
|
||||
class PrintReportCloseStatement(Wizard):
|
||||
"Asistente para imprimir extracto"
|
||||
__name__ = 'sale.print_cash_register'
|
||||
|
||||
start = StateView(
|
||||
'sale.print_cash_register.start',
|
||||
'sale_fast_food.print_cash_register_start_view_form',[
|
||||
Button("Cancel", 'end', 'tryton-cancel'),
|
||||
Button("Print Cash Register",
|
||||
'print_cash_register', 'tryton-ok', default=True)])
|
||||
|
||||
print_cash_register = StateReport('sale.cash_register')
|
||||
|
||||
def do_print_cash_register(self, action):
|
||||
data = {
|
||||
'date': self.start.date,
|
||||
'shop': self.start.shop.id
|
||||
}
|
||||
|
||||
return action, data
|
||||
|
||||
def transition_print_cash_register(self):
|
||||
return 'end'
|
||||
|
||||
class CashRegister(Report):
|
||||
"Extracto"
|
||||
__name__ = 'sale.cash_register'
|
||||
|
||||
def get_number_pizzas_sold(lines):
|
||||
pizzas = 0
|
||||
for line in lines:
|
||||
if line.bought_pizza:
|
||||
pizzas += line.quantity
|
||||
return pizzas
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, header, data):
|
||||
report_context = super(
|
||||
CashRegister, cls).get_context(records, header, data)
|
||||
|
||||
pool = Pool()
|
||||
Sale = pool.get('sale.sale')
|
||||
today_sales_domain = [('state', 'in', ['processing', 'done']),
|
||||
('sale_date', '=', data['date']),
|
||||
('shop', '=', data['shop'])]
|
||||
today_sales = Sale.search(today_sales_domain,
|
||||
order=[('id', 'ASC')])
|
||||
|
||||
if not today_sales:
|
||||
return
|
||||
|
||||
untaxed_amount = 0
|
||||
tax_amount = 0
|
||||
total_amount = 0
|
||||
number_pizzas_sold = 0
|
||||
|
||||
for sale in today_sales:
|
||||
untaxed_amount += sale.untaxed_amount
|
||||
tax_amount += sale.tax_amount
|
||||
number_pizzas_sold += cls.get_number_pizzas_sold(sale.lines)
|
||||
total_amount+=sale.total_amount
|
||||
|
||||
report_context['untaxed_amount'] = untaxed_amount
|
||||
report_context['tax_amount'] = tax_amount
|
||||
report_context['total_amount'] = total_amount
|
||||
report_context['number_pizzas_sold'] = number_pizzas_sold
|
||||
|
||||
return report_context
|
28
report_close_statement.xml
Normal file
28
report_close_statement.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?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. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.action.report" id="report_close_statement">
|
||||
<field name="name">Close statement</field>
|
||||
<field name="model"></field>
|
||||
<field name="report_name">sale.cash_register</field>
|
||||
<field name="report">sale_fast_food/report/close_statement.fodt</field>
|
||||
<field name="template_extension">odt</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="print_cash_register_start_view_form">
|
||||
<field name="model">sale.print_cash_register.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">print_cash_register_start_form</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="wizard_print_cash_register">
|
||||
<field name="name">Print cash register</field>
|
||||
<field name="wiz_name">sale.print_cash_register</field>
|
||||
</record>
|
||||
<menuitem
|
||||
parent="sale.menu_sale"
|
||||
action="wizard_print_cash_register"
|
||||
id="menu_print_cash_register"
|
||||
icon="tryton-print"/>
|
||||
</data>
|
||||
</tryton>
|
4
sale.py
4
sale.py
@ -329,6 +329,7 @@ class Line(metaclass=PoolMeta):
|
||||
|
||||
pizza = fields.Integer("Pizza")
|
||||
impreso = fields.Boolean("Impreso")
|
||||
bought_pizza = fields.Boolean("Sold pizza")
|
||||
|
||||
@fields.depends('product', 'unit', 'sale',
|
||||
'_parent_sale.party', '_parent_sale.invoice_party',
|
||||
@ -339,6 +340,9 @@ class Line(metaclass=PoolMeta):
|
||||
super(Line, self).on_change_product()
|
||||
if self.product and self.product.pizza:
|
||||
self.pizza = self.sale.pizza_number
|
||||
self.bought_pizza = True
|
||||
else:
|
||||
self.bought_pizza = False
|
||||
|
||||
def get_production(self):
|
||||
"Return production for the sale line"
|
||||
|
@ -9,7 +9,9 @@ depends:
|
||||
#sale_printer
|
||||
production
|
||||
account_invoice
|
||||
sale_shop
|
||||
xml:
|
||||
product.xml
|
||||
sale.xml
|
||||
user.xml
|
||||
report_close_statement.xml
|
10
view/print_cash_register_start_form.xml
Normal file
10
view/print_cash_register_start_form.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?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. -->
|
||||
<form col="6">
|
||||
<label name="date"/>
|
||||
<field name="date"/>
|
||||
|
||||
<label name="shop"/>
|
||||
<field name="shop"/>
|
||||
</form>
|
@ -7,5 +7,7 @@
|
||||
<field name="pizza"/>
|
||||
<label name="impreso"/>
|
||||
<field name="impreso"/>
|
||||
<label name="bought_pizza"/>
|
||||
<field name="bought_pizza"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
Loading…
Reference in New Issue
Block a user