Skip to content

Commit

Permalink
fix: FG Item incorrect qty in the work order (backport #39200) (#39211)
Browse files Browse the repository at this point in the history
fix: FG Item incorrect qty in the work order (#39200)

(cherry picked from commit 4666252)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Jan 8, 2024
1 parent 3caf462 commit abc99f8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
11 changes: 6 additions & 5 deletions erpnext/manufacturing/doctype/production_plan/production_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ def get_production_items(self):
"project": self.project,
}

key = (d.item_code, d.sales_order, d.warehouse)
if not d.sales_order:
key = (d.name, d.item_code, d.warehouse)

if not item_details["project"] and d.sales_order:
item_details["project"] = frappe.get_cached_value("Sales Order", d.sales_order, "project")

Expand All @@ -654,12 +658,9 @@ def get_production_items(self):
item_dict[(d.item_code, d.material_request_item, d.warehouse)] = item_details
else:
item_details.update(
{
"qty": flt(item_dict.get((d.item_code, d.sales_order, d.warehouse), {}).get("qty"))
+ (flt(d.planned_qty) - flt(d.ordered_qty))
}
{"qty": flt(item_dict.get(key, {}).get("qty")) + (flt(d.planned_qty) - flt(d.ordered_qty))}
)
item_dict[(d.item_code, d.sales_order, d.warehouse)] = item_details
item_dict[key] = item_details

return item_dict

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def create_work_order(item, pln, qty):
items_data = pln.get_production_items()

# Update qty
items_data[(item, None, None)]["qty"] = qty
items_data[(pln.po_items[0].name, item, None)]["qty"] = qty

# Create and Submit Work Order for each item in items_data
for key, item in items_data.items():
Expand Down Expand Up @@ -1522,6 +1522,45 @@ def test_min_order_qty_in_pp(self):
for d in mr_items:
self.assertEqual(d.get("quantity"), 1000.0)

def test_fg_item_quantity(self):
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
from erpnext.stock.utils import get_or_make_bin

fg_item = make_item(properties={"is_stock_item": 1}).name
rm_item = make_item(properties={"is_stock_item": 1}).name

make_bom(item=fg_item, raw_materials=[rm_item], source_warehouse="_Test Warehouse - _TC")

pln = create_production_plan(item_code=fg_item, planned_qty=10, do_not_submit=1)

pln.append(
"po_items",
{
"item_code": rm_item,
"planned_qty": 20,
"bom_no": pln.po_items[0].bom_no,
"warehouse": pln.po_items[0].warehouse,
"planned_start_date": add_to_date(nowdate(), days=1),
},
)
pln.submit()
wo_qty = {}

for row in pln.po_items:
wo_qty[row.name] = row.planned_qty

pln.make_work_order()

work_orders = frappe.get_all(
"Work Order",
fields=["qty", "production_plan_item as name"],
filters={"production_plan": pln.name},
)
self.assertEqual(len(work_orders), 2)

for row in work_orders:
self.assertEqual(row.qty, wo_qty[row.name])


def create_production_plan(**args):
"""
Expand Down

0 comments on commit abc99f8

Please sign in to comment.