mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-16 21:42:11 +00:00
fix: add base_outstanding and base_paid_amount in payment schedule table
(cherry picked from commit 6c2f9a563e)
# Conflicts:
# erpnext/accounts/doctype/payment_schedule/payment_schedule.json
This commit is contained in:
@@ -7,6 +7,7 @@ from functools import reduce
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import ValidationError, _, qb, scrub, throw
|
from frappe import ValidationError, _, qb, scrub, throw
|
||||||
|
from frappe.model.meta import get_field_precision
|
||||||
from frappe.query_builder import Tuple
|
from frappe.query_builder import Tuple
|
||||||
from frappe.query_builder.functions import Count
|
from frappe.query_builder.functions import Count
|
||||||
from frappe.utils import cint, comma_or, flt, getdate, nowdate
|
from frappe.utils import cint, comma_or, flt, getdate, nowdate
|
||||||
@@ -742,16 +743,39 @@ class PaymentEntry(AccountsController):
|
|||||||
outstanding = flt(invoice_paid_amount_map.get(key, {}).get("outstanding"))
|
outstanding = flt(invoice_paid_amount_map.get(key, {}).get("outstanding"))
|
||||||
discounted_amt = flt(invoice_paid_amount_map.get(key, {}).get("discounted_amt"))
|
discounted_amt = flt(invoice_paid_amount_map.get(key, {}).get("discounted_amt"))
|
||||||
|
|
||||||
|
conversion_rate = frappe.db.get_value(key[2], {"name": key[1]}, "conversion_rate")
|
||||||
|
base_paid_amount_precision = get_field_precision(
|
||||||
|
frappe.get_meta("Payment Schedule").get_field("base_paid_amount")
|
||||||
|
)
|
||||||
|
base_outstanding_precision = get_field_precision(
|
||||||
|
frappe.get_meta("Payment Schedule").get_field("base_outstanding")
|
||||||
|
)
|
||||||
|
|
||||||
|
base_paid_amount = flt(
|
||||||
|
(allocated_amount - discounted_amt) * conversion_rate, base_paid_amount_precision
|
||||||
|
)
|
||||||
|
base_outstanding = flt(allocated_amount * conversion_rate, base_outstanding_precision)
|
||||||
|
|
||||||
if cancel:
|
if cancel:
|
||||||
frappe.db.sql(
|
frappe.db.sql(
|
||||||
"""
|
"""
|
||||||
UPDATE `tabPayment Schedule`
|
UPDATE `tabPayment Schedule`
|
||||||
SET
|
SET
|
||||||
paid_amount = `paid_amount` - %s,
|
paid_amount = `paid_amount` - %s,
|
||||||
|
base_paid_amount = `base_paid_amount` - %s,
|
||||||
discounted_amount = `discounted_amount` - %s,
|
discounted_amount = `discounted_amount` - %s,
|
||||||
outstanding = `outstanding` + %s
|
outstanding = `outstanding` + %s,
|
||||||
|
base_outstanding = `base_outstanding` - %s
|
||||||
WHERE parent = %s and payment_term = %s""",
|
WHERE parent = %s and payment_term = %s""",
|
||||||
(allocated_amount - discounted_amt, discounted_amt, allocated_amount, key[1], key[0]),
|
(
|
||||||
|
allocated_amount - discounted_amt,
|
||||||
|
base_paid_amount,
|
||||||
|
discounted_amt,
|
||||||
|
allocated_amount,
|
||||||
|
base_outstanding,
|
||||||
|
key[1],
|
||||||
|
key[0],
|
||||||
|
),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if allocated_amount > outstanding:
|
if allocated_amount > outstanding:
|
||||||
@@ -767,10 +791,20 @@ class PaymentEntry(AccountsController):
|
|||||||
UPDATE `tabPayment Schedule`
|
UPDATE `tabPayment Schedule`
|
||||||
SET
|
SET
|
||||||
paid_amount = `paid_amount` + %s,
|
paid_amount = `paid_amount` + %s,
|
||||||
|
base_paid_amount = `base_paid_amount` + %s,
|
||||||
discounted_amount = `discounted_amount` + %s,
|
discounted_amount = `discounted_amount` + %s,
|
||||||
outstanding = `outstanding` - %s
|
outstanding = `outstanding` - %s,
|
||||||
|
base_outstanding = `base_outstanding` - %s
|
||||||
WHERE parent = %s and payment_term = %s""",
|
WHERE parent = %s and payment_term = %s""",
|
||||||
(allocated_amount - discounted_amt, discounted_amt, allocated_amount, key[1], key[0]),
|
(
|
||||||
|
allocated_amount - discounted_amt,
|
||||||
|
base_paid_amount,
|
||||||
|
discounted_amt,
|
||||||
|
allocated_amount,
|
||||||
|
base_outstanding,
|
||||||
|
key[1],
|
||||||
|
key[0],
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_allocated_amount_in_transaction_currency(
|
def get_allocated_amount_in_transaction_currency(
|
||||||
|
|||||||
@@ -24,7 +24,9 @@
|
|||||||
"paid_amount",
|
"paid_amount",
|
||||||
"discounted_amount",
|
"discounted_amount",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"base_payment_amount"
|
"base_payment_amount",
|
||||||
|
"base_outstanding",
|
||||||
|
"base_paid_amount"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -155,19 +157,43 @@
|
|||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"label": "Payment Amount (Company Currency)",
|
"label": "Payment Amount (Company Currency)",
|
||||||
"options": "Company:company:default_currency"
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "base_outstanding",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Outstanding (Company Currency)",
|
||||||
|
"options": "Company:company:default_currency",
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "base_paid_amount",
|
||||||
|
"fieldname": "base_paid_amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Paid Amount (Company Currency)",
|
||||||
|
"options": "Company:company:default_currency",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
|
<<<<<<< HEAD
|
||||||
"modified": "2022-09-16 13:57:06.382859",
|
"modified": "2022-09-16 13:57:06.382859",
|
||||||
|
=======
|
||||||
|
"modified": "2025-03-11 11:06:51.792982",
|
||||||
|
>>>>>>> 6c2f9a563e (fix: add base_outstanding and base_paid_amount in payment schedule table)
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Schedule",
|
"name": "Payment Schedule",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
"quick_entry": 1,
|
"quick_entry": 1,
|
||||||
|
<<<<<<< HEAD
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
|
=======
|
||||||
|
"row_format": "Dynamic",
|
||||||
|
"sort_field": "creation",
|
||||||
|
>>>>>>> 6c2f9a563e (fix: add base_outstanding and base_paid_amount in payment schedule table)
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": [],
|
"states": [],
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class PaymentSchedule(Document):
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from frappe.types import DF
|
from frappe.types import DF
|
||||||
|
|
||||||
|
base_outstanding: DF.Currency
|
||||||
|
base_paid_amount: DF.Currency
|
||||||
base_payment_amount: DF.Currency
|
base_payment_amount: DF.Currency
|
||||||
description: DF.SmallText | None
|
description: DF.SmallText | None
|
||||||
discount: DF.Float
|
discount: DF.Float
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ class ReceivablePayableReport:
|
|||||||
select
|
select
|
||||||
si.name, si.party_account_currency, si.currency, si.conversion_rate,
|
si.name, si.party_account_currency, si.currency, si.conversion_rate,
|
||||||
si.total_advance, ps.due_date, ps.payment_term, ps.payment_amount, ps.base_payment_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
|
ps.description, ps.paid_amount, ps.base_paid_amount, ps.discounted_amount
|
||||||
from `tab{row.voucher_type}` si, `tabPayment Schedule` ps
|
from `tab{row.voucher_type}` si, `tabPayment Schedule` ps
|
||||||
where
|
where
|
||||||
si.name = ps.parent and ps.parenttype = '{row.voucher_type}' and
|
si.name = ps.parent and ps.parenttype = '{row.voucher_type}' and
|
||||||
@@ -540,20 +540,24 @@ class ReceivablePayableReport:
|
|||||||
# Deduct that from paid amount pre allocation
|
# Deduct that from paid amount pre allocation
|
||||||
row.paid -= flt(payment_terms_details[0].total_advance)
|
row.paid -= flt(payment_terms_details[0].total_advance)
|
||||||
|
|
||||||
|
company_currency = frappe.get_value("Company", self.filters.get("company"), "default_currency")
|
||||||
|
|
||||||
# If single payment terms, no need to split the row
|
# If single payment terms, no need to split the row
|
||||||
if len(payment_terms_details) == 1 and payment_terms_details[0].payment_term:
|
if len(payment_terms_details) == 1 and payment_terms_details[0].payment_term:
|
||||||
self.append_payment_term(row, payment_terms_details[0], original_row)
|
self.append_payment_term(row, payment_terms_details[0], original_row, company_currency)
|
||||||
return
|
return
|
||||||
|
|
||||||
for d in payment_terms_details:
|
for d in payment_terms_details:
|
||||||
term = frappe._dict(original_row)
|
term = frappe._dict(original_row)
|
||||||
self.append_payment_term(row, d, term)
|
self.append_payment_term(row, d, term, company_currency)
|
||||||
|
|
||||||
def append_payment_term(self, row, d, term):
|
def append_payment_term(self, row, d, term, company_currency):
|
||||||
if d.currency == d.party_account_currency:
|
invoiced = d.base_payment_amount
|
||||||
|
paid_amount = d.base_paid_amount
|
||||||
|
|
||||||
|
if company_currency == d.party_account_currency or self.filters.get("in_party_currency"):
|
||||||
invoiced = d.payment_amount
|
invoiced = d.payment_amount
|
||||||
else:
|
paid_amount = d.paid_amount
|
||||||
invoiced = d.base_payment_amount
|
|
||||||
|
|
||||||
row.payment_terms.append(
|
row.payment_terms.append(
|
||||||
term.update(
|
term.update(
|
||||||
@@ -562,15 +566,15 @@ class ReceivablePayableReport:
|
|||||||
"invoiced": invoiced,
|
"invoiced": invoiced,
|
||||||
"invoice_grand_total": row.invoiced,
|
"invoice_grand_total": row.invoiced,
|
||||||
"payment_term": d.description or d.payment_term,
|
"payment_term": d.description or d.payment_term,
|
||||||
"paid": d.paid_amount + d.discounted_amount,
|
"paid": paid_amount + d.discounted_amount,
|
||||||
"credit_note": 0.0,
|
"credit_note": 0.0,
|
||||||
"outstanding": invoiced - d.paid_amount - d.discounted_amount,
|
"outstanding": invoiced - paid_amount - d.discounted_amount,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if d.paid_amount:
|
if paid_amount:
|
||||||
row["paid"] -= d.paid_amount + d.discounted_amount
|
row["paid"] -= paid_amount + d.discounted_amount
|
||||||
|
|
||||||
def allocate_closing_to_term(self, row, term, key):
|
def allocate_closing_to_term(self, row, term, key):
|
||||||
if row[key]:
|
if row[key]:
|
||||||
|
|||||||
@@ -2363,6 +2363,9 @@ class AccountsController(TransactionBase):
|
|||||||
base_grand_total * flt(d.invoice_portion) / 100, d.precision("base_payment_amount")
|
base_grand_total * flt(d.invoice_portion) / 100, d.precision("base_payment_amount")
|
||||||
)
|
)
|
||||||
d.outstanding = d.payment_amount
|
d.outstanding = d.payment_amount
|
||||||
|
d.base_outstanding = flt(
|
||||||
|
d.payment_amount * self.get("conversion_rate"), d.precision("base_outstanding")
|
||||||
|
)
|
||||||
elif not d.invoice_portion:
|
elif not d.invoice_portion:
|
||||||
d.base_payment_amount = flt(
|
d.base_payment_amount = flt(
|
||||||
d.payment_amount * self.get("conversion_rate"), d.precision("base_payment_amount")
|
d.payment_amount * self.get("conversion_rate"), d.precision("base_payment_amount")
|
||||||
|
|||||||
Reference in New Issue
Block a user