fix(bom): maintain a default bom for an item (#19407)

This commit is contained in:
Mangesh-Khairnar 2019-10-30 14:25:50 +05:30 committed by Nabin Hait
parent 7638788c2f
commit 83c7b5b44b

View File

@ -292,7 +292,8 @@ class BOM(WebsiteGenerator):
return valuation_rate
def manage_default_bom(self):
""" Uncheck others if current one is selected as default,
""" Uncheck others if current one is selected as default or
check the current one as default if it the only bom for the selected item,
update default bom in item master
"""
if self.is_default and self.is_active:
@ -301,6 +302,9 @@ class BOM(WebsiteGenerator):
item = frappe.get_doc("Item", self.item)
if item.default_bom != self.name:
frappe.db.set_value('Item', self.item, 'default_bom', self.name)
elif not frappe.db.exists(dict(doctype='BOM', docstatus=1, item=self.item, is_default=1)) \
and self.is_active:
frappe.db.set(self, "is_default", 1)
else:
frappe.db.set(self, "is_default", 0)
item = frappe.get_doc("Item", self.item)