minor fix

This commit is contained in:
wilsongomez 2022-08-01 16:13:07 -05:00
parent b867cc6ffa
commit 5041c54d66

20
sale.py
View file

@ -8,7 +8,7 @@ from itertools import chain
from sql import Null, Table, With
from sql.operators import NotIn, Or
from sql.aggregate import Sum, Count
from sql.conditionals import Case
from sql.conditionals import Case, Coalesce
from trytond.model import ModelView, fields
from trytond.pool import PoolMeta, Pool
@ -1535,12 +1535,12 @@ class SaleByKindReport(Report):
tables['invoice.line'] = line = Line.__table__()
columns_invoicetax = [
invoicetax.invoice.as_('invoice'),
Sum(invoicetax.amount).as_('amount')
invoice.id.as_('invoice'),
Sum(Coalesce(invoicetax.amount, 0)).as_('amount'),
]
query = invoicetax.select(
query = invoice.join(invoicetax, 'LEFT', condition=invoice.id==invoicetax.invoice).select(
*columns_invoicetax,
group_by=(invoicetax.invoice)
group_by=(invoice.id)
)
withs = {}
withs['with_invoicetax'] = with_invoicetax = With(query=query)
@ -1548,13 +1548,14 @@ class SaleByKindReport(Report):
columns = [
invoice.shop.as_('shop_id'),
shop.name.as_('shop'),
invoice.number.as_('invoice_number')
]
group_by = (invoice.shop, shop.name)
group_by = (invoice.shop, shop.name, invoice.number)
from_item = invoice.join(
shop, condition=shop.id == invoice.shop
).join(party, condition=party.id == invoice.party
).join(with_invoicetax, 'LEFT', condition=with_invoicetax.invoice == invoice.id
).join(with_invoicetax, 'LEFT', condition=invoice.id == with_invoicetax.invoice
)
return from_item, tables, columns, group_by, withs
@ -1687,11 +1688,11 @@ class SaleByKindReport(Report):
columns = list(cursor.description)
result = cursor.fetchall()
for row in result:
key = row[0]
# key = row[0]
key = str(row[0]) + '_' + str(row[2])
if detailed:
key = str(row[0]) + '_' + str(row[3])
row_dict = {}
print(row, 'row')
for i, col in enumerate(columns):
if col.name.startswith('sales') or col.name.startswith('amount'):
try:
@ -1699,6 +1700,7 @@ class SaleByKindReport(Report):
except:
totals[col.name] = row[i]
row_dict[col.name] = row[i]
print(row, 'row')
try:
records[key].update(row_dict)
except: