Skip to content

Commit

Permalink
Merge pull request #37465 from frappe/mergify/bp/version-14-hotfix/pr…
Browse files Browse the repository at this point in the history
…-37459

refactor: add validation for Advances in SI/PI (backport #37459)
  • Loading branch information
ruthra-kumar authored Oct 12, 2023
2 parents 26ad688 + d37a181 commit f434548
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
add_days,
add_months,
cint,
comma_and,
flt,
fmt_money,
formatdate,
Expand Down Expand Up @@ -180,6 +181,17 @@ def validate(self):
self.validate_party_account_currency()

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"
if cint(self.allocate_advances_automatically) and not cint(self.get(pos_check_field)):
self.set_advances()
Expand Down

0 comments on commit f434548

Please sign in to comment.