fix: validate product bundle for existing transactions before deletion (#25978)
This commit is contained in:
parent
79daed00c1
commit
9dc625c1c9
@ -4,6 +4,8 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
|
from frappe.utils import get_link_to_form
|
||||||
|
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
@ -18,6 +20,27 @@ class ProductBundle(Document):
|
|||||||
from erpnext.utilities.transaction_base import validate_uom_is_integer
|
from erpnext.utilities.transaction_base import validate_uom_is_integer
|
||||||
validate_uom_is_integer(self, "uom", "qty")
|
validate_uom_is_integer(self, "uom", "qty")
|
||||||
|
|
||||||
|
def on_trash(self):
|
||||||
|
linked_doctypes = ["Delivery Note", "Sales Invoice", "POS Invoice", "Purchase Receipt", "Purchase Invoice",
|
||||||
|
"Stock Entry", "Stock Reconciliation", "Sales Order", "Purchase Order", "Material Request"]
|
||||||
|
|
||||||
|
invoice_links = []
|
||||||
|
for doctype in linked_doctypes:
|
||||||
|
item_doctype = doctype + " Item"
|
||||||
|
|
||||||
|
if doctype == "Stock Entry":
|
||||||
|
item_doctype = doctype + " Detail"
|
||||||
|
|
||||||
|
invoices = frappe.db.get_all(item_doctype, {"item_code": self.new_item_code, "docstatus": 1}, ["parent"])
|
||||||
|
|
||||||
|
for invoice in invoices:
|
||||||
|
invoice_links.append(get_link_to_form(doctype, invoice['parent']))
|
||||||
|
|
||||||
|
if len(invoice_links):
|
||||||
|
frappe.throw(
|
||||||
|
"This Product Bundle is linked with {0}. You will have to cancel these documents in order to delete this Product Bundle"
|
||||||
|
.format(", ".join(invoice_links)), title=_("Not Allowed"))
|
||||||
|
|
||||||
def validate_main_item(self):
|
def validate_main_item(self):
|
||||||
"""Validates, main Item is not a stock item"""
|
"""Validates, main Item is not a stock item"""
|
||||||
if frappe.db.get_value("Item", self.new_item_code, "is_stock_item"):
|
if frappe.db.get_value("Item", self.new_item_code, "is_stock_item"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user