Merge pull request #34370 from ruthra-kumar/fix_flaky_test_in_payment_terms_report

fix(test): flaky test case in Payment terms report
This commit is contained in:
ruthra kumar 2023-03-11 14:17:45 +05:30 committed by GitHub
commit a9989b12d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@ import datetime
import frappe import frappe
from frappe.tests.utils import FrappeTestCase 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.sales_order import make_sales_invoice
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order 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): class TestPaymentTermsStatusForSalesOrder(FrappeTestCase):
def setUp(self):
self.cleanup_old_entries()
def tearDown(self): def tearDown(self):
frappe.db.rollback() 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): def create_payment_terms_template(self):
# create template for 50-50 payments # create template for 50-50 payments
template = None template = None
@ -348,7 +355,7 @@ class TestPaymentTermsStatusForSalesOrder(FrappeTestCase):
item = create_item(item_code="_Test Excavator 1", is_stock_item=0) item = create_item(item_code="_Test Excavator 1", is_stock_item=0)
transaction_date = nowdate() transaction_date = nowdate()
so = make_sales_order( 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), delivery_date=add_days(transaction_date, -15),
item=item.item_code, item=item.item_code,
qty=10, qty=10,
@ -369,13 +376,15 @@ class TestPaymentTermsStatusForSalesOrder(FrappeTestCase):
sinv.items[0].qty = 6 sinv.items[0].qty = 6
sinv.insert() sinv.insert()
sinv.submit() sinv.submit()
first_due_date = add_days(add_months(transaction_date, -1), 15)
columns, data, message, chart = execute( columns, data, message, chart = execute(
frappe._dict( frappe._dict(
{ {
"company": "_Test Company", "company": "_Test Company",
"item": item.item_code, "item": item.item_code,
"from_due_date": add_days(transaction_date, -30), "from_due_date": add_months(transaction_date, -1),
"to_due_date": add_days(transaction_date, -15), "to_due_date": first_due_date,
} }
) )
) )
@ -384,11 +393,11 @@ class TestPaymentTermsStatusForSalesOrder(FrappeTestCase):
{ {
"name": so.name, "name": so.name,
"customer": so.customer, "customer": so.customer,
"submitted": datetime.date.fromisoformat(add_days(transaction_date, -30)), "submitted": datetime.date.fromisoformat(add_months(transaction_date, -1)),
"status": "Completed", "status": "Completed",
"payment_term": None, "payment_term": None,
"description": "_Test 50-50", "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, "invoice_portion": 50.0,
"currency": "INR", "currency": "INR",
"base_payment_amount": 500000.0, "base_payment_amount": 500000.0,