Skip to content

Commit

Permalink
fix: incorrectly treating normal payment as advance (#38437)
Browse files Browse the repository at this point in the history
fix: treating normal payment as advance
  • Loading branch information
ruthra-kumar authored Dec 4, 2023
1 parent d659d40 commit dd39da0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,17 @@ def on_submit(self):
self.set_status()

def set_liability_account(self):
if not self.book_advance_payments_in_separate_party_account:
# Auto setting liability account should only be done during 'draft' status
if self.docstatus > 0:
return

if not frappe.db.get_value(
"Company", self.company, "book_advance_payments_in_separate_party_account"
):
return

# Important to set this flag for the gl building logic to work properly
self.book_advance_payments_in_separate_party_account = True
account_type = frappe.get_value(
"Account", {"name": self.party_account, "company": self.company}, "account_type"
)
Expand All @@ -118,11 +126,13 @@ def set_liability_account(self):
):
return

if self.unallocated_amount == 0:
for d in self.references:
if d.reference_doctype in ["Sales Order", "Purchase Order"]:
break
else:
if self.references:
allowed_types = frozenset(["Sales Order", "Purchase Order"])
reference_types = set([x.reference_doctype for x in self.references])

# If there are referencers other than `allowed_types`, treat this as a normal payment entry
if reference_types - allowed_types:
self.book_advance_payments_in_separate_party_account = False
return

liability_account = get_party_account(
Expand Down

0 comments on commit dd39da0

Please sign in to comment.