fix: update operating cost when propagating workstation hour rate to routing (#57504)

(cherry picked from commit 39d5fd84db)
This commit is contained in:
Shllokkk
2026-07-28 10:26:47 +05:30
committed by Mergify
parent ceb677844f
commit 8f68b7ed20
2 changed files with 15 additions and 3 deletions

View File

@@ -72,7 +72,7 @@ class TestWorkstation(FrappeTestCase):
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")
@@ -94,6 +94,17 @@ class TestWorkstation(FrappeTestCase):
self.assertEqual(bom_doc.operations[0].hour_rate, 250)
self.assertEqual(bom_doc.operations[1].hour_rate, 250)
# hour_rate propagation must also refresh operating_cost (hour_rate * time_in_mins / 60)
# on the Routing's BOM Operation rows; the 30-min op exercises the arithmetic.
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):
args = args if args else kwargs

View File

@@ -152,9 +152,10 @@ class Workstation(Document):
for bom_no in bom_list:
frappe.db.sql(
"""update `tabBOM Operation` set hour_rate = %s
"""update `tabBOM Operation`
set hour_rate = %s, operating_cost = %s * time_in_mins / 60
where parent = %s and workstation = %s""",
(self.hour_rate, bom_no[0], self.name),
(self.hour_rate, self.hour_rate, bom_no[0], self.name),
)
def validate_workstation_holiday(self, schedule_date, skip_holiday_list_check=False):