From 7fcd74ed03d93d78bfd984ce351e2395ab7ff0d5 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 6 Mar 2023 20:14:50 +0530 Subject: [PATCH] fix(test): flaky test case in Payment terms report --- ...st_payment_terms_status_for_sales_order.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py b/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py index 525ae8e7ea..58516f6f62 100644 --- a/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py +++ b/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py @@ -2,7 +2,7 @@ import datetime import frappe from frappe.tests.utils import FrappeTestCase -from frappe.utils import add_days, nowdate +from frappe.utils import add_days, add_months, nowdate from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order @@ -15,9 +15,16 @@ test_dependencies = ["Sales Order", "Item", "Sales Invoice", "Payment Terms Temp class TestPaymentTermsStatusForSalesOrder(FrappeTestCase): + def setUp(self): + self.cleanup_old_entries() + def tearDown(self): frappe.db.rollback() + def cleanup_old_entries(self): + frappe.db.delete("Sales Invoice", filters={"company": "_Test Company"}) + frappe.db.delete("Sales Order", filters={"company": "_Test Company"}) + def create_payment_terms_template(self): # create template for 50-50 payments template = None @@ -348,7 +355,7 @@ class TestPaymentTermsStatusForSalesOrder(FrappeTestCase): item = create_item(item_code="_Test Excavator 1", is_stock_item=0) transaction_date = nowdate() so = make_sales_order( - transaction_date=add_days(transaction_date, -30), + transaction_date=add_months(transaction_date, -1), delivery_date=add_days(transaction_date, -15), item=item.item_code, qty=10, @@ -369,13 +376,15 @@ class TestPaymentTermsStatusForSalesOrder(FrappeTestCase): sinv.items[0].qty = 6 sinv.insert() sinv.submit() + + first_due_date = add_days(add_months(transaction_date, -1), 15) columns, data, message, chart = execute( frappe._dict( { "company": "_Test Company", "item": item.item_code, - "from_due_date": add_days(transaction_date, -30), - "to_due_date": add_days(transaction_date, -15), + "from_due_date": add_months(transaction_date, -1), + "to_due_date": first_due_date, } ) ) @@ -384,11 +393,11 @@ class TestPaymentTermsStatusForSalesOrder(FrappeTestCase): { "name": so.name, "customer": so.customer, - "submitted": datetime.date.fromisoformat(add_days(transaction_date, -30)), + "submitted": datetime.date.fromisoformat(add_months(transaction_date, -1)), "status": "Completed", "payment_term": None, "description": "_Test 50-50", - "due_date": datetime.date.fromisoformat(add_days(transaction_date, -15)), + "due_date": datetime.date.fromisoformat(first_due_date), "invoice_portion": 50.0, "currency": "INR", "base_payment_amount": 500000.0,