100 lines
3.1 KiB
Python
100 lines
3.1 KiB
Python
# 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.bougth_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
|