mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 11:49:10 +00:00
Merge pull request #48595 from rohitwaghchaure/fixed-support-43674
fix: system was allowing credit notes with serial numbers for any customer
This commit is contained in:
@@ -38,6 +38,17 @@ def validate_return_against(doc):
|
||||
|
||||
party_type = "customer" if doc.doctype in ("Sales Invoice", "Delivery Note") else "supplier"
|
||||
|
||||
if ref_doc.get(party_type) != doc.get(party_type):
|
||||
frappe.throw(
|
||||
_("The {0} {1} does not match with the {0} {2} in the {3} {4}").format(
|
||||
doc.meta.get_label(party_type),
|
||||
doc.get(party_type),
|
||||
ref_doc.get(party_type),
|
||||
ref_doc.doctype,
|
||||
ref_doc.name,
|
||||
)
|
||||
)
|
||||
|
||||
if (
|
||||
ref_doc.company == doc.company
|
||||
and ref_doc.get(party_type) == doc.get(party_type)
|
||||
|
||||
@@ -61,6 +61,35 @@ class SellingController(StockController):
|
||||
if self.get(table_field):
|
||||
self.set_serial_and_batch_bundle(table_field)
|
||||
|
||||
def validate_standalone_serial_nos_customer(self):
|
||||
if not self.is_return or self.return_against:
|
||||
return
|
||||
|
||||
if self.doctype in ["Sales Invoice", "Delivery Note"]:
|
||||
bundle_ids = [d.serial_and_batch_bundle for d in self.get("items") if d.serial_and_batch_bundle]
|
||||
if not bundle_ids:
|
||||
return
|
||||
|
||||
serial_nos = frappe.get_all(
|
||||
"Serial and Batch Entry",
|
||||
filters={"parent": ("in", bundle_ids)},
|
||||
pluck="serial_no",
|
||||
)
|
||||
|
||||
if serial_nos := frappe.get_all(
|
||||
"Serial No",
|
||||
filters={"name": ("in", serial_nos), "customer": ("is", "set")},
|
||||
fields=["name", "customer"],
|
||||
):
|
||||
for sn in serial_nos:
|
||||
if sn.customer and sn.customer != self.customer:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Serial No {0} is already assigned to customer {1}. Can only be returned against the customer {1}"
|
||||
).format(frappe.bold(sn.name), frappe.bold(sn.customer)),
|
||||
title=_("Serial No Already Assigned"),
|
||||
)
|
||||
|
||||
def set_missing_values(self, for_validate=False):
|
||||
super().set_missing_values(for_validate)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user