Skip to content

Commit

Permalink
fix: AR/AP report based on payment terms (#36574)
Browse files Browse the repository at this point in the history
fix: AR/AP report based on payment terms (#36574)

* fix: AR/AP report based on payment terms

* fix: AR/AP report based on payment terms

(cherry picked from commit fbb5058)

Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
  • Loading branch information
mergify[bot] and deepeshgarg007 committed Aug 14, 2023
1 parent 3044f46 commit ac0fff7
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,11 @@ def set_party_details(self, row):
def allocate_outstanding_based_on_payment_terms(self, row):
self.get_payment_terms(row)
for term in row.payment_terms:

# update "paid" and "oustanding" for this term
# update "paid" and "outstanding" for this term
if not term.paid:
self.allocate_closing_to_term(row, term, "paid")

# update "credit_note" and "oustanding" for this term
# update "credit_note" and "outstanding" for this term
if term.outstanding:
self.allocate_closing_to_term(row, term, "credit_note")

Expand All @@ -453,7 +452,8 @@ def get_payment_terms(self, row):
"""
select
si.name, si.party_account_currency, si.currency, si.conversion_rate,
ps.due_date, ps.payment_term, ps.payment_amount, ps.description, ps.paid_amount, ps.discounted_amount
si.total_advance, ps.due_date, ps.payment_term, ps.payment_amount, ps.base_payment_amount,
ps.description, ps.paid_amount, ps.discounted_amount
from `tab{0}` si, `tabPayment Schedule` ps
where
si.name = ps.parent and
Expand All @@ -469,6 +469,10 @@ def get_payment_terms(self, row):
original_row = frappe._dict(row)
row.payment_terms = []

# Advance allocated during invoicing is not considered in payment terms
# Deduct that from paid amount pre allocation
row.paid -= flt(payment_terms_details[0].total_advance)

# If no or single payment terms, no need to split the row
if len(payment_terms_details) <= 1:
return
Expand All @@ -483,7 +487,7 @@ def append_payment_term(self, row, d, term):
) and d.currency == d.party_account_currency:
invoiced = d.payment_amount
else:
invoiced = flt(flt(d.payment_amount) * flt(d.conversion_rate), self.currency_precision)
invoiced = d.base_payment_amount

row.payment_terms.append(
term.update(
Expand Down

0 comments on commit ac0fff7

Please sign in to comment.