From 74f8d65021aef62550345549d9de4e919041e8f6 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 8 May 2025 12:07:23 +0530 Subject: [PATCH 1/2] refactor(test): deterministic test suite for sales invoice --- .../accounting_dimension/test_accounting_dimension.py | 1 - .../doctype/sales_invoice/test_sales_invoice.py | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py index ccc9f1353b6..c3d1e295c8b 100644 --- a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py @@ -121,7 +121,6 @@ def create_dimension(): "company": "_Test Company", "reference_document": "Location", "default_dimension": "Block 1", - "mandatory_for_bs": 1, }, ) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 367f3f82ccd..692ba62218b 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2230,13 +2230,13 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(expected_account_values[1], gle.credit) def test_rounding_adjustment_3(self): - from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( - create_dimension, - disable_dimension, - ) + from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import create_dimension + # Dimension creates custom field, which does an implicit DB commit as it is a DDL command + # Ensure dimension don't have any mandatory fields create_dimension() + # rollback from tearDown() happens till here si = create_sales_invoice(do_not_save=True) si.items = [] for d in [(1122, 2), (1122.01, 1), (1122.01, 1)]: @@ -2317,8 +2317,6 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(round_off_gle.cost_center, "_Test Cost Center 2 - _TC") self.assertEqual(round_off_gle.location, "Block 1") - disable_dimension() - def test_sales_invoice_with_shipping_rule(self): from erpnext.accounts.doctype.shipping_rule.test_shipping_rule import create_shipping_rule From fb921836794fa1f1c4ac4993d5f286006b47b3a8 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 8 May 2025 13:17:21 +0530 Subject: [PATCH 2/2] refactor(test): set mandatory dimension at invidual test cases --- .../doctype/accounting_dimension/test_accounting_dimension.py | 4 ++++ .../doctype/pos_closing_entry/test_pos_closing_entry.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py index c3d1e295c8b..769522e2642 100644 --- a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py @@ -58,6 +58,10 @@ class TestAccountingDimension(IntegrationTestCase): self.assertEqual(gle1.get("department"), "_Test Department - _TC") def test_mandatory(self): + location = frappe.get_doc("Accounting Dimension", "Location") + location.dimension_defaults[0].mandatory_for_bs = True + location.save() + si = create_sales_invoice(do_not_save=1) si.append( "items", diff --git a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py index d2bd406f03b..fd620053728 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py +++ b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py @@ -159,6 +159,10 @@ class TestPOSClosingEntry(IntegrationTestCase): """ create_dimension() + location = frappe.get_doc("Accounting Dimension", "Location") + location.dimension_defaults[0].mandatory_for_bs = True + location.save() + pos_profile = make_pos_profile(do_not_insert=1, do_not_set_accounting_dimension=1) self.assertRaises(frappe.ValidationError, pos_profile.insert)