mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
fix(Payment Entry): split orders as per the schedules in the reference table (backport #52285)
This commit is contained in:
committed by
Mihir Kandoi
parent
a689f13ae2
commit
4cfe0d07d1
@@ -2433,6 +2433,8 @@ def get_outstanding_reference_documents(args, validate=False):
|
||||
filters=args,
|
||||
)
|
||||
|
||||
orders_to_be_billed = split_invoices_based_on_payment_terms(orders_to_be_billed, args.get("company"))
|
||||
|
||||
data = negative_outstanding_invoices + outstanding_invoices + orders_to_be_billed
|
||||
|
||||
if not data:
|
||||
@@ -2461,7 +2463,7 @@ def split_invoices_based_on_payment_terms(outstanding_invoices, company) -> list
|
||||
|
||||
outstanding_invoices_after_split = []
|
||||
for entry in outstanding_invoices:
|
||||
if entry.voucher_type in ["Sales Invoice", "Purchase Invoice"]:
|
||||
if entry.voucher_type in ["Sales Invoice", "Purchase Invoice", "Sales Order", "Purchase Order"]:
|
||||
if payment_term_template := frappe.db.get_value(
|
||||
entry.voucher_type, entry.voucher_no, "payment_terms_template"
|
||||
):
|
||||
@@ -2490,7 +2492,7 @@ def get_currency_data(outstanding_invoices: list, company: str | None = None) ->
|
||||
exc_rates = frappe._dict()
|
||||
company_currency = frappe.db.get_value("Company", company, "default_currency") if company else None
|
||||
|
||||
for doctype in ["Sales Invoice", "Purchase Invoice"]:
|
||||
for doctype in ["Sales Invoice", "Purchase Invoice", "Sales Order", "Purchase Order"]:
|
||||
invoices = [x.voucher_no for x in outstanding_invoices if x.voucher_type == doctype]
|
||||
for x in frappe.db.get_all(
|
||||
doctype,
|
||||
|
||||
@@ -2052,6 +2052,92 @@ class TestPaymentEntry(FrappeTestCase):
|
||||
self.assertEqual(rows[0].project, si.project)
|
||||
self.assertEqual(rows[1].project, si.project)
|
||||
|
||||
def test_outstanding_orders_split_by_payment_terms(self):
|
||||
create_payment_terms_template()
|
||||
|
||||
so = make_sales_order(do_not_save=1, qty=1, rate=200)
|
||||
so.payment_terms_template = "Test Receivable Template"
|
||||
so.save().submit()
|
||||
|
||||
args = {
|
||||
"posting_date": nowdate(),
|
||||
"company": so.company,
|
||||
"party_type": "Customer",
|
||||
"payment_type": "Receive",
|
||||
"party": so.customer,
|
||||
"party_account": "Debtors - _TC",
|
||||
"get_orders_to_be_billed": True,
|
||||
}
|
||||
|
||||
references = get_outstanding_reference_documents(args)
|
||||
|
||||
self.assertEqual(len(references), 2)
|
||||
self.assertEqual(references[0].voucher_no, so.name)
|
||||
self.assertEqual(references[1].voucher_no, so.name)
|
||||
self.assertEqual(references[0].payment_term, "Basic Amount Receivable")
|
||||
self.assertEqual(references[1].payment_term, "Tax Receivable")
|
||||
|
||||
def test_outstanding_orders_no_split_when_allocate_disabled(self):
|
||||
create_payment_terms_template()
|
||||
|
||||
template = frappe.get_doc("Payment Terms Template", "Test Receivable Template")
|
||||
template.allocate_payment_based_on_payment_terms = 0
|
||||
template.save()
|
||||
|
||||
so = make_sales_order(do_not_save=1, qty=1, rate=200)
|
||||
so.payment_terms_template = "Test Receivable Template"
|
||||
so.save().submit()
|
||||
|
||||
args = {
|
||||
"posting_date": nowdate(),
|
||||
"company": so.company,
|
||||
"party_type": "Customer",
|
||||
"payment_type": "Receive",
|
||||
"party": so.customer,
|
||||
"party_account": "Debtors - _TC",
|
||||
"get_orders_to_be_billed": True,
|
||||
}
|
||||
|
||||
references = get_outstanding_reference_documents(args)
|
||||
|
||||
self.assertEqual(len(references), 1)
|
||||
self.assertIsNone(references[0].payment_term)
|
||||
|
||||
template.allocate_payment_based_on_payment_terms = 1
|
||||
template.save()
|
||||
|
||||
def test_outstanding_multicurrency_sales_order_split(self):
|
||||
create_payment_terms_template()
|
||||
|
||||
so = make_sales_order(
|
||||
customer="_Test Customer USD",
|
||||
currency="USD",
|
||||
qty=1,
|
||||
rate=100,
|
||||
do_not_submit=True,
|
||||
)
|
||||
so.payment_terms_template = "Test Receivable Template"
|
||||
so.conversion_rate = 50
|
||||
so.save().submit()
|
||||
|
||||
args = {
|
||||
"posting_date": nowdate(),
|
||||
"company": so.company,
|
||||
"party_type": "Customer",
|
||||
"payment_type": "Receive",
|
||||
"party": so.customer,
|
||||
"party_account": "Debtors - _TC",
|
||||
"get_orders_to_be_billed": True,
|
||||
}
|
||||
|
||||
references = get_outstanding_reference_documents(args)
|
||||
|
||||
# Should split without throwing currency errors
|
||||
self.assertEqual(len(references), 2)
|
||||
for ref in references:
|
||||
self.assertEqual(ref.voucher_no, so.name)
|
||||
self.assertIsNotNone(ref.payment_term)
|
||||
|
||||
|
||||
def create_payment_entry(**args):
|
||||
payment_entry = frappe.new_doc("Payment Entry")
|
||||
|
||||
Reference in New Issue
Block a user