Merge pull request #26910 from frappe-pr-bot/backport/version-13-pre-release/26908
fix: Stock Analytics Report must consider warehouse during calculation
This commit is contained in:
commit
b1406dba98
@ -114,14 +114,41 @@ def get_period(posting_date, filters):
|
|||||||
|
|
||||||
|
|
||||||
def get_periodic_data(entry, filters):
|
def get_periodic_data(entry, filters):
|
||||||
|
"""Structured as:
|
||||||
|
Item 1
|
||||||
|
- Balance (updated and carried forward):
|
||||||
|
- Warehouse A : bal_qty/value
|
||||||
|
- Warehouse B : bal_qty/value
|
||||||
|
- Jun 2021 (sum of warehouse quantities used in report)
|
||||||
|
- Warehouse A : bal_qty/value
|
||||||
|
- Warehouse B : bal_qty/value
|
||||||
|
- Jul 2021 (sum of warehouse quantities used in report)
|
||||||
|
- Warehouse A : bal_qty/value
|
||||||
|
- Warehouse B : bal_qty/value
|
||||||
|
Item 2
|
||||||
|
- Balance (updated and carried forward):
|
||||||
|
- Warehouse A : bal_qty/value
|
||||||
|
- Warehouse B : bal_qty/value
|
||||||
|
- Jun 2021 (sum of warehouse quantities used in report)
|
||||||
|
- Warehouse A : bal_qty/value
|
||||||
|
- Warehouse B : bal_qty/value
|
||||||
|
- Jul 2021 (sum of warehouse quantities used in report)
|
||||||
|
- Warehouse A : bal_qty/value
|
||||||
|
- Warehouse B : bal_qty/value
|
||||||
|
"""
|
||||||
periodic_data = {}
|
periodic_data = {}
|
||||||
for d in entry:
|
for d in entry:
|
||||||
period = get_period(d.posting_date, filters)
|
period = get_period(d.posting_date, filters)
|
||||||
bal_qty = 0
|
bal_qty = 0
|
||||||
|
|
||||||
|
# if period against item does not exist yet, instantiate it
|
||||||
|
# insert existing balance dict against period, and add/subtract to it
|
||||||
|
if periodic_data.get(d.item_code) and not periodic_data.get(d.item_code).get(period):
|
||||||
|
periodic_data[d.item_code][period] = periodic_data[d.item_code]['balance']
|
||||||
|
|
||||||
if d.voucher_type == "Stock Reconciliation":
|
if d.voucher_type == "Stock Reconciliation":
|
||||||
if periodic_data.get(d.item_code):
|
if periodic_data.get(d.item_code) and periodic_data.get(d.item_code).get('balance').get(d.warehouse):
|
||||||
bal_qty = periodic_data[d.item_code]["balance"]
|
bal_qty = periodic_data[d.item_code]['balance'][d.warehouse]
|
||||||
|
|
||||||
qty_diff = d.qty_after_transaction - bal_qty
|
qty_diff = d.qty_after_transaction - bal_qty
|
||||||
else:
|
else:
|
||||||
@ -132,12 +159,12 @@ def get_periodic_data(entry, filters):
|
|||||||
else:
|
else:
|
||||||
value = d.stock_value_difference
|
value = d.stock_value_difference
|
||||||
|
|
||||||
periodic_data.setdefault(d.item_code, {}).setdefault(period, 0.0)
|
# period-warehouse wise balance
|
||||||
periodic_data.setdefault(d.item_code, {}).setdefault("balance", 0.0)
|
periodic_data.setdefault(d.item_code, {}).setdefault('balance', {}).setdefault(d.warehouse, 0.0)
|
||||||
|
periodic_data.setdefault(d.item_code, {}).setdefault(period, {}).setdefault(d.warehouse, 0.0)
|
||||||
periodic_data[d.item_code]["balance"] += value
|
|
||||||
periodic_data[d.item_code][period] = periodic_data[d.item_code]["balance"]
|
|
||||||
|
|
||||||
|
periodic_data[d.item_code]['balance'][d.warehouse] += value
|
||||||
|
periodic_data[d.item_code][period][d.warehouse] = periodic_data[d.item_code]['balance'][d.warehouse]
|
||||||
|
|
||||||
return periodic_data
|
return periodic_data
|
||||||
|
|
||||||
@ -160,7 +187,8 @@ def get_data(filters):
|
|||||||
total = 0
|
total = 0
|
||||||
for dummy, end_date in ranges:
|
for dummy, end_date in ranges:
|
||||||
period = get_period(end_date, filters)
|
period = get_period(end_date, filters)
|
||||||
amount = flt(periodic_data.get(item_data.name, {}).get(period))
|
period_data = periodic_data.get(item_data.name, {}).get(period)
|
||||||
|
amount = sum(period_data.values()) if period_data else 0
|
||||||
row[scrub(period)] = amount
|
row[scrub(period)] = amount
|
||||||
total += amount
|
total += amount
|
||||||
row["total"] = total
|
row["total"] = total
|
||||||
|
|||||||
@ -235,12 +235,15 @@ def filter_items_with_no_transactions(iwb_map, float_precision):
|
|||||||
return iwb_map
|
return iwb_map
|
||||||
|
|
||||||
def get_items(filters):
|
def get_items(filters):
|
||||||
|
"Get items based on item code, item group or brand."
|
||||||
conditions = []
|
conditions = []
|
||||||
if filters.get("item_code"):
|
if filters.get("item_code"):
|
||||||
conditions.append("item.name=%(item_code)s")
|
conditions.append("item.name=%(item_code)s")
|
||||||
else:
|
else:
|
||||||
if filters.get("item_group"):
|
if filters.get("item_group"):
|
||||||
conditions.append(get_item_group_condition(filters.get("item_group")))
|
conditions.append(get_item_group_condition(filters.get("item_group")))
|
||||||
|
if filters.get("brand"): # used in stock analytics report
|
||||||
|
conditions.append("item.brand=%(brand)s")
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
if conditions:
|
if conditions:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user