mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-17 17:26:43 +00:00
fix: Show achieved amount and variance for parent item groups
(cherry picked from commit 8ac11ae88d)
Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
@@ -164,9 +164,10 @@ def prepare_data(
|
|||||||
rows = {}
|
rows = {}
|
||||||
|
|
||||||
target_qty_amt_field = "target_qty" if filters.get("target_on") == "Quantity" else "target_amount"
|
target_qty_amt_field = "target_qty" if filters.get("target_on") == "Quantity" else "target_amount"
|
||||||
|
|
||||||
qty_or_amount_field = "stock_qty" if filters.get("target_on") == "Quantity" else "base_net_amount"
|
qty_or_amount_field = "stock_qty" if filters.get("target_on") == "Quantity" else "base_net_amount"
|
||||||
|
|
||||||
|
item_group_parent_child_map = get_item_group_parent_child_map()
|
||||||
|
|
||||||
for d in sales_users_data:
|
for d in sales_users_data:
|
||||||
key = (d.parent, d.item_group)
|
key = (d.parent, d.item_group)
|
||||||
dist_data = get_periodwise_distribution_data(d.distribution_id, period_list, filters.get("period"))
|
dist_data = get_periodwise_distribution_data(d.distribution_id, period_list, filters.get("period"))
|
||||||
@@ -191,7 +192,11 @@ def prepare_data(
|
|||||||
r.get(sales_field) == d.parent
|
r.get(sales_field) == d.parent
|
||||||
and period.from_date <= r.get(date_field)
|
and period.from_date <= r.get(date_field)
|
||||||
and r.get(date_field) <= period.to_date
|
and r.get(date_field) <= period.to_date
|
||||||
and (not sales_user_wise_item_groups.get(d.parent) or r.item_group == d.item_group)
|
and (
|
||||||
|
not sales_user_wise_item_groups.get(d.parent)
|
||||||
|
or r.item_group == d.item_group
|
||||||
|
or r.item_group in item_group_parent_child_map.get(d.item_group, [])
|
||||||
|
)
|
||||||
):
|
):
|
||||||
details[p_key] += r.get(qty_or_amount_field, 0)
|
details[p_key] += r.get(qty_or_amount_field, 0)
|
||||||
details[variance_key] = details.get(p_key) - details.get(target_key)
|
details[variance_key] = details.get(p_key) - details.get(target_key)
|
||||||
@@ -204,6 +209,25 @@ def prepare_data(
|
|||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
def get_item_group_parent_child_map():
|
||||||
|
"""
|
||||||
|
Returns a dict of all item group parents and leaf children associated with them.
|
||||||
|
"""
|
||||||
|
|
||||||
|
item_groups = frappe.get_all(
|
||||||
|
"Item Group", fields=["name", "parent_item_group"], order_by="lft desc, rgt desc"
|
||||||
|
)
|
||||||
|
item_group_parent_child_map = {}
|
||||||
|
|
||||||
|
for item_group in item_groups:
|
||||||
|
children = item_group_parent_child_map.get(item_group.name, [])
|
||||||
|
if not children:
|
||||||
|
children = [item_group.name]
|
||||||
|
item_group_parent_child_map.setdefault(item_group.parent_item_group, []).extend(children)
|
||||||
|
|
||||||
|
return item_group_parent_child_map
|
||||||
|
|
||||||
|
|
||||||
def get_actual_data(filters, sales_users_or_territory_data, date_field, sales_field):
|
def get_actual_data(filters, sales_users_or_territory_data, date_field, sales_field):
|
||||||
fiscal_year = get_fiscal_year(fiscal_year=filters.get("fiscal_year"), as_dict=1)
|
fiscal_year = get_fiscal_year(fiscal_year=filters.get("fiscal_year"), as_dict=1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user