From e33d0be32c38485f7705af8ad12e59fe43645f80 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 6 Sep 2013 13:23:33 +0530 Subject: [PATCH 1/2] [fix] [minor] changed uom replace utility message --- stock/doctype/item/item.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py index e6c277ee08..f5d50be7a7 100644 --- a/stock/doctype/item/item.py +++ b/stock/doctype/item/item.py @@ -62,13 +62,12 @@ class DocType(DocListController): def check_stock_uom_with_bin(self): if not self.doc.fields.get("__islocal"): - bin = webnotes.conn.sql("select stock_uom from `tabBin` where item_code = %s", - self.doc.name) - if self.doc.stock_uom and bin and cstr(bin[0][0]) \ - and cstr(bin[0][0]) != cstr(self.doc.stock_uom): - msgprint(_("Please Update Stock UOM with the help of Stock UOM Replace Utility."), - raise_exception=1) - + bin_uom = webnotes.conn.get_value("Bin", {"item_code": self.doc.name}, "stock_uom") + if self.doc.stock_uom and bin_uom and cstr(bin_uom) != cstr(self.doc.stock_uom): + webnotes.throw(_("Default Unit of Measure can not be changed directly \ + because you have already made some transaction(s) with another UOM. \ + To change default UOM, use 'UOM Replace Utility' tool under Stock module.")) + def validate_conversion_factor(self): check_list = [] for d in getlist(self.doclist,'uom_conversion_details'): From 78fde78405378e15fd93e62d2a6f97a31dd59161 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 6 Sep 2013 14:05:47 +0530 Subject: [PATCH 2/2] [fix] [minor] changed uom replace utility message --- stock/doctype/item/item.py | 12 +++++++++--- .../stock_uom_replace_utility.py | 16 +++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py index f5d50be7a7..ac9f18fcd0 100644 --- a/stock/doctype/item/item.py +++ b/stock/doctype/item/item.py @@ -30,8 +30,8 @@ class DocType(DocListController): self.check_warehouse_is_set_for_stock_item() self.check_stock_uom_with_bin() - self.validate_conversion_factor() self.add_default_uom_in_conversion_factor_table() + self.validate_conversion_factor() self.valiadte_item_type() self.check_for_active_boms() self.validate_price_lists() @@ -59,15 +59,21 @@ class DocType(DocListController): ch = addchild(self.doc, 'uom_conversion_details', 'UOM Conversion Detail', self.doclist) ch.uom = self.doc.stock_uom ch.conversion_factor = 1 + + for d in self.doclist.get({"parentfield": "uom_conversion_details"}): + if d.conversion_factor == 1 and d.uom != self.doc.stock_uom: + self.doclist.remove(d) + def check_stock_uom_with_bin(self): if not self.doc.fields.get("__islocal"): bin_uom = webnotes.conn.get_value("Bin", {"item_code": self.doc.name}, "stock_uom") if self.doc.stock_uom and bin_uom and cstr(bin_uom) != cstr(self.doc.stock_uom): + webnotes.errprint([self.doc.stock_uom, bin_uom]) webnotes.throw(_("Default Unit of Measure can not be changed directly \ - because you have already made some transaction(s) with another UOM. \ + because you have already made some transaction(s) with another UOM.\n \ To change default UOM, use 'UOM Replace Utility' tool under Stock module.")) - + def validate_conversion_factor(self): check_list = [] for d in getlist(self.doclist,'uom_conversion_details'): diff --git a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py index 4e69a37803..eff62f6ddf 100644 --- a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py +++ b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py @@ -8,7 +8,7 @@ from webnotes.utils import cstr, flt, now, cint from webnotes.model import db_exists from webnotes.model.bean import copy_doclist from webnotes.model.code import get_obj -from webnotes import msgprint +from webnotes import msgprint, _ sql = webnotes.conn.sql @@ -41,11 +41,11 @@ class DocType: raise Exception def update_item_master(self): - # update stock uom in item master - sql("update `tabItem` set stock_uom = '%s' where name = '%s' " % (self.doc.new_stock_uom, self.doc.item_code)) + item_bean = webnotes.bean("Item", self.doc.item_code) + item_bean.doc.stock_uom = self.doc.new_stock_uom + item_bean.save() - # acknowledge user - msgprint("New Stock UOM : " + cstr(self.doc.new_stock_uom) + " updated in Item : " + cstr(self.doc.item_code)) + msgprint(_("Default UOM updated in item ") + self.doc.item_code) def update_bin(self): # update bin @@ -80,20 +80,14 @@ class DocType: # Update Stock UOM def update_stock_uom(self): - # validate mandatory self.validate_mandatory() self.validate_uom_integer_type() - # update item master self.update_item_master() - # update stock ledger entry self.update_stock_ledger_entry() - # update bin self.update_bin() - - get_obj("Item", self.doc.item_code).on_update() def validate_uom_integer_type(self): current_is_integer = webnotes.conn.get_value("UOM", self.doc.current_stock_uom, "must_be_whole_number")