mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 15:39:20 +00:00
feat: tests for discounted payment terms
This commit is contained in:
committed by
Deepesh Garg
parent
e42f423ed8
commit
427f9b6367
@@ -1223,7 +1223,7 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
|
|||||||
pe.set_gain_or_loss(account_details={
|
pe.set_gain_or_loss(account_details={
|
||||||
'account': frappe.get_cached_value('Company', pe.company, "default_discount_account"),
|
'account': frappe.get_cached_value('Company', pe.company, "default_discount_account"),
|
||||||
'cost_center': pe.cost_center or frappe.get_cached_value('Company', pe.company, "cost_center"),
|
'cost_center': pe.cost_center or frappe.get_cached_value('Company', pe.company, "cost_center"),
|
||||||
'amount': discount_amount * -1 if payment_type == "Pay" else 1
|
'amount': discount_amount * (-1 if payment_type == "Pay" else 1)
|
||||||
})
|
})
|
||||||
pe.set_difference_amount()
|
pe.set_difference_amount()
|
||||||
|
|
||||||
|
|||||||
@@ -193,6 +193,34 @@ class TestPaymentEntry(unittest.TestCase):
|
|||||||
self.assertEqual(si.payment_schedule[0].paid_amount, 200.0)
|
self.assertEqual(si.payment_schedule[0].paid_amount, 200.0)
|
||||||
self.assertEqual(si.payment_schedule[1].paid_amount, 36.0)
|
self.assertEqual(si.payment_schedule[1].paid_amount, 36.0)
|
||||||
|
|
||||||
|
def test_payment_entry_against_payment_terms_with_discount(self):
|
||||||
|
si = create_sales_invoice(do_not_save=1, qty=1, rate=200)
|
||||||
|
create_payment_terms_template_with_discount()
|
||||||
|
si.payment_terms_template = 'Test Discount Template'
|
||||||
|
|
||||||
|
frappe.db.set_value('Company', si.company, 'default_discount_account', 'Write Off - _TC')
|
||||||
|
|
||||||
|
si.append('taxes', {
|
||||||
|
"charge_type": "On Net Total",
|
||||||
|
"account_head": "_Test Account Service Tax - _TC",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"description": "Service Tax",
|
||||||
|
"rate": 18
|
||||||
|
})
|
||||||
|
si.save()
|
||||||
|
|
||||||
|
si.submit()
|
||||||
|
|
||||||
|
pe = get_payment_entry("Sales Invoice", si.name, bank_account="_Test Cash - _TC")
|
||||||
|
pe.submit()
|
||||||
|
si.load_from_db()
|
||||||
|
|
||||||
|
self.assertEqual(pe.references[0].payment_term, '30 Credit Days with 10% Discount')
|
||||||
|
self.assertEqual(si.payment_schedule[0].payment_amount, 236.0)
|
||||||
|
self.assertEqual(si.payment_schedule[0].paid_amount, 212.40)
|
||||||
|
self.assertEqual(si.payment_schedule[0].outstanding, 0)
|
||||||
|
self.assertEqual(si.payment_schedule[0].discounted_amount, 23.6)
|
||||||
|
|
||||||
|
|
||||||
def test_payment_against_purchase_invoice_to_check_status(self):
|
def test_payment_against_purchase_invoice_to_check_status(self):
|
||||||
pi = make_purchase_invoice(supplier="_Test Supplier USD", debit_to="_Test Payable USD - _TC",
|
pi = make_purchase_invoice(supplier="_Test Supplier USD", debit_to="_Test Payable USD - _TC",
|
||||||
@@ -591,6 +619,26 @@ def create_payment_terms_template():
|
|||||||
}]
|
}]
|
||||||
}).insert()
|
}).insert()
|
||||||
|
|
||||||
|
def create_payment_terms_template_with_discount():
|
||||||
|
|
||||||
|
create_payment_term('30 Credit Days with 10% Discount')
|
||||||
|
|
||||||
|
if not frappe.db.exists('Payment Terms Template', 'Test Discount Template'):
|
||||||
|
payment_term_template = frappe.get_doc({
|
||||||
|
'doctype': 'Payment Terms Template',
|
||||||
|
'template_name': 'Test Discount Template',
|
||||||
|
'allocate_payment_based_on_payment_terms': 1,
|
||||||
|
'terms': [{
|
||||||
|
'doctype': 'Payment Terms Template Detail',
|
||||||
|
'payment_term': '30 Credit Days with 10% Discount',
|
||||||
|
'invoice_portion': 100,
|
||||||
|
'credit_days_based_on': 'Day(s) after invoice date',
|
||||||
|
'credit_days': 2,
|
||||||
|
'discount': 10,
|
||||||
|
'discount_validity_based_on': 'Day(s) after invoice date',
|
||||||
|
'discount_validity': 1
|
||||||
|
}]
|
||||||
|
}).insert()
|
||||||
|
|
||||||
def create_payment_term(name):
|
def create_payment_term(name):
|
||||||
if not frappe.db.exists('Payment Term', name):
|
if not frappe.db.exists('Payment Term', name):
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
{
|
{
|
||||||
"columns": 2,
|
"columns": 2,
|
||||||
"fetch_from": "payment_term.due_date_based_on",
|
"fetch_from": "payment_term.due_date_based_on",
|
||||||
|
"fetch_if_empty": 1,
|
||||||
"fieldname": "due_date_based_on",
|
"fieldname": "due_date_based_on",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
@@ -100,6 +101,7 @@
|
|||||||
{
|
{
|
||||||
"default": "Percentage",
|
"default": "Percentage",
|
||||||
"fetch_from": "payment_term.discount_type",
|
"fetch_from": "payment_term.discount_type",
|
||||||
|
"fetch_if_empty": 1,
|
||||||
"fieldname": "discount_type",
|
"fieldname": "discount_type",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Discount Type",
|
"label": "Discount Type",
|
||||||
@@ -107,6 +109,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fetch_from": "payment_term.discount",
|
"fetch_from": "payment_term.discount",
|
||||||
|
"fetch_if_empty": 1,
|
||||||
"fieldname": "discount",
|
"fieldname": "discount",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Discount"
|
"label": "Discount"
|
||||||
@@ -119,6 +122,7 @@
|
|||||||
"default": "Day(s) after invoice date",
|
"default": "Day(s) after invoice date",
|
||||||
"depends_on": "discount",
|
"depends_on": "discount",
|
||||||
"fetch_from": "payment_term.discount_validity_based_on",
|
"fetch_from": "payment_term.discount_validity_based_on",
|
||||||
|
"fetch_if_empty": 1,
|
||||||
"fieldname": "discount_validity_based_on",
|
"fieldname": "discount_validity_based_on",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Discount Validity Based On",
|
"label": "Discount Validity Based On",
|
||||||
@@ -133,6 +137,7 @@
|
|||||||
{
|
{
|
||||||
"depends_on": "discount",
|
"depends_on": "discount",
|
||||||
"fetch_from": "payment_term.discount_validity",
|
"fetch_from": "payment_term.discount_validity",
|
||||||
|
"fetch_if_empty": 1,
|
||||||
"fieldname": "discount_validity",
|
"fieldname": "discount_validity",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
"label": "Discount Validity",
|
"label": "Discount Validity",
|
||||||
@@ -146,7 +151,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-02-24 11:32:39.134870",
|
"modified": "2021-02-24 11:56:12.410807",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Terms Template Detail",
|
"name": "Payment Terms Template Detail",
|
||||||
|
|||||||
Reference in New Issue
Block a user