refactor: add validation for Advances in SI/PI

This commit is contained in:
ruthra kumar 2023-10-11 14:42:23 +05:30
parent cea0d65fbd
commit 0cdd6435a5

View File

@ -13,6 +13,7 @@ from frappe.utils import (
add_days, add_days,
add_months, add_months,
cint, cint,
comma_and,
flt, flt,
fmt_money, fmt_money,
formatdate, formatdate,
@ -181,6 +182,17 @@ class AccountsController(TransactionBase):
self.validate_party_account_currency() self.validate_party_account_currency()
if self.doctype in ["Purchase Invoice", "Sales Invoice"]: if self.doctype in ["Purchase Invoice", "Sales Invoice"]:
if invalid_advances := [
x for x in self.advances if not x.reference_type or not x.reference_name
]:
frappe.throw(
_(
"Rows: {0} in {1} section are Invalid. Reference Name should point to a valid Payment Entry or Journal Entry."
).format(
frappe.bold(comma_and([x.idx for x in invalid_advances])), frappe.bold(_("Advance Payments"))
)
)
pos_check_field = "is_pos" if self.doctype == "Sales Invoice" else "is_paid" pos_check_field = "is_pos" if self.doctype == "Sales Invoice" else "is_paid"
if cint(self.allocate_advances_automatically) and not cint(self.get(pos_check_field)): if cint(self.allocate_advances_automatically) and not cint(self.get(pos_check_field)):
self.set_advances() self.set_advances()