Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: FG Item incorrect qty in the work order (backport #39200) #39211

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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