Se adiciona lógica de extractos
This commit is contained in:
@@ -57,13 +57,31 @@ class CashRegister(Report):
|
||||
"Extracto"
|
||||
__name__ = 'sale.cash_register'
|
||||
|
||||
def get_number_pizzas_sold(lines):
|
||||
def _get_number_pizzas_sold(lines):
|
||||
pizzas = 0
|
||||
for line in lines:
|
||||
if line.bougth_pizza:
|
||||
if line.bought_pizza:
|
||||
pizzas += line.quantity
|
||||
return pizzas
|
||||
|
||||
def _get_statements_by_date(date):
|
||||
pool = Pool()
|
||||
User = pool.get('res.user')
|
||||
Statement = pool.get('account.statement')
|
||||
user = Transaction().user
|
||||
user = User(user)
|
||||
device = user.sale_device
|
||||
|
||||
if not device:
|
||||
return
|
||||
journals = [j.id for j in device.journals]
|
||||
statements = Statement.search([
|
||||
('journal', 'in', journals),
|
||||
('state', 'in', ['validated', 'posted']),
|
||||
('date', '=', date)
|
||||
])
|
||||
return statements
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, header, data):
|
||||
report_context = super(
|
||||
@@ -79,21 +97,26 @@ class CashRegister(Report):
|
||||
|
||||
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)
|
||||
number_pizzas_sold += cls._get_number_pizzas_sold(sale.lines)
|
||||
total_amount+=sale.total_amount
|
||||
|
||||
statements = cls._get_statements_by_date(data['date'])
|
||||
|
||||
if statements:
|
||||
report_context['statements'] = [{
|
||||
'name': statement.journal.name,
|
||||
'total_amount':statement.total_amount
|
||||
} for statement in statements]
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user