From 5fe0086d9a540b1be60cd0e8866b6610fa509000 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 16 Sep 2015 16:59:24 +0530 Subject: [PATCH] [Fixes] Warehouse check while company delete & Variant Attribute value check --- erpnext/controllers/item_variant.py | 4 ++-- erpnext/setup/doctype/company/company.py | 12 +++++++----- erpnext/stock/doctype/item/item.py | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index 4edf52b645..38536cff32 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -60,8 +60,8 @@ def validate_item_variant_attributes(item, args): if not (is_in_range and is_incremental): frappe.throw(_("Value for Attribute {0} must be within the range of {1} to {2} in the increments of {3}")\ .format(attribute, from_range, to_range, increment), InvalidItemAttributeValueError) - - elif value not in attribute_values[attribute]: + + elif value not in attribute_values.get(attribute, []): frappe.throw(_("Value {0} for Attribute {1} does not exist in the list of valid Item Attribute Values").format( value, attribute)) diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 804dc4deb9..785e7aa6fa 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -207,12 +207,14 @@ class Company(Document): frappe.defaults.clear_default("company", value=self.name) # clear default accounts, warehouses from item - for f in ["default_warehouse", "website_warehouse"]: - frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)""" - % (f, f, ', '.join(['%s']*len(warehouses))), tuple(warehouses)) + if warehouses: + + for f in ["default_warehouse", "website_warehouse"]: + frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)""" + % (f, f, ', '.join(['%s']*len(warehouses))), tuple(warehouses)) - frappe.db.sql("""delete from `tabItem Reorder` where warehouse in (%s)""" - % ', '.join(['%s']*len(warehouses)), tuple(warehouses)) + frappe.db.sql("""delete from `tabItem Reorder` where warehouse in (%s)""" + % ', '.join(['%s']*len(warehouses)), tuple(warehouses)) for f in ["income_account", "expense_account"]: frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)""" diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index d8d21ff09f..6eadb83779 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -341,10 +341,10 @@ class Item(WebsiteGenerator): frappe.throw(_("Please specify Attribute Value for attribute {0}").format(d.attribute)) args[d.attribute] = d.attribute_value - if self.get("__islocal"): + if self.variant_of: # test this during insert because naming is based on item_code and we cannot use condition like self.name != variant variant = get_variant(self.variant_of, args) - if variant: + if variant and self.get("__islocal"): frappe.throw(_("Item variant {0} exists with same attributes").format(variant), ItemVariantExistsError) def validate_end_of_life(item_code, end_of_life=None, verbose=1):