minor fix in kardex report

This commit is contained in:
Elvis 2023-10-26 11:17:27 -05:00
parent c456fe6005
commit fb051916d2
3 changed files with 27 additions and 20 deletions

View File

@ -1 +1 @@
,presik,presik,24.10.2023 08:33,file:///home/presik/.config/libreoffice/4;
,presik,presik,26.10.2023 10:55,file:///home/presik/.config/libreoffice/4;

Binary file not shown.

View File

@ -849,7 +849,6 @@ class WarehouseKardexReport(Report):
'input': f'and to_location in {tup_locations}',
'output': f'and from_location in {tup_locations}',
}
# where product in {tuple(products)}
moves = {}
if not data['detail_by_product']:
@ -867,16 +866,16 @@ class WarehouseKardexReport(Report):
for k, v in type.items():
clause = v
query = f"""select s.product as id, p.code, t.name, t.reference, sum(s.quantity) as quantity from stock_move as s
join product_product as p on p.id = s.product
join product_template as t on p.template = t.id
where effective_date >= '{str(data['from_date'])}'
and effective_date <= '{str(data['to_date'])}'
{clause}
group by s.product, p.code, t.name, t.reference;"""
moves = cls.query_to_dict(query)
for m, v in moves.items():
cls.set_value(v, k, products)
query = f"""select s.product as id, p.code, t.name, t.reference, sum(s.quantity) as quantity from stock_move as s
join product_product as p on p.id = s.product
join product_template as t on p.template = t.id
where effective_date >= '{str(data['from_date'])}'
and effective_date <= '{str(data['to_date'])}'
{clause}
group by s.product, p.code, t.name, t.reference ;"""
moves = cls.query_to_dict(query)
for m, v in moves.items():
cls.set_value(v, k, products)
# moves[k] = cls.query_to_dict(query)
# for m, v in moves.items():
@ -898,15 +897,17 @@ class WarehouseKardexReport(Report):
products_two = {}
for k, v in type.items():
clause = v
query = f"""select CONCAT(s.product, s.effective_date) as cid, p.id, p.code, t.name, pb.name as brand, t.reference, s.effective_date as effective_date, sum(s.quantity) as quantity from stock_move as s
query = f"""select CONCAT(s.product, s.effective_date) as cid, p.id, p.code, t.name, pb.name as brand, t.reference, s.effective_date, lp.list_price, sum(s.quantity) as quantity
from stock_move as s
join product_product as p on p.id = s.product
join product_template as t on p.template = t.id
join product_list_price as lp on t.id = lp.template
join product_brand as pb on pb.id = t.brand
where effective_date >= '{str(data['from_date'])}'
and effective_date <= '{str(data['to_date'])}'
AND p.id IN ({', '.join(map(str, data['products']))})
{clause}
GROUP BY CONCAT(s.product, s.effective_date), p.id, p.code, t.name, pb.name, t.reference, s.effective_date;"""
GROUP BY CONCAT(s.product, s.effective_date), p.id, p.code, t.name, pb.name, t.reference, s.effective_date, lp.list_price"""
# group by s.product, s.effective_date;"""
moves = cls.query_to_dict(query)
for m, v in moves.items():
@ -951,16 +952,21 @@ class WarehouseKardexReport(Report):
'end': 0,
'effective_date': None,
'cost_price': None,
'cost_price_output': None,
'list_price': None,
}
try:
products[p['id']].update({
key: p['quantity'],
# 'end': products[p['id']]['end'] - products[p['id']]['output'] + products[p['id']]['input'],
print('intento')
products[p['cid']].update({
key: p['quantity']
})
print('termino intento')
except:
print(key, p['quantity'], p['effective_date'], p['id'], 'aqui esta')
start, end = cls.get_balances(Product, p['id'], p['effective_date'], id_locations)
domain_cost = [('product', '=', p['id']), ('effective_date', '=', p['effective_date'])]
cost_price = AverageCost.search_read(domain_cost, fields_names=['cost_price'])
product_origin = Product(p['id'])
products[p['cid']] = copy.deepcopy(defaults)
products[p['cid']].update({
'code': p['code'],
@ -971,6 +977,7 @@ class WarehouseKardexReport(Report):
'end': end,
'brand': p['brand'],
'cost_price': cost_price[0]['cost_price'] if cost_price else None,
'list_price': product_origin.list_price if product_origin else None,
'id': p['id'],
key: p['quantity']
})
@ -989,15 +996,15 @@ class WarehouseKardexReport(Report):
'locations': locations,
}
with Transaction().set_context(stock_context):
products_start = Product.search_read(dom_products, fields_names=fields_names, order=[('code', 'ASC')])
products_start = Product.search_read(dom_products, fields_names=fields_names)
with Transaction().set_context(stock_context_end):
products_end = Product.search_read(dom_products, fields_names=fields_names, order=[('code', 'ASC')])
products_end = Product.search_read(dom_products, fields_names=fields_names)
for p in products_start:
cls.set_value(p, 'start', products)
for p in products_end:
cls.set_value(p, 'end', products)
print(products)
# print(products)
return products[id]['start'], products[id]['end']
@classmethod