Skip to content

Commit 6c2f9a5

Browse files
committed
fix: add base_outstanding and base_paid_amount in payment schedule table
1 parent 9026b67 commit 6c2f9a5

5 files changed

Lines changed: 78 additions & 17 deletions

File tree

erpnext/accounts/doctype/payment_entry/payment_entry.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import frappe
99
from frappe import ValidationError, _, qb, scrub, throw
10+
from frappe.model.meta import get_field_precision
1011
from frappe.query_builder import Tuple
1112
from frappe.query_builder.functions import Count
1213
from frappe.utils import cint, comma_or, flt, getdate, nowdate
@@ -825,16 +826,39 @@ def update_payment_schedule(self, cancel=0):
825826
outstanding = flt(invoice_paid_amount_map.get(key, {}).get("outstanding"))
826827
discounted_amt = flt(invoice_paid_amount_map.get(key, {}).get("discounted_amt"))
827828

829+
conversion_rate = frappe.db.get_value(key[2], {"name": key[1]}, "conversion_rate")
830+
base_paid_amount_precision = get_field_precision(
831+
frappe.get_meta("Payment Schedule").get_field("base_paid_amount")
832+
)
833+
base_outstanding_precision = get_field_precision(
834+
frappe.get_meta("Payment Schedule").get_field("base_outstanding")
835+
)
836+
837+
base_paid_amount = flt(
838+
(allocated_amount - discounted_amt) * conversion_rate, base_paid_amount_precision
839+
)
840+
base_outstanding = flt(allocated_amount * conversion_rate, base_outstanding_precision)
841+
828842
if cancel:
829843
frappe.db.sql(
830844
"""
831845
UPDATE `tabPayment Schedule`
832846
SET
833847
paid_amount = `paid_amount` - %s,
848+
base_paid_amount = `base_paid_amount` - %s,
834849
discounted_amount = `discounted_amount` - %s,
835-
outstanding = `outstanding` + %s
850+
outstanding = `outstanding` + %s,
851+
base_outstanding = `base_outstanding` - %s
836852
WHERE parent = %s and payment_term = %s""",
837-
(allocated_amount - discounted_amt, discounted_amt, allocated_amount, key[1], key[0]),
853+
(
854+
allocated_amount - discounted_amt,
855+
base_paid_amount,
856+
discounted_amt,
857+
allocated_amount,
858+
base_outstanding,
859+
key[1],
860+
key[0],
861+
),
838862
)
839863
else:
840864
if allocated_amount > outstanding:
@@ -850,10 +874,20 @@ def update_payment_schedule(self, cancel=0):
850874
UPDATE `tabPayment Schedule`
851875
SET
852876
paid_amount = `paid_amount` + %s,
877+
base_paid_amount = `base_paid_amount` + %s,
853878
discounted_amount = `discounted_amount` + %s,
854-
outstanding = `outstanding` - %s
879+
outstanding = `outstanding` - %s,
880+
base_outstanding = `base_outstanding` - %s
855881
WHERE parent = %s and payment_term = %s""",
856-
(allocated_amount - discounted_amt, discounted_amt, allocated_amount, key[1], key[0]),
882+
(
883+
allocated_amount - discounted_amt,
884+
base_paid_amount,
885+
discounted_amt,
886+
allocated_amount,
887+
base_outstanding,
888+
key[1],
889+
key[0],
890+
),
857891
)
858892

859893
def get_allocated_amount_in_transaction_currency(

erpnext/accounts/doctype/payment_schedule/payment_schedule.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"paid_amount",
2525
"discounted_amount",
2626
"column_break_3",
27-
"base_payment_amount"
27+
"base_payment_amount",
28+
"base_outstanding",
29+
"base_paid_amount"
2830
],
2931
"fields": [
3032
{
@@ -155,18 +157,34 @@
155157
"fieldtype": "Currency",
156158
"label": "Payment Amount (Company Currency)",
157159
"options": "Company:company:default_currency"
160+
},
161+
{
162+
"fieldname": "base_outstanding",
163+
"fieldtype": "Currency",
164+
"label": "Outstanding (Company Currency)",
165+
"options": "Company:company:default_currency",
166+
"read_only": 1
167+
},
168+
{
169+
"depends_on": "base_paid_amount",
170+
"fieldname": "base_paid_amount",
171+
"fieldtype": "Currency",
172+
"label": "Paid Amount (Company Currency)",
173+
"options": "Company:company:default_currency",
174+
"read_only": 1
158175
}
159176
],
160177
"index_web_pages_for_search": 1,
161178
"istable": 1,
162179
"links": [],
163-
"modified": "2024-03-27 13:10:11.356171",
180+
"modified": "2025-03-11 11:06:51.792982",
164181
"modified_by": "Administrator",
165182
"module": "Accounts",
166183
"name": "Payment Schedule",
167184
"owner": "Administrator",
168185
"permissions": [],
169186
"quick_entry": 1,
187+
"row_format": "Dynamic",
170188
"sort_field": "creation",
171189
"sort_order": "DESC",
172190
"states": [],

erpnext/accounts/doctype/payment_schedule/payment_schedule.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class PaymentSchedule(Document):
1414
if TYPE_CHECKING:
1515
from frappe.types import DF
1616

17+
base_outstanding: DF.Currency
18+
base_paid_amount: DF.Currency
1719
base_payment_amount: DF.Currency
1820
description: DF.SmallText | None
1921
discount: DF.Float

erpnext/accounts/report/accounts_receivable/accounts_receivable.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def get_payment_terms(self, row):
529529
select
530530
si.name, si.party_account_currency, si.currency, si.conversion_rate,
531531
si.total_advance, ps.due_date, ps.payment_term, ps.payment_amount, ps.base_payment_amount,
532-
ps.description, ps.paid_amount, ps.discounted_amount
532+
ps.description, ps.paid_amount, ps.base_paid_amount, ps.discounted_amount
533533
from `tab{row.voucher_type}` si, `tabPayment Schedule` ps
534534
where
535535
si.name = ps.parent and
@@ -552,20 +552,24 @@ def get_payment_terms(self, row):
552552
# Deduct that from paid amount pre allocation
553553
row.paid -= flt(payment_terms_details[0].total_advance)
554554

555+
company_currency = frappe.get_value("Company", self.filters.get("company"), "default_currency")
556+
555557
# If single payment terms, no need to split the row
556558
if len(payment_terms_details) == 1 and payment_terms_details[0].payment_term:
557-
self.append_payment_term(row, payment_terms_details[0], original_row)
559+
self.append_payment_term(row, payment_terms_details[0], original_row, company_currency)
558560
return
559561

560562
for d in payment_terms_details:
561563
term = frappe._dict(original_row)
562-
self.append_payment_term(row, d, term)
564+
self.append_payment_term(row, d, term, company_currency)
565+
566+
def append_payment_term(self, row, d, term, company_currency):
567+
invoiced = d.base_payment_amount
568+
paid_amount = d.base_paid_amount
563569

564-
def append_payment_term(self, row, d, term):
565-
if d.currency == d.party_account_currency:
570+
if company_currency == d.party_account_currency or self.filters.get("in_party_currency"):
566571
invoiced = d.payment_amount
567-
else:
568-
invoiced = d.base_payment_amount
572+
paid_amount = d.paid_amount
569573

570574
row.payment_terms.append(
571575
term.update(
@@ -574,15 +578,15 @@ def append_payment_term(self, row, d, term):
574578
"invoiced": invoiced,
575579
"invoice_grand_total": row.invoiced,
576580
"payment_term": d.description or d.payment_term,
577-
"paid": d.paid_amount + d.discounted_amount,
581+
"paid": paid_amount + d.discounted_amount,
578582
"credit_note": 0.0,
579-
"outstanding": invoiced - d.paid_amount - d.discounted_amount,
583+
"outstanding": invoiced - paid_amount - d.discounted_amount,
580584
}
581585
)
582586
)
583587

584-
if d.paid_amount:
585-
row["paid"] -= d.paid_amount + d.discounted_amount
588+
if paid_amount:
589+
row["paid"] -= paid_amount + d.discounted_amount
586590

587591
def allocate_closing_to_term(self, row, term, key):
588592
if row[key]:

erpnext/controllers/accounts_controller.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,9 @@ def set_payment_schedule(self):
23432343
base_grand_total * flt(d.invoice_portion) / 100, d.precision("base_payment_amount")
23442344
)
23452345
d.outstanding = d.payment_amount
2346+
d.base_outstanding = flt(
2347+
d.payment_amount * self.get("conversion_rate"), d.precision("base_outstanding")
2348+
)
23462349
elif not d.invoice_portion:
23472350
d.base_payment_amount = flt(
23482351
d.payment_amount * self.get("conversion_rate"), d.precision("base_payment_amount")

0 commit comments

Comments
 (0)