Fixed stock ageing report data develop (#23673)

* fix: stock ageing report

* Update stock_ageing.py
This commit is contained in:
rohitwaghchaure 2020-10-19 10:39:20 +05:30 committed by GitHub
parent 21bf5e9b8e
commit 5d6686bd8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,10 +16,11 @@ def execute(filters=None):
data = [] data = []
for item, item_dict in iteritems(item_details): for item, item_dict in iteritems(item_details):
earliest_age, latest_age = 0, 0
fifo_queue = sorted(filter(_func, item_dict["fifo_queue"]), key=_func) fifo_queue = sorted(filter(_func, item_dict["fifo_queue"]), key=_func)
details = item_dict["details"] details = item_dict["details"]
if not fifo_queue or (not item_dict.get("total_qty")): continue if not fifo_queue and (not item_dict.get("total_qty")): continue
average_age = get_average_age(fifo_queue, to_date) average_age = get_average_age(fifo_queue, to_date)
earliest_age = date_diff(to_date, fifo_queue[0][1]) earliest_age = date_diff(to_date, fifo_queue[0][1])
@ -60,7 +61,7 @@ def get_range_age(filters, fifo_queue, to_date):
range1 = range2 = range3 = above_range3 = 0.0 range1 = range2 = range3 = above_range3 = 0.0
for item in fifo_queue: for item in fifo_queue:
age = date_diff(to_date, item[1]) age = date_diff(to_date, item[1])
if age <= filters.range1: if age <= filters.range1:
range1 += flt(item[0]) range1 += flt(item[0])
elif age <= filters.range2: elif age <= filters.range2:
@ -69,7 +70,7 @@ def get_range_age(filters, fifo_queue, to_date):
range3 += flt(item[0]) range3 += flt(item[0])
else: else:
above_range3 += flt(item[0]) above_range3 += flt(item[0])
return range1, range2, range3, above_range3 return range1, range2, range3, above_range3
def get_columns(filters): def get_columns(filters):
@ -170,7 +171,8 @@ def get_fifo_queue(filters, sle=None):
item_details.setdefault(key, {"details": d, "fifo_queue": []}) item_details.setdefault(key, {"details": d, "fifo_queue": []})
fifo_queue = item_details[key]["fifo_queue"] fifo_queue = item_details[key]["fifo_queue"]
transferred_item_details.setdefault((d.voucher_no, d.name), []) transferred_item_key = (d.voucher_no, d.name, d.warehouse)
transferred_item_details.setdefault(transferred_item_key, [])
if d.voucher_type == "Stock Reconciliation": if d.voucher_type == "Stock Reconciliation":
d.actual_qty = flt(d.qty_after_transaction) - flt(item_details[key].get("qty_after_transaction", 0)) d.actual_qty = flt(d.qty_after_transaction) - flt(item_details[key].get("qty_after_transaction", 0))
@ -178,10 +180,10 @@ def get_fifo_queue(filters, sle=None):
serial_no_list = get_serial_nos(d.serial_no) if d.serial_no else [] serial_no_list = get_serial_nos(d.serial_no) if d.serial_no else []
if d.actual_qty > 0: if d.actual_qty > 0:
if transferred_item_details.get((d.voucher_no, d.name)): if transferred_item_details.get(transferred_item_key):
batch = transferred_item_details[(d.voucher_no, d.name)][0] batch = transferred_item_details[transferred_item_key][0]
fifo_queue.append(batch) fifo_queue.append(batch)
transferred_item_details[((d.voucher_no, d.name))].pop(0) transferred_item_details[transferred_item_key].pop(0)
else: else:
if serial_no_list: if serial_no_list:
for serial_no in serial_no_list: for serial_no in serial_no_list:
@ -205,11 +207,11 @@ def get_fifo_queue(filters, sle=None):
# if batch qty > 0 # if batch qty > 0
# not enough or exactly same qty in current batch, clear batch # not enough or exactly same qty in current batch, clear batch
qty_to_pop -= flt(batch[0]) qty_to_pop -= flt(batch[0])
transferred_item_details[(d.voucher_no, d.name)].append(fifo_queue.pop(0)) transferred_item_details[transferred_item_key].append(fifo_queue.pop(0))
else: else:
# all from current batch # all from current batch
batch[0] = flt(batch[0]) - qty_to_pop batch[0] = flt(batch[0]) - qty_to_pop
transferred_item_details[(d.voucher_no, d.name)].append([qty_to_pop, batch[1]]) transferred_item_details[transferred_item_key].append([qty_to_pop, batch[1]])
qty_to_pop = 0 qty_to_pop = 0
item_details[key]["qty_after_transaction"] = d.qty_after_transaction item_details[key]["qty_after_transaction"] = d.qty_after_transaction