Skip to content

Commit

Permalink
test: get_outstanding_reference_documents (triggered via UI)
Browse files Browse the repository at this point in the history
  • Loading branch information
marination committed Nov 7, 2023
1 parent 6bd56d2 commit 162c049
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion erpnext/accounts/doctype/payment_entry/test_payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import frappe
from frappe import qb
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import flt, nowdate
from frappe.utils import add_days, flt, nowdate

from erpnext.accounts.doctype.payment_entry.payment_entry import (
InvalidPaymentEntry,
get_outstanding_reference_documents,
get_payment_entry,
get_reference_details,
)
Expand Down Expand Up @@ -1262,6 +1263,42 @@ def test_allocation_validation_for_sales_order(self):
so.reload()
self.assertEqual(so.advance_paid, so.rounded_total)

def test_outstanding_invoices_api(self):
"""
Test if `get_outstanding_reference_documents` fetches invoices in the right order.
"""
customer = create_customer("Max Mustermann", "INR")
create_payment_terms_template()

si = create_sales_invoice(qty=1, rate=100, customer=customer)
si2 = create_sales_invoice(do_not_save=1, qty=1, rate=100, customer=customer)
si2.payment_terms_template = "Test Receivable Template"
si2.submit()

args = {
"posting_date": nowdate(),
"company": "_Test Company",
"party_type": "Customer",
"payment_type": "Pay",
"party": customer,
"party_account": "Debtors - _TC",
}
args.update(
{
"get_outstanding_invoices": True,
"from_posting_date": nowdate(),
"to_posting_date": add_days(nowdate(), 7),
}
)
references = get_outstanding_reference_documents(args)

self.assertEqual(len(references), 3)
self.assertEqual(references[0].voucher_no, si.name)
self.assertEqual(references[1].voucher_no, si2.name)
self.assertEqual(references[2].voucher_no, si2.name)
self.assertEqual(references[1].payment_term, "Basic Amount Receivable")
self.assertEqual(references[2].payment_term, "Tax Receivable")


def create_payment_entry(**args):
payment_entry = frappe.new_doc("Payment Entry")
Expand Down Expand Up @@ -1322,6 +1359,9 @@ def create_payment_terms_template():
def create_payment_terms_template_with_discount(
name=None, discount_type=None, discount=None, template_name=None
):
"""
Create a Payment Terms Template with % or amount discount.
"""
create_payment_term(name or "30 Credit Days with 10% Discount")
template_name = template_name or "Test Discount Template"

Expand Down

0 comments on commit 162c049

Please sign in to comment.