optimization ShopDailyCategoryReport
This commit is contained in:
parent
d6943e37c8
commit
1e8f3403b0
|
@ -0,0 +1 @@
|
|||
,presik,presik,19.09.2023 15:27,file:///home/presik/.config/libreoffice/4;
|
78
shop.py
78
shop.py
|
@ -106,7 +106,7 @@ class ShopDailySummaryReport(Report):
|
|||
Line = pool.get('sale.line')
|
||||
Invoice = pool.get('account.invoice')
|
||||
Company = pool.get('company.company')
|
||||
fixed_hour = time(6, 0)
|
||||
fixed_hour = time(6, 0)
|
||||
|
||||
cursor = Transaction().connection.cursor()
|
||||
sale = Sale.__table__()
|
||||
|
@ -450,7 +450,7 @@ class ShopDailyCategoryReport(Report):
|
|||
Sale = pool.get('sale.sale')
|
||||
Line = pool.get('sale.line')
|
||||
Invoice = pool.get('account.invoice')
|
||||
fixed_hour = time(6, 0)
|
||||
fixed_hour = time(6, 0)
|
||||
|
||||
cursor = Transaction().connection.cursor()
|
||||
sale = Sale.__table__()
|
||||
|
@ -502,7 +502,7 @@ class ShopDailyCategoryReport(Report):
|
|||
Shop = pool.get('sale.shop')
|
||||
fixed_hour = time(6, 0)
|
||||
|
||||
config = pool.get('sale.configuration')(1)
|
||||
# config = pool.get('sale.configuration')(1)
|
||||
products_exception = []
|
||||
amount_exception = {}
|
||||
if products_exception:
|
||||
|
@ -538,20 +538,11 @@ class ShopDailyCategoryReport(Report):
|
|||
dom_sales.append(('state', 'in', states_sale))
|
||||
|
||||
sales = Sale.search(dom_sales, order=[('number', 'ASC')])
|
||||
|
||||
total_amount = []
|
||||
numbers = []
|
||||
categories = {}
|
||||
_payments = {}
|
||||
total_payments = []
|
||||
print('voy a entrar al for sale')
|
||||
for sale in sales:
|
||||
payments = sale.payments
|
||||
sale_id = sale.id
|
||||
device_id = None
|
||||
try:
|
||||
value_except = Decimal(amount_exception[sale_id])
|
||||
except:
|
||||
value_except = Decimal(0)
|
||||
if sale.sale_device:
|
||||
device_id = sale.sale_device.id
|
||||
if sale.total_amount <= 0:
|
||||
|
@ -563,58 +554,47 @@ class ShopDailyCategoryReport(Report):
|
|||
invoice = sale.invoices[0]
|
||||
if not invoice.number or invoice.total_amount <= 0 or not device_id:
|
||||
continue
|
||||
numbers.append(invoice.number)
|
||||
|
||||
for line in sale.lines:
|
||||
category_id = '0'
|
||||
if line.product.id in products_exception:
|
||||
product_id = line.product.id
|
||||
product_name = line.product.name
|
||||
line_quantity = line.quantity
|
||||
line_amount_w_tax = line.amount_w_tax
|
||||
if product_id in products_exception:
|
||||
continue
|
||||
if line.product.categories:
|
||||
category = line.product.categories[0]
|
||||
category_id = category.id
|
||||
if category_id not in categories.keys() and category_id != '0':
|
||||
try:
|
||||
if category_id != '0':
|
||||
categories[category_id]['base'].append(line.amount)
|
||||
try:
|
||||
categories[category_id]['products'][product_id]['quantity'] += line_quantity
|
||||
categories[category_id]['products'][product_id]['amount'] += line_amount_w_tax
|
||||
total_payments.append(line_amount_w_tax)
|
||||
except KeyError:
|
||||
categories[category_id]['products'][product_id] = {
|
||||
'name': product_name,
|
||||
'quantity': line_quantity,
|
||||
'amount': line_amount_w_tax,
|
||||
}
|
||||
total_payments.append(line_amount_w_tax)
|
||||
except KeyError:
|
||||
categories[category_id] = {
|
||||
'name': category.name,
|
||||
'base': [line.amount],
|
||||
'products': {line.product.template.id: {
|
||||
'name': line.product.template.name,
|
||||
'quantity': line.quantity,
|
||||
'amount': line.amount_w_tax,
|
||||
'products': {product_id: {
|
||||
'name': product_name,
|
||||
'quantity': line_quantity,
|
||||
'amount': line_amount_w_tax,
|
||||
}
|
||||
}
|
||||
}
|
||||
total_payments.append(line.amount_w_tax)
|
||||
else:
|
||||
if category_id != '0':
|
||||
categories[category_id]['base'].append(line.amount)
|
||||
if line.product.template.id in categories[category_id]['products'].keys():
|
||||
categories[category_id]['products'][line.product.template.id]['quantity'] += line.quantity
|
||||
categories[category_id]['products'][line.product.template.id]['amount'] += line.amount_w_tax
|
||||
total_payments.append(line.amount_w_tax)
|
||||
else:
|
||||
categories[category_id]['products'][line.product.template.id] = {
|
||||
'name': line.product.template.name,
|
||||
'quantity': line.quantity,
|
||||
'amount': line.amount_w_tax,
|
||||
}
|
||||
total_payments.append(line.amount_w_tax)
|
||||
if numbers:
|
||||
min_number = min(numbers)
|
||||
max_number = max(numbers)
|
||||
|
||||
else:
|
||||
min_number = ''
|
||||
max_number = ''
|
||||
total_payments.append(line_amount_w_tax)
|
||||
report_context['date'] = data['sale_date']
|
||||
report_context['end_date'] = data['end_date'] if data['end_date'] else data['sale_date']
|
||||
report_context['company'] = company.party
|
||||
report_context['shop'] = Shop(data['shop']).name
|
||||
report_context['start_number'] = min_number
|
||||
report_context['end_number'] = max_number
|
||||
report_context['categories'] = categories.values()
|
||||
report_context['sum_count_invoices'] = len(numbers)
|
||||
report_context['sum_total_amount'] = sum(total_amount)
|
||||
report_context['payments'] = _payments.values()
|
||||
report_context['total_payments'] = sum(total_payments)
|
||||
print(report_context['total_payments'])
|
||||
return report_context
|
||||
|
|
Loading…
Reference in New Issue