Skip to content

Commit 8f99850

Browse files
mihir-kandoiNishka Gosalia
authored andcommitted
fix: test case
1 parent 258013c commit 8f99850

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
lines changed

erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,40 +112,31 @@ def setUpClass(cls):
112112
def tearDownClass(self):
113113
unlink_payment_on_cancel_of_invoice(0)
114114

115-
def test_payment_date_recalculate(self):
115+
def test_payment_date_recalculation(self):
116116
posting_date = getdate()
117117
new_posting_date = add_days(posting_date, 5)
118+
payment_term = frappe.new_doc("Payment Term")
119+
payment_term.payment_term_name = "Test Term 2 Days"
120+
payment_term.invoice_portion = 100
121+
payment_term.credit_days = 2
122+
payment_term.save()
118123

119-
payment_term = frappe.get_doc(
120-
{
121-
"doctype": "Payment Term",
122-
"payment_term_name": "Test Term 2 Days",
123-
"invoice_portion": 100,
124-
"credit_days": 2,
125-
}
126-
).insert()
127-
128-
ptt = frappe.get_doc(
129-
{
130-
"doctype": "Payment Terms Template",
131-
"template_name": "Test Template Recalc",
132-
"terms": [{"payment_term": payment_term.name, "invoice_portion": 100, "credit_days": 2}],
133-
}
134-
).insert()
124+
payment_term_template = frappe.new_doc("Payment Terms Template")
125+
payment_term_template.template_name = "Test Template Recalc"
126+
payment_term_template.append(
127+
"terms", {"payment_term": payment_term.name, "invoice_portion": 100, "credit_days": 2}
128+
)
129+
payment_term_template.save()
135130

136131
si = create_sales_invoice(do_not_save=1)
132+
si.set_posting_time = 1
137133
si.posting_date = posting_date
138-
si.payment_terms_template = ptt.name
139-
si.set_missing_values()
140-
si.set_payment_schedule()
141-
si.set_due_date()
142-
si.insert()
143-
134+
si.payment_terms_template = payment_term_template.name
135+
si.save()
144136
self.assertEqual(si.payment_schedule[0].due_date, add_days(posting_date, 2))
145137

146-
si = frappe.get_doc("Sales Invoice", si.name)
147-
148-
recalculate_payment_due_date(new_posting_date, si.payment_schedule)
138+
si.update({"posting_date": new_posting_date})
139+
si.save()
149140

150141
self.assertEqual(si.payment_schedule[0].due_date, add_days(new_posting_date, 2))
151142

erpnext/controllers/accounts_controller.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,13 +2569,18 @@ def set_payment_schedule(self):
25692569
self.append("payment_schedule", data)
25702570
elif (not self.is_new()) and posting_date:
25712571
doc_before_save = self.get_doc_before_save()
2572-
old_posting_date = (
2573-
doc_before_save.get("bill_date")
2574-
or doc_before_save.get("transaction_date")
2575-
or doc_before_save.get("posting_date")
2576-
)
2577-
if getdate(old_posting_date) != getdate(posting_date):
2578-
recalculate_payment_due_date(posting_date, self.payment_schedule)
2572+
2573+
if doc_before_save:
2574+
old_posting_date = (
2575+
doc_before_save.get("bill_date")
2576+
or doc_before_save.get("transaction_date")
2577+
or doc_before_save.get("posting_date")
2578+
)
2579+
2580+
if getdate(old_posting_date) != getdate(posting_date) and any(
2581+
[term.payment_term for term in self.payment_schedule]
2582+
):
2583+
recalculate_payment_due_date(posting_date, self.payment_schedule)
25792584

25802585
allocate_payment_based_on_payment_terms = frappe.db.get_value(
25812586
"Payment Terms Template", self.payment_terms_template, "allocate_payment_based_on_payment_terms"
@@ -3614,6 +3619,7 @@ def get_payment_term_details(
36143619
def get_due_date(term, posting_date=None, bill_date=None):
36153620
due_date = None
36163621
date = bill_date or posting_date
3622+
print(term)
36173623
if term.due_date_based_on == "Day(s) after invoice date":
36183624
due_date = add_days(date, cint(term.credit_days))
36193625
elif term.due_date_based_on == "Day(s) after the end of the invoice month":

0 commit comments

Comments
 (0)