From dab1cf9f6cd68299eaeacc9b1d4211c0f5d0809f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 26 Jul 2013 12:00:41 +0530 Subject: [PATCH 1/2] [feature] [bom] update cost button --- manufacturing/doctype/bom/bom.js | 11 +++++++++++ manufacturing/doctype/bom/bom.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/manufacturing/doctype/bom/bom.js b/manufacturing/doctype/bom/bom.js index 276e883f813..ce246d921a0 100644 --- a/manufacturing/doctype/bom/bom.js +++ b/manufacturing/doctype/bom/bom.js @@ -20,12 +20,23 @@ cur_frm.cscript.refresh = function(doc,dt,dn){ if (!doc.__islocal && doc.docstatus==0) { cur_frm.set_intro("Submit the BOM to use it for manufacturing or repacking."); + cur_frm.add_custom_button("Update Cost", cur_frm.cscript.update_cost); } else cur_frm.set_intro(""); cur_frm.cscript.with_operations(doc); set_operation_no(doc); } +cur_frm.cscript.update_cost = function() { + wn.call({ + doc: cur_frm.doc, + method: "update_cost", + callback: function(r) { + if(!r.exc) cur_frm.refresh_fields(); + } + }) +} + cur_frm.cscript.with_operations = function(doc) { cur_frm.fields_dict["bom_materials"].grid.set_column_disp("operation_no", doc.with_operations); cur_frm.fields_dict["bom_materials"].grid.toggle_reqd("operation_no", doc.with_operations) diff --git a/manufacturing/doctype/bom/bom.py b/manufacturing/doctype/bom/bom.py index b4091b93767..e4c81ff0db4 100644 --- a/manufacturing/doctype/bom/bom.py +++ b/manufacturing/doctype/bom/bom.py @@ -135,6 +135,17 @@ class DocType: rate = arg['standard_rate'] return rate + + def update_cost(self): + for d in self.doclist.get({"parentfield": "bom_materials"}): + d.rate = self.get_bom_material_detail({ + 'item_code': d.item_code, + 'bom_no': d.bom_no, + 'qty': d.qty + })["rate"] + + self.on_update() + def get_bom_unitcost(self, bom_no): bom = sql("""select name, total_cost/quantity as unit_cost from `tabBOM` From e32921562b10f23366834d2d21628b82c5b80ccc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 26 Jul 2013 12:51:06 +0530 Subject: [PATCH 2/2] [fix] [minor] over-billing validation --- controllers/accounts_controller.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py index 56ddfd12b2d..f73d16a1678 100644 --- a/controllers/accounts_controller.py +++ b/controllers/accounts_controller.py @@ -389,10 +389,11 @@ class AccountsController(TransactionBase): where %s=%s and docstatus=1""" % (based_on, self.tname, item_ref_dn, '%s'), item.fields[item_ref_dn])[0][0] - max_allowed_amt = webnotes.conn.get_value(ref_dt + " Item", - item.fields[item_ref_dn], based_on) + max_allowed_amt = flt(webnotes.conn.get_value(ref_dt + " Item", + item.fields[item_ref_dn], based_on)) - if flt(already_billed) + flt(item.fields[based_on]) > max_allowed_amt: + if max_allowed_amt and \ + flt(already_billed) + flt(item.fields[based_on]) > max_allowed_amt: webnotes.msgprint(_("Row ")+ cstr(item.idx) + ": " + cstr(item.item_code) + _(" will be over-billed against mentioned ") + cstr(ref_dt) + _(". Max allowed " + cstr(based_on) + ": " + cstr(max_allowed_amt)),