Skip to content

Commit

Permalink
fix: duplicate required items in the CSV (backport #44498) (#44507)
Browse files Browse the repository at this point in the history
* fix: duplicate required items in the CSV (#44498)

(cherry picked from commit b4534e5)

# Conflicts:
#	erpnext/manufacturing/doctype/production_plan/production_plan.json

* chore: fix conflicts

---------

Co-authored-by: rohitwaghchaure <[email protected]>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Dec 4, 2024
1 parent 94a0725 commit 539c5b7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
"depends_on": "eval:!doc.__islocal",
"fieldname": "download_materials_required",
"fieldtype": "Button",
"label": "Download Materials Request Plan"
"label": "Download Required Materials"
},
{
"fieldname": "get_items_for_mr",
Expand Down Expand Up @@ -398,7 +398,7 @@
"collapsible": 1,
"fieldname": "download_materials_request_plan_section_section",
"fieldtype": "Section Break",
"label": "Download Materials Request Plan Section"
"label": "Preview Required Materials"
},
{
"default": "0",
Expand Down Expand Up @@ -439,7 +439,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-02-27 13:34:20.692211",
"modified": "2024-12-04 11:55:03.108971",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Plan",
Expand All @@ -463,4 +463,4 @@
"sort_field": "modified",
"sort_order": "ASC",
"states": []
}
}
47 changes: 27 additions & 20 deletions erpnext/manufacturing/doctype/production_plan/production_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class ProductionPlan(Document):
from erpnext.manufacturing.doctype.material_request_plan_item.material_request_plan_item import (
MaterialRequestPlanItem,
)
from erpnext.manufacturing.doctype.production_plan_item.production_plan_item import (
ProductionPlanItem,
)
from erpnext.manufacturing.doctype.production_plan_item.production_plan_item import ProductionPlanItem
from erpnext.manufacturing.doctype.production_plan_item_reference.production_plan_item_reference import (
ProductionPlanItemReference,
)
Expand Down Expand Up @@ -1085,24 +1083,33 @@ def download_raw_materials(doc, warehouses=None):
frappe.flags.show_qty_in_stock_uom = 1
items = get_items_for_material_requests(doc, warehouses=warehouses, get_parent_warehouse_data=True)

duplicate_item_wh_list = frappe._dict()

for d in items:
item_list.append(
[
d.get("item_code"),
d.get("item_name"),
d.get("description"),
d.get("stock_uom"),
d.get("warehouse"),
d.get("required_bom_qty"),
d.get("projected_qty"),
d.get("actual_qty"),
d.get("ordered_qty"),
d.get("planned_qty"),
d.get("reserved_qty_for_production"),
d.get("safety_stock"),
d.get("quantity"),
]
)
key = (d.get("item_code"), d.get("warehouse"))
if key in duplicate_item_wh_list:
rm_data = duplicate_item_wh_list[key]
rm_data[12] += d.get("quantity")
continue

rm_data = [
d.get("item_code"),
d.get("item_name"),
d.get("description"),
d.get("stock_uom"),
d.get("warehouse"),
d.get("required_bom_qty"),
d.get("projected_qty"),
d.get("actual_qty"),
d.get("ordered_qty"),
d.get("planned_qty"),
d.get("reserved_qty_for_production"),
d.get("safety_stock"),
d.get("quantity"),
]

duplicate_item_wh_list[key] = rm_data
item_list.append(rm_data)

if not doc.get("for_warehouse"):
row = {"item_code": d.get("item_code")}
Expand Down

0 comments on commit 539c5b7

Please sign in to comment.