From a16f0f44232e12d39ff374d9ce0d72938ba838a0 Mon Sep 17 00:00:00 2001 From: Alchez Date: Thu, 11 Oct 2018 16:56:46 +0530 Subject: [PATCH] fix(item_defaults): handle multiple item defaults for a company (#15634) --- erpnext/stock/doctype/item/item.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index f32e959903..17cf044074 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -122,6 +122,7 @@ class Item(WebsiteGenerator): self.validate_fixed_asset() self.validate_retain_sample() self.validate_uom_conversion_factor() + self.validate_item_defaults() self.update_defaults_from_item_group() if not self.get("__islocal"): @@ -663,6 +664,12 @@ class Item(WebsiteGenerator): template_item.flags.ignore_permissions = True template_item.save() + def validate_item_defaults(self): + companies = list(set([row.company for row in self.item_defaults])) + + if len(companies) != len(self.item_defaults): + frappe.throw(_("Cannot set multiple Item Defaults for a company.")) + def update_defaults_from_item_group(self): """Get defaults from Item Group""" if self.item_group and not self.item_defaults: