Skip to content

Commit

Permalink
fix: FG Item incorrect qty in the work order (frappe#39200)
Browse files Browse the repository at this point in the history
rohitwaghchaure authored Jan 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7e198cc commit 4666252
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
@@ -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")

@@ -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

Original file line number Diff line number Diff line change
@@ -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():
@@ -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):
"""

0 comments on commit 4666252

Please sign in to comment.