refactor(test): make sales order deterministic

This commit is contained in:
ruthra kumar
2025-12-01 18:01:15 +05:30
parent a4f8920d97
commit 6e3ea35dda
2 changed files with 43 additions and 6 deletions

View File

@@ -56,7 +56,6 @@ class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite):
def tearDown(self):
frappe.db.rollback()
frappe.set_user("Administrator")
@IntegrationTestCase.change_settings(
"Stock Settings",
@@ -145,7 +144,7 @@ class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite):
so.reload()
self.assertEqual(so.status, "Completed")
@IntegrationTestCase.change_settings("Selling Settings", {"allow_negative_rates_for_items": 1})
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1, "allow_negative_rates_for_items": 1})
def test_sales_order_with_negative_rate(self):
"""
Test if negative rate is allowed in Sales Order via doc submission and update items
@@ -175,6 +174,7 @@ class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite):
)
update_child_qty_rate("Sales Order", trans_item, so.name)
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1})
def test_sales_order_qty(self):
so = make_sales_order(qty=1, do_not_save=True)
@@ -823,6 +823,7 @@ class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite):
# reserved qty in packed item should increase after changing bundle item uom
self.assertEqual(get_reserved_qty("_Packed Item"), existing_reserved_qty + 8)
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1})
def test_update_child_with_tax_template(self):
"""
Test Action: Create a SO with one item having its tax account head already in the SO.
@@ -1485,6 +1486,7 @@ class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite):
si.insert()
self.assertTrue(si.get("payment_schedule"))
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1})
def test_make_work_order(self):
from erpnext.selling.doctype.sales_order.sales_order import get_work_order_items
@@ -1826,7 +1828,7 @@ class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite):
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
so = make_sales_order(uom="Nos", do_not_save=1)
so.items[0].rate = 0
so.items[0].rate = so.items[0].price_list_rate = 0
so.save()
so.submit()
@@ -2384,7 +2386,7 @@ class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite):
frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 1)
so = make_sales_order(
item_code=item.name, currency="USD", qty=1, rate=100, price_list_rate=100, do_not_submit=True
item_code=item.name, currency="INR", qty=1, rate=100, price_list_rate=100, do_not_submit=True
)
so.save()
@@ -2392,7 +2394,7 @@ class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite):
self.assertEqual(item_price, 100)
so = make_sales_order(
item_code=item.name, currency="USD", qty=1, rate=200, price_list_rate=100, do_not_submit=True
item_code=item.name, currency="INR", qty=1, rate=200, price_list_rate=100, do_not_submit=True
)
so.save()
@@ -2401,7 +2403,7 @@ class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite):
frappe.db.set_single_value("Stock Settings", "update_existing_price_list_rate", 1)
so = make_sales_order(
item_code=item.name, currency="USD", qty=1, rate=200, price_list_rate=200, do_not_submit=True
item_code=item.name, currency="INR", qty=1, rate=200, price_list_rate=200, do_not_submit=True
)
so.save()

View File

@@ -233,6 +233,7 @@ class ERPNextTestSuite(unittest.TestCase):
cls.make_asset_maintenance_team()
cls.make_asset_category()
cls._make_item()
cls.make_product_bundle()
cls.make_location()
cls.make_price_list()
cls.make_item_price()
@@ -2170,6 +2171,40 @@ class ERPNextTestSuite(unittest.TestCase):
)
)
@classmethod
def make_product_bundle(cls):
records = [
{
"doctype": "Product Bundle",
"new_item_code": "_Test Product Bundle Item",
"items": [
{
"doctype": "Product Bundle Item",
"item_code": "_Test Item",
"parentfield": "items",
"qty": 5.0,
},
{
"doctype": "Product Bundle Item",
"item_code": "_Test Item Home Desktop 100",
"parentfield": "items",
"qty": 2.0,
},
],
}
]
cls.product_bundle = []
for x in records:
if not frappe.db.exists("Product Bundle", {"new_item_code": x.get("new_item_code")}):
cls.product_bundle.append(frappe.get_doc(x).insert())
else:
cls.product_bundle.append(
frappe.get_doc(
"Product Bundle",
{"new_item_code": x.get("new_item_code")},
)
)
@classmethod
def make_test_account(cls):
records = [