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: incorrect produced-qty in production-plan-item (backport #31706) #31862

Merged
merged 1 commit into from
Aug 17, 2022
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 @@ -482,7 +482,6 @@ def prepare_data_for_sub_assembly_items(self, row, wo_data):
"bom_no",
"stock_uom",
"bom_level",
"production_plan_item",
"schedule_date",
]:
if row.get(field):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
get_warehouse_list,
)
from erpnext.manufacturing.doctype.work_order.work_order import OverProductionError
from erpnext.manufacturing.doctype.work_order.work_order import make_stock_entry as make_se_from_wo
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.stock.doctype.item.test_item import create_item
from erpnext.stock.doctype.item.test_item import create_item, make_item
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import (
create_stock_reconciliation,
Expand Down Expand Up @@ -536,9 +537,6 @@ def test_production_plan_pending_qty_with_sales_order(self):
Test Prod Plan impact via: SO -> Prod Plan -> WO -> SE -> SE (cancel)
"""
from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record
from erpnext.manufacturing.doctype.work_order.work_order import (
make_stock_entry as make_se_from_wo,
)

make_stock_entry(
item_code="Raw Material Item 1", target="Work In Progress - _TC", qty=2, basic_rate=100
Expand Down Expand Up @@ -581,9 +579,6 @@ def test_production_plan_pending_qty_with_sales_order(self):
def test_production_plan_pending_qty_independent_items(self):
"Test Prod Plan impact if items are added independently (no from SO or MR)."
from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record
from erpnext.manufacturing.doctype.work_order.work_order import (
make_stock_entry as make_se_from_wo,
)

make_stock_entry(
item_code="Raw Material Item 1", target="Work In Progress - _TC", qty=2, basic_rate=100
Expand Down Expand Up @@ -679,6 +674,57 @@ def test_temporary_name_relinking(self):
for po_item, subassy_item in zip(pp.po_items, pp.sub_assembly_items):
self.assertEqual(po_item.name, subassy_item.production_plan_item)

def test_produced_qty_for_multi_level_bom_item(self):
# Create Items and BOMs
rm_item = make_item(properties={"is_stock_item": 1}).name
sub_assembly_item = make_item(properties={"is_stock_item": 1}).name
fg_item = make_item(properties={"is_stock_item": 1}).name

make_stock_entry(
item_code=rm_item,
qty=60,
to_warehouse="Work In Progress - _TC",
rate=99,
purpose="Material Receipt",
)

make_bom(item=sub_assembly_item, raw_materials=[rm_item], rm_qty=3)
make_bom(item=fg_item, raw_materials=[sub_assembly_item], rm_qty=4)

# Step - 1: Create Production Plan
pln = create_production_plan(item_code=fg_item, planned_qty=5, skip_getting_mr_items=1)
pln.get_sub_assembly_items()

# Step - 2: Create Work Orders
pln.make_work_order()
work_orders = frappe.get_all("Work Order", filters={"production_plan": pln.name}, pluck="name")
sa_wo = fg_wo = None
for work_order in work_orders:
wo_doc = frappe.get_doc("Work Order", work_order)
if wo_doc.production_plan_item:
wo_doc.update(
{"wip_warehouse": "Work In Progress - _TC", "fg_warehouse": "Finished Goods - _TC"}
)
fg_wo = wo_doc.name
else:
wo_doc.update(
{"wip_warehouse": "Work In Progress - _TC", "fg_warehouse": "Work In Progress - _TC"}
)
sa_wo = wo_doc.name
wo_doc.submit()

# Step - 3: Complete Work Orders
se = frappe.get_doc(make_se_from_wo(sa_wo, "Manufacture"))
se.submit()

se = frappe.get_doc(make_se_from_wo(fg_wo, "Manufacture"))
se.submit()

# Step - 4: Check Production Plan Item Produced Qty
pln.load_from_db()
self.assertEqual(pln.status, "Completed")
self.assertEqual(pln.po_items[0].produced_qty, 5)


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