diff --git a/erpnext/manufacturing/doctype/workstation/test_workstation.py b/erpnext/manufacturing/doctype/workstation/test_workstation.py index b0154cb96f5..4c8e740e71e 100644 --- a/erpnext/manufacturing/doctype/workstation/test_workstation.py +++ b/erpnext/manufacturing/doctype/workstation/test_workstation.py @@ -80,7 +80,7 @@ class TestWorkstation(ERPNextTestSuite): test_routing_operations = [ {"operation": "Test Operation A", "workstation": "_Test Workstation A", "time_in_mins": 60}, - {"operation": "Test Operation B", "workstation": "_Test Workstation A", "time_in_mins": 60}, + {"operation": "Test Operation B", "workstation": "_Test Workstation A", "time_in_mins": 30}, ] routing_doc = create_routing(routing_name="Routing Test", operations=test_routing_operations) bom_doc = setup_bom(item_code="_Testing Item", routing=routing_doc.name, currency="INR") @@ -113,12 +113,16 @@ class TestWorkstation(ERPNextTestSuite): # update_bom_operation() (run on w1.save()) must write the new rate directly onto the # Routing's BOM Operation rows. This is the converted query's own effect (not the BOM # update_cost above) and is what silently skipped on Postgres when parenttype was 'routing'. - routing_op_rate = frappe.db.get_value( - "BOM Operation", - {"parent": routing_doc.name, "parenttype": "Routing", "workstation": "_Test Workstation A"}, - "hour_rate", - ) - self.assertEqual(routing_op_rate, 250) + # It must also refresh operating_cost (hour_rate * time_in_mins / 60); the 30-min op + # exercises the arithmetic rather than a plain rate copy. + for operation, expected_operating_cost in (("Test Operation A", 250), ("Test Operation B", 125)): + hour_rate, operating_cost = frappe.db.get_value( + "BOM Operation", + {"parent": routing_doc.name, "parenttype": "Routing", "operation": operation}, + ["hour_rate", "operating_cost"], + ) + self.assertEqual(hour_rate, 250) + self.assertEqual(operating_cost, expected_operating_cost) def make_workstation(*args, **kwargs): diff --git a/erpnext/manufacturing/doctype/workstation/workstation.py b/erpnext/manufacturing/doctype/workstation/workstation.py index 64be85f6a2f..f89e7700db6 100644 --- a/erpnext/manufacturing/doctype/workstation/workstation.py +++ b/erpnext/manufacturing/doctype/workstation/workstation.py @@ -206,6 +206,7 @@ class Workstation(Document): ( frappe.qb.update(bom_op) .set(bom_op.hour_rate, self.hour_rate) + .set(bom_op.operating_cost, self.hour_rate * bom_op.time_in_mins / 60) .where(bom_op.parent.isin(bom_list) & (bom_op.workstation == self.name)) .run() )