Merge pull request #32428 from s-aga-r/fix/item/update-stock

fix: don't allow to update `Maintain Stock` if the item has a `BOM`
This commit is contained in:
Sagar Sharma 2022-09-30 19:08:19 +05:30 committed by GitHub
commit 793295cfe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -937,17 +937,21 @@ class Item(Document):
"Purchase Order Item", "Purchase Order Item",
"Material Request Item", "Material Request Item",
"Product Bundle", "Product Bundle",
"BOM",
] ]
for doctype in linked_doctypes: for doctype in linked_doctypes:
filters = {"item_code": self.name, "docstatus": 1} filters = {"item_code": self.name, "docstatus": 1}
if doctype in ("Product Bundle", "BOM"):
if doctype == "Product Bundle": if doctype == "Product Bundle":
filters = {"new_item_code": self.name} filters = {"new_item_code": self.name}
fieldname = "new_item_code as docname"
else:
filters = {"item": self.name, "docstatus": 1}
fieldname = "name as docname"
if linked_doc := frappe.db.get_value( if linked_doc := frappe.db.get_value(doctype, filters, fieldname, as_dict=True):
doctype, filters, ["new_item_code as docname"], as_dict=True
):
return linked_doc.update({"doctype": doctype}) return linked_doc.update({"doctype": doctype})
elif doctype in ( elif doctype in (