mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 05:59:18 +00:00
test: fix dunning test
This commit is contained in:
@@ -6,6 +6,7 @@ import unittest
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import add_days, nowdate, today
|
from frappe.utils import add_days, nowdate, today
|
||||||
|
|
||||||
|
from erpnext import get_default_cost_center
|
||||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
||||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import (
|
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import (
|
||||||
unlink_payment_on_cancel_of_invoice,
|
unlink_payment_on_cancel_of_invoice,
|
||||||
@@ -17,16 +18,19 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import (
|
|||||||
create_sales_invoice_against_cost_center,
|
create_sales_invoice_against_cost_center,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
test_dependencies = ["Company", "Cost Center"]
|
||||||
|
|
||||||
|
|
||||||
class TestDunning(unittest.TestCase):
|
class TestDunning(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(self):
|
def setUpClass(cls):
|
||||||
create_dunning_type("First Notice", fee=0.0, interest=0.0, is_default=1)
|
create_dunning_type("First Notice", fee=0.0, interest=0.0, is_default=1)
|
||||||
create_dunning_type("Second Notice", fee=10.0, interest=10.0, is_default=0)
|
create_dunning_type("Second Notice", fee=10.0, interest=10.0, is_default=0)
|
||||||
unlink_payment_on_cancel_of_invoice()
|
unlink_payment_on_cancel_of_invoice()
|
||||||
|
frappe.db.commit()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(self):
|
def tearDownClass(cls):
|
||||||
unlink_payment_on_cancel_of_invoice(0)
|
unlink_payment_on_cancel_of_invoice(0)
|
||||||
|
|
||||||
def test_first_dunning(self):
|
def test_first_dunning(self):
|
||||||
@@ -39,7 +43,7 @@ class TestDunning(unittest.TestCase):
|
|||||||
self.assertEqual(round(dunning.grand_total, 2), 100.00)
|
self.assertEqual(round(dunning.grand_total, 2), 100.00)
|
||||||
|
|
||||||
def test_second_dunning(self):
|
def test_second_dunning(self):
|
||||||
dunning = create_dunning(overdue_days=15, dunning_type_name="Second Notice")
|
dunning = create_dunning(overdue_days=15, dunning_type_name="Second Notice - _TC")
|
||||||
|
|
||||||
self.assertEqual(round(dunning.total_outstanding, 2), 100.00)
|
self.assertEqual(round(dunning.total_outstanding, 2), 100.00)
|
||||||
self.assertEqual(round(dunning.total_interest, 2), 0.41)
|
self.assertEqual(round(dunning.total_interest, 2), 0.41)
|
||||||
@@ -48,7 +52,7 @@ class TestDunning(unittest.TestCase):
|
|||||||
self.assertEqual(round(dunning.grand_total, 2), 110.41)
|
self.assertEqual(round(dunning.grand_total, 2), 110.41)
|
||||||
|
|
||||||
def test_payment_entry(self):
|
def test_payment_entry(self):
|
||||||
dunning = create_dunning(overdue_days=15, dunning_type_name="Second Notice")
|
dunning = create_dunning(overdue_days=15, dunning_type_name="Second Notice - _TC")
|
||||||
dunning.submit()
|
dunning.submit()
|
||||||
pe = get_payment_entry("Dunning", dunning.name)
|
pe = get_payment_entry("Dunning", dunning.name)
|
||||||
pe.reference_no = "1"
|
pe.reference_no = "1"
|
||||||
@@ -78,24 +82,25 @@ def create_dunning(overdue_days, dunning_type_name=None):
|
|||||||
dunning.dunning_type = dunning_type.name
|
dunning.dunning_type = dunning_type.name
|
||||||
dunning.rate_of_interest = dunning_type.rate_of_interest
|
dunning.rate_of_interest = dunning_type.rate_of_interest
|
||||||
dunning.dunning_fee = dunning_type.dunning_fee
|
dunning.dunning_fee = dunning_type.dunning_fee
|
||||||
|
dunning.income_account = dunning_type.income_account
|
||||||
|
dunning.cost_center = dunning_type.cost_center
|
||||||
|
|
||||||
dunning.income_account = get_income_account(dunning.company)
|
return dunning.save()
|
||||||
dunning.save()
|
|
||||||
|
|
||||||
return dunning
|
|
||||||
|
|
||||||
|
|
||||||
def create_dunning_type(title, fee, interest, is_default):
|
def create_dunning_type(title, fee, interest, is_default):
|
||||||
existing = frappe.db.exists("Dunning Type", title)
|
company = "_Test Company"
|
||||||
if existing:
|
if frappe.db.exists("Dunning Type", f"{title} - _TC"):
|
||||||
return frappe.get_doc("Dunning Type", existing)
|
return
|
||||||
|
|
||||||
dunning_type = frappe.new_doc("Dunning Type")
|
dunning_type = frappe.new_doc("Dunning Type")
|
||||||
dunning_type.dunning_type = title
|
dunning_type.dunning_type = title
|
||||||
dunning_type.company = "_Test Company"
|
dunning_type.company = company
|
||||||
dunning_type.is_default = is_default
|
dunning_type.is_default = is_default
|
||||||
dunning_type.dunning_fee = fee
|
dunning_type.dunning_fee = fee
|
||||||
dunning_type.rate_of_interest = interest
|
dunning_type.rate_of_interest = interest
|
||||||
|
dunning_type.income_account = get_income_account(company)
|
||||||
|
dunning_type.cost_center = get_default_cost_center(company)
|
||||||
dunning_type.append(
|
dunning_type.append(
|
||||||
"dunning_letter_text",
|
"dunning_letter_text",
|
||||||
{
|
{
|
||||||
@@ -104,8 +109,7 @@ def create_dunning_type(title, fee, interest, is_default):
|
|||||||
"closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees.",
|
"closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees.",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
dunning_type.save()
|
dunning_type.insert()
|
||||||
return dunning_type
|
|
||||||
|
|
||||||
|
|
||||||
def get_income_account(company):
|
def get_income_account(company):
|
||||||
|
|||||||
Reference in New Issue
Block a user