Skip to content

Commit

Permalink
feat: Add operating cost based on bom quanity without creating job card
Browse files Browse the repository at this point in the history
(cherry picked from commit b559245)
  • Loading branch information
vishdha authored and mergify[bot] committed Jan 20, 2023
1 parent 1c1c903 commit 0035ee2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
28 changes: 20 additions & 8 deletions erpnext/manufacturing/doctype/bom/bom.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ frappe.ui.form.on("BOM", {
});
},

onload_post_render(frm) {
validate: function(frm) {
if (frm.doc.fg_based_operating_cost && frm.doc.with_operations) {
frappe.throw({message: __("Please check either with operations or FG Based Operating Cost."), title: __("Mandatory")});
}
},

onload_post_render: function(frm) {
frm.get_field("items").grid.set_multiple_add("item_code", "qty");
},

Expand Down Expand Up @@ -536,14 +542,20 @@ erpnext.bom.calculate_op_cost = function(doc) {
doc.operating_cost = 0.0;
doc.base_operating_cost = 0.0;

for(var i=0;i<op.length;i++) {
var operating_cost = flt(flt(op[i].hour_rate) * flt(op[i].time_in_mins) / 60, 2);
var base_operating_cost = flt(operating_cost * doc.conversion_rate, 2);
frappe.model.set_value('BOM Operation',op[i].name, "operating_cost", operating_cost);
frappe.model.set_value('BOM Operation',op[i].name, "base_operating_cost", base_operating_cost);
if(doc.with_operations) {
for(var i=0;i<op.length;i++) {
var operating_cost = flt(flt(op[i].hour_rate) * flt(op[i].time_in_mins) / 60, 2);
var base_operating_cost = flt(operating_cost * doc.conversion_rate, 2);
frappe.model.set_value('BOM Operation',op[i].name, "operating_cost", operating_cost);
frappe.model.set_value('BOM Operation',op[i].name, "base_operating_cost", base_operating_cost);

doc.operating_cost += operating_cost;
doc.base_operating_cost += base_operating_cost;
doc.operating_cost += operating_cost;
doc.base_operating_cost += base_operating_cost;
}
} else if(doc.fg_based_operating_cost) {
let total_operating_cost = doc.quantity * flt(doc.operating_cost_per_bom_quantity);
doc.operating_cost = total_operating_cost;
doc.base_operating_cost = flt(total_operating_cost * doc.conversion_rate, 2);
}
refresh_field(['operating_cost', 'base_operating_cost']);
};
Expand Down
24 changes: 23 additions & 1 deletion erpnext/manufacturing/doctype/bom/bom.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"column_break_23",
"transfer_material_against",
"routing",
"fg_based_operating_cost",
"fg_based_section_section",
"operating_cost_per_bom_quantity",
"operations_section",
"operations",
"materials_section",
Expand Down Expand Up @@ -575,7 +578,26 @@
{
"fieldname": "scrap_items_section",
"fieldtype": "Section Break",
"label": "Scrap Items"
"label": "Scrap Items",
"hide_border": 1
},
{
"default": "0",
"fieldname": "fg_based_operating_cost",
"fieldtype": "Check",
"label": "FG based Operating Cost"
},
{
"depends_on": "fg_based_operating_cost",
"fieldname": "fg_based_section_section",
"fieldtype": "Section Break",
"label": "FG Based Operating Cost Section"
},
{
"depends_on": "fg_based_operating_cost",
"fieldname": "operating_cost_per_bom_quantity",
"fieldtype": "Currency",
"label": "Operating Cost Per BOM Quantity"
}
],
"icon": "fa fa-sitemap",
Expand Down
30 changes: 18 additions & 12 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,18 +614,24 @@ def calculate_op_cost(self, update_hour_rate=False):
"""Update workstation rate and calculates totals"""
self.operating_cost = 0
self.base_operating_cost = 0
for d in self.get("operations"):
if d.workstation:
self.update_rate_and_time(d, update_hour_rate)

operating_cost = d.operating_cost
base_operating_cost = d.base_operating_cost
if d.set_cost_based_on_bom_qty:
operating_cost = flt(d.cost_per_unit) * flt(self.quantity)
base_operating_cost = flt(d.base_cost_per_unit) * flt(self.quantity)

self.operating_cost += flt(operating_cost)
self.base_operating_cost += flt(base_operating_cost)
if (self.get("with_operations")):
for d in self.get("operations"):
if d.workstation:
self.update_rate_and_time(d, update_hour_rate)

operating_cost = d.operating_cost
base_operating_cost = d.base_operating_cost
if d.set_cost_based_on_bom_qty:
operating_cost = flt(d.cost_per_unit) * flt(self.quantity)
base_operating_cost = flt(d.base_cost_per_unit) * flt(self.quantity)

self.operating_cost += flt(operating_cost)
self.base_operating_cost += flt(base_operating_cost)

elif(self.get("fg_based_operating_cost")):
total_operating_cost = flt(self.get("quantity")) * flt(self.get("operating_cost_per_bom_quantity"))
self.operating_cost = total_operating_cost
self.base_operating_cost = flt(total_operating_cost * self.conversion_rate, 2)

def update_rate_and_time(self, row, update_hour_rate=False):
if not row.hour_rate or update_hour_rate:
Expand Down

0 comments on commit 0035ee2

Please sign in to comment.