diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 1efb5446840..39f0a0a4258 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -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 = ( diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index 1a8e8c53590..4cfd8232d88 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -1234,13 +1234,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: @@ -1263,7 +1268,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