refactor(test): make dunning deterministic

This commit is contained in:
ruthra kumar
2026-01-29 11:48:51 +05:30
parent 3a5869e525
commit c55628a55d
2 changed files with 48 additions and 15 deletions

View File

@@ -8,9 +8,6 @@ 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.purchase_invoice.test_purchase_invoice import (
unlink_payment_on_cancel_of_invoice,
)
from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
create_dunning as create_dunning_from_sales_invoice,
)
@@ -21,18 +18,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestDunning(ERPNextTestSuite):
@classmethod
def setUpClass(cls):
super().setUpClass()
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)
unlink_payment_on_cancel_of_invoice()
@classmethod
def tearDownClass(cls):
unlink_payment_on_cancel_of_invoice(0)
super().tearDownClass()
def test_dunning_without_fees(self):
dunning = create_dunning(overdue_days=20)

View File

@@ -252,6 +252,7 @@ class ERPNextTestSuite(unittest.TestCase):
cls.make_brand()
cls.make_monthly_distribution()
cls.make_projects()
cls.make_dunning_type()
cls.update_selling_settings()
cls.update_stock_settings()
cls.update_system_settings()
@@ -3042,6 +3043,53 @@ class ERPNextTestSuite(unittest.TestCase):
else:
cls.brand.append(frappe.get_doc("Brand", {"Brand": x.get("brand")}))
@classmethod
def make_dunning_type(cls):
records = [
{
"doctype": "Dunning Type",
"dunning_type": "First Notice",
"company": cls.companies[0].name,
"is_default": 1,
"dunning_fee": 0,
"rate_of_interest": 0,
"income_account": "Sales - _TC",
"cost_center": "Main - _TC",
"dunning_letter_text": [
{
"language": "en",
"body_text": "We have still not received payment for our invoice",
"closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees.",
},
],
},
{
"doctype": "Dunning Type",
"dunning_type": "Second Notice",
"company": cls.companies[0].name,
"is_default": 0,
"dunning_fee": 10,
"rate_of_interest": 10,
"income_account": "Sales - _TC",
"cost_center": "Main - _TC",
"dunning_letter_text": [
{
"language": "en",
"body_text": "We have still not received payment for our invoice",
"closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees.",
},
],
},
]
cls.dunning_type = []
for x in records:
if not frappe.db.exists("Dunning Type", {"dunning_type": x.get("dunning_type")}):
cls.dunning_type.append(frappe.get_doc(x).insert())
else:
cls.dunning_type.append(
frappe.get_doc("Dunning Type", {"dunning_type": x.get("dunning_type")})
)
@contextmanager
def set_user(self, user: str):
try: