From 799a9cabe793838d4282dec58e11c627c520e044 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 23 May 2017 16:36:33 +0530 Subject: [PATCH] Can't change valuation method in stock settings, if there are transactions against some items which does not have it's own valuation method --- .../doctype/stock_settings/stock_settings.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.py b/erpnext/stock/doctype/stock_settings/stock_settings.py index 68d64a2474..d9d9568e40 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.py +++ b/erpnext/stock/doctype/stock_settings/stock_settings.py @@ -26,3 +26,19 @@ class StockSettings(Document): # show/hide barcode field frappe.make_property_setter({'fieldname': 'barcode', 'property': 'hidden', 'value': 0 if self.show_barcode_field else 1}) + + self.cant_change_valuation_method() + + def cant_change_valuation_method(self): + db_valuation_method = frappe.db.get_single_value("Stock Settings", "valuation_method") + + if db_valuation_method and db_valuation_method != self.valuation_method: + # check if there are any stock ledger entries against items + # which does not have it's own valuation method + sle = frappe.db.sql("""select name from `tabStock Ledger Entry` sle + where exists(select name from tabItem + where name=sle.item_code and (valuation_method is null or valuation_method='')) + """) + + if sle: + frappe.throw(_("Can't change valuation method, as there are transactions against some items which does not have it's own valuation method")) \ No newline at end of file