fix: set operating cost based on bom qty causing incorrect operating costing

This commit is contained in:
Rohit Waghchaure
2025-11-07 13:48:28 +05:30
parent 689eee767d
commit 4c5ddf03e2
2 changed files with 15 additions and 4 deletions

View File

@@ -836,7 +836,7 @@ class BOM(WebsiteGenerator):
self.base_operating_cost = 0
if self.get("with_operations"):
for d in self.get("operations"):
if d.workstation:
if d.workstation or d.workstation_type:
self.update_rate_and_time(d, update_hour_rate)
operating_cost = d.operating_cost
@@ -857,7 +857,13 @@ class BOM(WebsiteGenerator):
def update_rate_and_time(self, row, update_hour_rate=False):
if not row.hour_rate or update_hour_rate:
hour_rate = flt(frappe.get_cached_value("Workstation", row.workstation, "hour_rate"))
hour_rate = 0
if row.workstation:
hour_rate = flt(frappe.get_cached_value("Workstation", row.workstation, "hour_rate"))
elif row.workstation_type:
hour_rate = flt(
frappe.get_cached_value("Workstation Type", row.workstation_type, "hour_rate")
)
if hour_rate:
row.hour_rate = (

View File

@@ -1229,13 +1229,18 @@ class WorkOrder(Document):
"fixed_time",
"skip_material_transfer",
"backflush_from_wip_warehouse",
"set_cost_based_on_bom_qty",
],
order_by="idx",
)
for d in data:
if not d.fixed_time:
d.time_in_mins = flt(d.time_in_mins) * flt(qty)
if d.set_cost_based_on_bom_qty:
d.time_in_mins = flt(d.time_in_mins) * flt(flt(qty) / flt(d.batch_size or 1))
else:
d.time_in_mins = flt(d.time_in_mins) * flt(qty)
d.status = "Pending"
if self.track_semi_finished_goods and not d.sequence_id:
@@ -1258,7 +1263,7 @@ class WorkOrder(Document):
operations.extend(_get_operations(node.name, qty=node.exploded_qty / node.bom_qty))
bom_qty = frappe.get_cached_value("BOM", self.bom_no, "quantity")
operations.extend(_get_operations(self.bom_no, qty=1.0 / bom_qty))
operations.extend(_get_operations(self.bom_no, qty=bom_qty))
for correct_index, operation in enumerate(operations, start=1):
operation.idx = correct_index