From 9669a2c56fc5498ce18e241998f8958fefc14c61 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 20 Mar 2026 11:46:43 +0530 Subject: [PATCH 01/14] refactor(test): move commits inside test guard clause (cherry picked from commit ed76d6699afbc35cfdb0cc5a9b6bf100f7525e02) --- erpnext/accounts/doctype/gl_entry/gl_entry.py | 3 ++- erpnext/accounts/doctype/ledger_merge/ledger_merge.py | 3 ++- .../opening_invoice_creation_tool.py | 3 ++- .../accounts/doctype/payment_request/payment_request.py | 3 ++- erpnext/accounts/doctype/subscription/subscription.py | 3 ++- erpnext/assets/doctype/asset/depreciation.py | 7 +++++-- erpnext/buying/doctype/purchase_order/purchase_order.py | 3 ++- erpnext/crm/doctype/appointment/appointment.py | 3 ++- erpnext/setup/doctype/company/company.py | 6 ++++-- erpnext/stock/stock_balance.py | 3 ++- erpnext/telephony/doctype/call_log/call_log.py | 4 +++- 11 files changed, 28 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index 3abfa176622..452164c728c 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -489,4 +489,5 @@ def rename_temporarily_named_docs(doctype): for hook in frappe.get_hooks(hook_type): frappe.call(hook, newname=newname, oldname=oldname) - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() diff --git a/erpnext/accounts/doctype/ledger_merge/ledger_merge.py b/erpnext/accounts/doctype/ledger_merge/ledger_merge.py index 008b4115f5f..3dd3883608c 100644 --- a/erpnext/accounts/doctype/ledger_merge/ledger_merge.py +++ b/erpnext/accounts/doctype/ledger_merge/ledger_merge.py @@ -71,7 +71,8 @@ def start_merge(docname): ledger_merge.account, ) row.db_set("merged", 1) - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() successful_merges += 1 frappe.publish_realtime( "ledger_merge_progress", diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py index 6a3df141f52..e1e70e0f6cb 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py @@ -274,7 +274,8 @@ def start_import(invoices): doc.flags.ignore_mandatory = True doc.insert(set_name=invoice_number) doc.submit() - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() names.append(doc.name) except Exception: errors += 1 diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index c95945bf6e2..e16e132957f 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -750,7 +750,8 @@ def make_payment_request(**args): pr.submit() if args.order_type == "Shopping Cart": - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() frappe.local.response["type"] = "redirect" frappe.local.response["location"] = pr.get_payment_url() diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index 0b3da559e39..642f918c3b1 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -772,7 +772,8 @@ def process_all(subscription: list, posting_date: DateTimeLikeObject | None = No try: subscription = frappe.get_doc("Subscription", subscription_name) subscription.process(posting_date) - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() except frappe.ValidationError: frappe.db.rollback() subscription.log_error("Subscription failed") diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index 832e3736e7d..1a9788be48e 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -61,7 +61,9 @@ def book_depreciation_entries(date): accounting_dimensions, ) - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() + except Exception as e: frappe.db.rollback() failed_assets.append(asset_name) @@ -71,7 +73,8 @@ def book_depreciation_entries(date): if failed_assets: set_depr_entry_posting_status_for_failed_assets(failed_assets) notify_depr_entry_posting_error(failed_assets, error_logs) - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() def get_depreciable_assets_data(date): diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index a0daeca51f2..bd22a21bd99 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -780,7 +780,8 @@ def make_purchase_invoice_from_portal(purchase_order_name): if frappe.session.user not in frappe.get_all("Portal User", {"parent": doc.supplier}, pluck="user"): frappe.throw(_("Not Permitted"), frappe.PermissionError) doc.save() - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() frappe.response["type"] = "redirect" frappe.response.location = "/purchase-invoices/" + doc.name diff --git a/erpnext/crm/doctype/appointment/appointment.py b/erpnext/crm/doctype/appointment/appointment.py index b41064ce9e3..9a213aea5fc 100644 --- a/erpnext/crm/doctype/appointment/appointment.py +++ b/erpnext/crm/doctype/appointment/appointment.py @@ -120,7 +120,8 @@ class Appointment(Document): self.auto_assign() self.create_calendar_event() self.save(ignore_permissions=True) - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() def create_lead_and_link(self): # Return if already linked diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 5da3ca40904..8111935a339 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -927,7 +927,7 @@ def update_transactions_annual_history(company, commit=False): transactions_history = get_all_transactions_annual_history(company) frappe.db.set_value("Company", company, "transactions_annual_history", json.dumps(transactions_history)) - if commit: + if commit and not frappe.in_test: frappe.db.commit() @@ -936,7 +936,9 @@ def cache_companies_monthly_sales_history(): for company in companies: update_company_monthly_sales(company) update_transactions_annual_history(company) - frappe.db.commit() + + if not frappe.in_test: + frappe.db.commit() @frappe.whitelist() diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index b2401da4f8f..7f6deda9b8c 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -31,7 +31,8 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False, for d in item_warehouses: try: repost_stock(d[0], d[1], allow_zero_rate, only_actual, only_bin, allow_negative_stock) - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() except Exception: frappe.db.rollback() diff --git a/erpnext/telephony/doctype/call_log/call_log.py b/erpnext/telephony/doctype/call_log/call_log.py index 0b5fd5dc368..b2ae785e110 100644 --- a/erpnext/telephony/doctype/call_log/call_log.py +++ b/erpnext/telephony/doctype/call_log/call_log.py @@ -190,7 +190,9 @@ def link_existing_conversations(doc, state): call_log = frappe.get_doc("Call Log", log) call_log.add_link(link_type=doc.doctype, link_name=doc.name) call_log.save(ignore_permissions=True) - frappe.db.commit() + + if not frappe.in_test: + frappe.db.commit() except Exception: frappe.log_error(title=_("Error during caller information update")) From 941375877e57b1e1cdb95dc52180ab6bb7f7bfd1 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 20 Mar 2026 11:50:01 +0530 Subject: [PATCH 02/14] refactor(test): move dimension setup to test data bootstrap and remove create_dimension() and disable_dimension() (cherry picked from commit 342ce654019ad845282f4e6a1be5ea861c6e1492) --- .../test_accounting_dimension.py | 63 ------------------- .../test_accounting_dimension_filter.py | 5 -- .../test_opening_invoice_creation_tool.py | 6 +- .../test_pos_closing_entry.py | 6 -- .../sales_invoice/test_sales_invoice.py | 7 --- .../tests/test_accounts_controller.py | 18 ------ erpnext/tests/utils.py | 31 +++++++++ 7 files changed, 32 insertions(+), 104 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py index 81e639dc6b2..250442a3cd4 100644 --- a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py @@ -10,9 +10,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestAccountingDimension(ERPNextTestSuite): - def setUp(self): - create_dimension() - def test_dimension_against_sales_invoice(self): si = create_sales_invoice(do_not_save=1) @@ -77,63 +74,3 @@ class TestAccountingDimension(ERPNextTestSuite): si.save() self.assertRaises(frappe.ValidationError, si.submit) - - -def create_dimension(): - frappe.set_user("Administrator") - - if not frappe.db.exists("Accounting Dimension", {"document_type": "Department"}): - dimension = frappe.get_doc( - { - "doctype": "Accounting Dimension", - "document_type": "Department", - } - ) - dimension.append( - "dimension_defaults", - { - "company": "_Test Company", - "reference_document": "Department", - "default_dimension": "_Test Department - _TC", - }, - ) - dimension.insert() - dimension.save() - else: - dimension = frappe.get_doc("Accounting Dimension", "Department") - dimension.disabled = 0 - dimension.save() - - if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}): - dimension1 = frappe.get_doc( - { - "doctype": "Accounting Dimension", - "document_type": "Location", - } - ) - - dimension1.append( - "dimension_defaults", - { - "company": "_Test Company", - "reference_document": "Location", - "default_dimension": "Block 1", - }, - ) - - dimension1.insert() - dimension1.save() - else: - dimension1 = frappe.get_doc("Accounting Dimension", "Location") - dimension1.disabled = 0 - dimension1.save() - - -def disable_dimension(): - dimension1 = frappe.get_doc("Accounting Dimension", "Department") - dimension1.disabled = 1 - dimension1.save() - - dimension2 = frappe.get_doc("Accounting Dimension", "Location") - dimension2.disabled = 1 - dimension2.save() diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py index 9bed10824bb..fe7d4706967 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py +++ b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py @@ -5,10 +5,6 @@ import unittest import frappe -from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( - create_dimension, - disable_dimension, -) from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError from erpnext.tests.utils import ERPNextTestSuite @@ -16,7 +12,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestAccountingDimensionFilter(ERPNextTestSuite): def setUp(self): - create_dimension() create_accounting_dimension_filter() self.invoice_list = [] diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py index 3d57c781983..1a61adad4cd 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py @@ -3,10 +3,6 @@ import frappe -from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( - create_dimension, - disable_dimension, -) from erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool import ( get_temporary_opening_account, ) @@ -15,9 +11,9 @@ from erpnext.tests.utils import ERPNextTestSuite class TestOpeningInvoiceCreationTool(ERPNextTestSuite): def setUp(self): + # TODO: move to bootstrap if not frappe.db.exists("Company", "_Test Opening Invoice Company"): make_company() - create_dimension() def make_invoices( self, 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 af5f73a39ec..05e24d16a3a 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 @@ -4,10 +4,6 @@ import unittest import frappe -from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( - create_dimension, - disable_dimension, -) from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import ( make_closing_entry_from_opening, ) @@ -162,7 +158,6 @@ class TestPOSClosingEntry(ERPNextTestSuite): test case to check whether we can create POS Closing Entry without mandatory accounting dimension """ - create_dimension() location = frappe.get_doc("Accounting Dimension", "Location") location.dimension_defaults[0].mandatory_for_bs = True location.save() @@ -198,7 +193,6 @@ class TestPOSClosingEntry(ERPNextTestSuite): ) accounting_dimension_department.mandatory_for_bs = 0 accounting_dimension_department.save() - disable_dimension() def test_merging_into_sales_invoice_for_batched_item(self): frappe.flags.print_message = False diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 3616f196bb7..002cdc4a43c 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2246,13 +2246,6 @@ class TestSalesInvoice(ERPNextTestSuite): @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_rounding_adjustment_3(self): - 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)]: diff --git a/erpnext/controllers/tests/test_accounts_controller.py b/erpnext/controllers/tests/test_accounts_controller.py index 6bb9b2f91fc..021e034a70d 100644 --- a/erpnext/controllers/tests/test_accounts_controller.py +++ b/erpnext/controllers/tests/test_accounts_controller.py @@ -1567,25 +1567,10 @@ class TestAccountsController(ERPNextTestSuite): frappe.db.set_value("Company", self.company, "cost_center", cc) - def setup_dimensions(self): - # create dimension - from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( - create_dimension, - ) - - create_dimension() - # make it non-mandatory - loc = frappe.get_doc("Accounting Dimension", "Location") - for x in loc.dimension_defaults: - x.mandatory_for_bs = False - x.mandatory_for_pl = False - loc.save() - def test_90_dimensions_filter(self): """ Test workings of dimension filters """ - self.setup_dimensions() rate_in_account_currency = 1 # Invoices @@ -1653,7 +1638,6 @@ class TestAccountsController(ERPNextTestSuite): self.assertEqual(len(pr.payments), 1) def test_91_cr_note_should_inherit_dimension(self): - self.setup_dimensions() rate_in_account_currency = 1 # Invoice @@ -1698,7 +1682,6 @@ class TestAccountsController(ERPNextTestSuite): def test_92_dimension_inhertiance_exc_gain_loss(self): # Sales Invoice in Foreign Currency - self.setup_dimensions() rate_in_account_currency = 1 dpt = "Research & Development - _TC" @@ -1734,7 +1717,6 @@ class TestAccountsController(ERPNextTestSuite): ) def test_93_dimension_inheritance_on_advance(self): - self.setup_dimensions() dpt = "Research & Development - _TC" adv = self.create_payment_entry(amount=1, source_exc_rate=85) diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index 9485eb9af42..f5f9d7428cf 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -246,6 +246,10 @@ class BootStrapTestData: frappe.db.commit() # nosemgrep + # Dimensions + # DDL commands have implicit commit + self.make_dimensions() + # custom doctype # DDL commands have implicit commit self.make_custom_doctype() @@ -2794,6 +2798,33 @@ class BootStrapTestData: ] self.make_records(["address_title", "address_type"], records) + def make_dimensions(self): + records = [ + { + "doctype": "Accounting Dimension", + "document_type": "Department", + "dimension_defaults": [ + { + "company": "_Test Company", + "reference_document": "Department", + "default_dimension": "_Test Department - _TC", + } + ], + }, + { + "doctype": "Accounting Dimension", + "document_type": "Location", + "dimension_defaults": [ + { + "company": "_Test Company", + "reference_document": "Location", + "default_dimension": "Block 1", + } + ], + }, + ] + self.make_records(["document_type"], records) + BootStrapTestData() From ee72ed94d566133bdf636f37f9202ae93a7f3702 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 20 Mar 2026 12:02:02 +0530 Subject: [PATCH 03/14] refactor(test): move company setup to bootstrap (cherry picked from commit 9ed072ac834e6986adae28100367ab9e0dbdc55b) --- .../test_opening_invoice_creation_tool.py | 18 ------------------ .../setup/doctype/company/test_records.json | 8 ++++++++ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py index 1a61adad4cd..c01ada6d317 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py @@ -10,11 +10,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestOpeningInvoiceCreationTool(ERPNextTestSuite): - def setUp(self): - # TODO: move to bootstrap - if not frappe.db.exists("Company", "_Test Opening Invoice Company"): - make_company() - def make_invoices( self, invoice_type="Sales", @@ -179,19 +174,6 @@ def get_opening_invoice_creation_dict(**args): return invoice_dict -def make_company(): - if frappe.db.exists("Company", "_Test Opening Invoice Company"): - return frappe.get_doc("Company", "_Test Opening Invoice Company") - - company = frappe.new_doc("Company") - company.company_name = "_Test Opening Invoice Company" - company.abbr = "_TOIC" - company.default_currency = "INR" - company.country = "Pakistan" - company.insert() - return company - - def make_customer(customer=None): customer_name = customer or "Opening Customer" customer = frappe.get_doc( diff --git a/erpnext/setup/doctype/company/test_records.json b/erpnext/setup/doctype/company/test_records.json index 1b51d98413e..f26caa50fde 100644 --- a/erpnext/setup/doctype/company/test_records.json +++ b/erpnext/setup/doctype/company/test_records.json @@ -180,5 +180,13 @@ "default_currency": "ZAR", "doctype": "Company", "create_chart_of_accounts_based_on": "Standard Template" + }, + { + "abbr": "_TOIC", + "company_name": "_Test Opening Invoice Company", + "country": "Pakistan", + "default_currency": "INR", + "doctype": "Company", + "create_chart_of_accounts_based_on": "Standard Template" } ] From bb42d3ddbe24023d9e48d025c71e96e516dfc20a Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 20 Mar 2026 16:20:05 +0530 Subject: [PATCH 04/14] refactor(test): move purchase invoice dimension setup to bootstrap (cherry picked from commit 31ce09204f5a6bfdec64fa45a0c61bdba0bd137a) --- .../purchase_invoice/test_purchase_invoice.py | 18 ++++++++++-------- erpnext/tests/utils.py | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 33117c639dc..09febdfd915 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -2189,11 +2189,6 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin): def test_offsetting_entries_for_accounting_dimensions(self): from erpnext.accounts.doctype.account.test_account import create_account - from erpnext.accounts.report.trial_balance.test_trial_balance import ( - clear_dimension_defaults, - create_accounting_dimension, - disable_dimension, - ) create_account( account_name="Offsetting", @@ -2201,7 +2196,16 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin): parent_account="Temporary Accounts - _TC", ) - create_accounting_dimension(company="_Test Company", offsetting_account="Offsetting - _TC") + dim = frappe.get_doc("Accounting Dimension", "Branch") + dim.append( + "dimension_defaults", + { + "company": "_Test Company", + "reference_document": "Branch", + "offsetting_account": "Offsetting - _TC", + }, + ) + dim.save() branch1 = frappe.new_doc("Branch") branch1.branch = "Location 1" @@ -2238,8 +2242,6 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin): voucher_type="Purchase Invoice", additional_columns=["branch"], ) - clear_dimension_defaults("Branch") - disable_dimension() def test_repost_accounting_entries(self): # update repost settings diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index f5f9d7428cf..bfc0d5d89f6 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -2822,6 +2822,10 @@ class BootStrapTestData: } ], }, + { + "doctype": "Accounting Dimension", + "document_type": "Branch", + }, ] self.make_records(["document_type"], records) From ebe45add4c7207107f65b9c24731ff592fcb2800 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 20 Mar 2026 16:38:55 +0530 Subject: [PATCH 05/14] refactor(test): move trial company creation to bootstrap (cherry picked from commit 11fb00c21d5d6caeb636ab7a2bcd00b8681eb0de) --- .../trial_balance/test_trial_balance.py | 69 ++++--------------- .../setup/doctype/company/test_records.json | 8 +++ 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/erpnext/accounts/report/trial_balance/test_trial_balance.py b/erpnext/accounts/report/trial_balance/test_trial_balance.py index 42cf62af0a0..c37f9d5a46a 100644 --- a/erpnext/accounts/report/trial_balance/test_trial_balance.py +++ b/erpnext/accounts/report/trial_balance/test_trial_balance.py @@ -14,7 +14,6 @@ class TestTrialBalance(ERPNextTestSuite): from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center from erpnext.accounts.utils import get_fiscal_year - self.company = create_company() create_cost_center( cost_center_name="Test Cost Center", company="Trial Balance Company", @@ -26,7 +25,16 @@ class TestTrialBalance(ERPNextTestSuite): parent_account="Temporary Accounts - TBC", ) self.fiscal_year = get_fiscal_year(today(), company="Trial Balance Company")[0] - create_accounting_dimension() + dim = frappe.get_doc("Accounting Dimension", "Branch") + dim.append( + "dimension_defaults", + { + "company": "Trial Balance Company", + "automatically_post_balancing_accounting_entry": 1, + "offsetting_account": "Offsetting - TBC", + }, + ) + dim.save() def test_offsetting_entries_for_accounting_dimensions(self): """ @@ -45,7 +53,7 @@ class TestTrialBalance(ERPNextTestSuite): branch2.insert(ignore_if_duplicate=True) si = create_sales_invoice( - company=self.company, + company="Trial Balance Company", debit_to="Debtors - TBC", cost_center="Test Cost Center - TBC", income_account="Sales - TBC", @@ -57,60 +65,7 @@ class TestTrialBalance(ERPNextTestSuite): si.submit() filters = frappe._dict( - {"company": self.company, "fiscal_year": self.fiscal_year, "branch": ["Location 1"]} + {"company": "Trial Balance Company", "fiscal_year": self.fiscal_year, "branch": ["Location 1"]} ) total_row = execute(filters)[1][-1] self.assertEqual(total_row["debit"], total_row["credit"]) - - -def create_company(**args): - args = frappe._dict(args) - company = frappe.get_doc( - { - "doctype": "Company", - "company_name": args.company_name or "Trial Balance Company", - "country": args.country or "India", - "default_currency": args.currency or "INR", - "parent_company": args.get("parent_company"), - "is_group": args.get("is_group"), - } - ) - company.insert(ignore_if_duplicate=True) - return company.name - - -def create_accounting_dimension(**args): - args = frappe._dict(args) - document_type = args.document_type or "Branch" - if frappe.db.exists("Accounting Dimension", document_type): - accounting_dimension = frappe.get_doc("Accounting Dimension", document_type) - accounting_dimension.disabled = 0 - else: - accounting_dimension = frappe.new_doc("Accounting Dimension") - accounting_dimension.document_type = document_type - accounting_dimension.insert() - - accounting_dimension.set("dimension_defaults", []) - accounting_dimension.append( - "dimension_defaults", - { - "company": args.company or "Trial Balance Company", - "automatically_post_balancing_accounting_entry": 1, - "offsetting_account": args.offsetting_account or "Offsetting - TBC", - }, - ) - accounting_dimension.save() - - -def disable_dimension(**args): - args = frappe._dict(args) - document_type = args.document_type or "Branch" - dimension = frappe.get_doc("Accounting Dimension", document_type) - dimension.disabled = 1 - dimension.save() - - -def clear_dimension_defaults(dimension_name): - accounting_dimension = frappe.get_doc("Accounting Dimension", dimension_name) - accounting_dimension.dimension_defaults = [] - accounting_dimension.save() diff --git a/erpnext/setup/doctype/company/test_records.json b/erpnext/setup/doctype/company/test_records.json index f26caa50fde..0378ba939c3 100644 --- a/erpnext/setup/doctype/company/test_records.json +++ b/erpnext/setup/doctype/company/test_records.json @@ -188,5 +188,13 @@ "default_currency": "INR", "doctype": "Company", "create_chart_of_accounts_based_on": "Standard Template" + }, + { + "abbr": "TBC", + "company_name": "Trial Balance Company", + "country": "India", + "default_currency": "INR", + "doctype": "Company", + "create_chart_of_accounts_based_on": "Standard Template" } ] From d41e7098bda8da839ca7031a7731491e58352fcf Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 20 Mar 2026 17:05:39 +0530 Subject: [PATCH 06/14] refactor(test): move tax category custom field creation to bootstrap (cherry picked from commit 4454af8efd57b702c328dd54806858e3a3375fec) --- .../test_tax_withholding_category.py | 16 -------------- erpnext/tests/utils.py | 21 +++++++++++++++++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py index 66dc090f7c7..bd633c94dc9 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py @@ -18,7 +18,6 @@ class TestTaxWithholdingCategory(ERPNextTestSuite): # create relevant supplier, etc create_records() create_tax_withholding_category_records() - make_pan_no_field() def validate_tax_withholding_entries(self, doctype, docname, expected_entries): """Validate tax withholding entries for a document""" @@ -3998,18 +3997,3 @@ def create_lower_deduction_certificate( "certificate_limit": limit, } ).insert() - - -def make_pan_no_field(): - pan_field = { - "Supplier": [ - { - "fieldname": "pan", - "label": "PAN", - "fieldtype": "Data", - "translatable": 0, - } - ] - } - - create_custom_fields(pan_field, update=1) diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index bfc0d5d89f6..b5c8e19f648 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -8,6 +8,7 @@ from typing import Any, NewType import frappe from frappe import _ from frappe.core.doctype.report.report import get_report_module_dotted_path +from frappe.custom.doctype.custom_field.custom_field import create_custom_fields from frappe.tests.utils import load_test_records_for from frappe.utils import now_datetime, today @@ -246,14 +247,16 @@ class BootStrapTestData: frappe.db.commit() # nosemgrep - # Dimensions # DDL commands have implicit commit + # Dimensions self.make_dimensions() # custom doctype - # DDL commands have implicit commit self.make_custom_doctype() + # custom field + self.make_custom_field() + def update_system_settings(self): system_settings = frappe.get_doc("System Settings") system_settings.time_zone = "Asia/Kolkata" @@ -2829,6 +2832,20 @@ class BootStrapTestData: ] self.make_records(["document_type"], records) + def make_custom_field(self): + pan_field = { + "Supplier": [ + { + "fieldname": "pan", + "label": "PAN", + "fieldtype": "Data", + "translatable": 0, + } + ] + } + + create_custom_fields(pan_field, update=1) + BootStrapTestData() From cdc77caf6a0f6c460cb5fa3f38686a5887d8df5d Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 20 Mar 2026 18:43:46 +0530 Subject: [PATCH 07/14] refactor(test): move custom doctype data setup to bootstrap (cherry picked from commit 934740205aa6729c93b75f7ea57d735d11628df1) --- .../test_inventory_dimension.py | 26 +-------- erpnext/tests/utils.py | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py b/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py index cbf6059a812..fb62b0eb5c0 100644 --- a/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py +++ b/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py @@ -22,9 +22,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestInventoryDimension(ERPNextTestSuite): - def setUp(self): - prepare_test_data() - def test_validate_inventory_dimension(self): # Can not be child doc inv_dim1 = create_inventory_dimension( @@ -77,6 +74,7 @@ class TestInventoryDimension(ERPNextTestSuite): self.assertFalse(custom_field) def test_inventory_dimension(self): + create_warehouse("Shelf Warehouse") warehouse = "Shelf Warehouse - _TC" item_code = "_Test Item" @@ -556,28 +554,6 @@ def get_voucher_sl_entries(voucher_no, fields): ) -def prepare_test_data(): - for shelf in ["Shelf 1", "Shelf 2"]: - if not frappe.db.exists("Shelf", shelf): - frappe.get_doc({"doctype": "Shelf", "shelf_name": shelf}).insert(ignore_permissions=True) - - create_warehouse("Shelf Warehouse") - - for rack in ["Rack 1", "Rack 2"]: - if not frappe.db.exists("Rack", rack): - frappe.get_doc({"doctype": "Rack", "rack_name": rack}).insert(ignore_permissions=True) - - create_warehouse("Rack Warehouse") - - for site in ["Site 1", "Site 2"]: - if not frappe.db.exists("Inv Site", site): - frappe.get_doc({"doctype": "Inv Site", "site_name": site}).insert(ignore_permissions=True) - - for store in ["Store 1", "Store 2"]: - if not frappe.db.exists("Store", store): - frappe.get_doc({"doctype": "Store", "store_name": store}).insert(ignore_permissions=True) - - def create_inventory_dimension(**args): args = frappe._dict(args) diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index b5c8e19f648..a9ab25bff1a 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -254,6 +254,12 @@ class BootStrapTestData: # custom doctype self.make_custom_doctype() + # data on custom doctype + self.make_shelf() + self.make_rack() + self.make_inv_site() + self.make_store() + # custom field self.make_custom_field() @@ -2846,6 +2852,58 @@ class BootStrapTestData: create_custom_fields(pan_field, update=1) + def make_shelf(self): + records = [ + { + "doctype": "Shelf", + "shelf_name": "Shelf 1", + }, + { + "doctype": "Shelf", + "shelf_name": "Shelf 2", + }, + ] + self.make_records(["shelf_name"], records) + + def make_rack(self): + records = [ + { + "doctype": "Rack", + "rack_name": "Rack 1", + }, + { + "doctype": "Rack", + "rack_name": "Rack 2", + }, + ] + self.make_records(["rack_name"], records) + + def make_inv_site(self): + records = [ + { + "doctype": "Inv Site", + "site_name": "Site 1", + }, + { + "doctype": "Inv Site", + "site_name": "Site 2", + }, + ] + self.make_records(["site_name"], records) + + def make_store(self): + records = [ + { + "doctype": "Store", + "store_name": "Store 1", + }, + { + "doctype": "Store", + "store_name": "Store 2", + }, + ] + self.make_records(["store_name"], records) + BootStrapTestData() From ad2cf0624f434ec0016233a2545b5f7303735203 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 23 Mar 2026 14:10:06 +0530 Subject: [PATCH 08/14] refactor(test): move webform custom dt creation to boostrap (cherry picked from commit 426b7db3c85c949b62179f11b23bb75ee9fde74d) --- erpnext/tests/test_webform.py | 37 -------------------------------- erpnext/tests/utils.py | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/erpnext/tests/test_webform.py b/erpnext/tests/test_webform.py index 8b4ed9ceec9..9ba780e4805 100644 --- a/erpnext/tests/test_webform.py +++ b/erpnext/tests/test_webform.py @@ -22,7 +22,6 @@ class TestWebsite(ERPNextTestSuite): po1 = create_purchase_order(supplier="Supplier1") po2 = create_purchase_order(supplier="Supplier2") - create_custom_doctype() create_webform() create_order_assignment(supplier="Supplier1", po=po1.name) create_order_assignment(supplier="Supplier2", po=po2.name) @@ -62,42 +61,6 @@ def create_user(name, email): ).insert(ignore_if_duplicate=True) -def create_custom_doctype(): - frappe.get_doc( - { - "doctype": "DocType", - "name": "Order Assignment", - "module": "Buying", - "custom": 1, - "autoname": "field:po", - "fields": [ - {"label": "PO", "fieldname": "po", "fieldtype": "Link", "options": "Purchase Order"}, - { - "label": "Supplier", - "fieldname": "supplier", - "fieldtype": "Data", - "fetch_from": "po.supplier", - }, - ], - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "write": 1, - }, - {"read": 1, "role": "Supplier"}, - ], - } - ).insert(ignore_if_duplicate=True) - - def create_webform(): frappe.get_doc( { diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index a9ab25bff1a..6b591cd9500 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -2756,6 +2756,46 @@ class BootStrapTestData: } ).insert(ignore_permissions=True) + if not frappe.db.exists("DocType", "Order Assignment"): + frappe.get_doc( + { + "doctype": "DocType", + "name": "Order Assignment", + "module": "Buying", + "custom": 1, + "autoname": "field:po", + "fields": [ + { + "label": "PO", + "fieldname": "po", + "fieldtype": "Link", + "options": "Purchase Order", + }, + { + "label": "Supplier", + "fieldname": "supplier", + "fieldtype": "Data", + "fetch_from": "po.supplier", + }, + ], + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1, + }, + {"read": 1, "role": "Supplier"}, + ], + } + ).insert(ignore_if_duplicate=True) + def make_address(self): records = [ { From 0ba03ce8516ea6528496c59ee5569b019b9d4f47 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 23 Mar 2026 15:37:08 +0530 Subject: [PATCH 09/14] refactor(test): SLA move company creation to bootstrap (cherry picked from commit 77f41e120d43ff804ae6cbbeac04b5c44d0d8154) --- .../setup/doctype/company/test_records.json | 10 +++++ .../test_service_level_agreement.py | 37 +++---------------- erpnext/tests/utils.py | 6 +++ 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/erpnext/setup/doctype/company/test_records.json b/erpnext/setup/doctype/company/test_records.json index 0378ba939c3..bfcddfe0208 100644 --- a/erpnext/setup/doctype/company/test_records.json +++ b/erpnext/setup/doctype/company/test_records.json @@ -196,5 +196,15 @@ "default_currency": "INR", "doctype": "Company", "create_chart_of_accounts_based_on": "Standard Template" + }, + { + "abbr": "_TSS", + "company_name": "_Test Support SLA", + "country": "India", + "default_currency": "INR", + "doctype": "Company", + "chart_of_accounts": "Standard", + "create_chart_of_accounts_based_on": "Standard Template" } + ] diff --git a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py index d7ada387f82..0f6c1262b69 100644 --- a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py @@ -14,32 +14,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestServiceLevelAgreement(ERPNextTestSuite): - def setUp(self): - self.create_company() - frappe.db.set_single_value("Support Settings", "track_service_level_agreement", 1) - lead = frappe.qb.DocType("Lead") - frappe.qb.from_(lead).delete().where(lead.company == self.company).run() - - def create_company(self): - name = "_Test Support SLA" - company = None - if frappe.db.exists("Company", name): - company = frappe.get_doc("Company", name) - else: - company = frappe.get_doc( - { - "doctype": "Company", - "company_name": name, - "country": "India", - "default_currency": "INR", - "create_chart_of_accounts_based_on": "Standard Template", - "chart_of_accounts": "Standard", - } - ) - company = company.save() - - self.company = company.name - def test_service_level_agreement(self): # Default Service Level Agreement create_default_service_level_agreement = create_service_level_agreement( @@ -220,10 +194,9 @@ class TestServiceLevelAgreement(ERPNextTestSuite): doctype=doctype, sla_fulfilled_on=[{"status": "Converted"}], ) - # make lead with default SLA creation = datetime.datetime(2019, 3, 4, 12, 0) - lead = make_lead(creation=creation, index=1, company=self.company) + lead = make_lead(creation=creation, index=1, company="_Test Support SLA") self.assertEqual(lead.service_level_agreement, lead_sla.name) self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0)) @@ -251,7 +224,7 @@ class TestServiceLevelAgreement(ERPNextTestSuite): ) creation = datetime.datetime(2020, 3, 4, 4, 0) - lead = make_lead(creation, index=2, company=self.company) + lead = make_lead(creation, index=2, company="_Test Support SLA") frappe.flags.current_time = datetime.datetime(2020, 3, 4, 4, 15) lead.reload() @@ -285,7 +258,7 @@ class TestServiceLevelAgreement(ERPNextTestSuite): ) creation = datetime.datetime(2019, 3, 4, 12, 0) - lead = make_lead(creation=creation, index=1, company=self.company) + lead = make_lead(creation=creation, index=1, company="_Test Support SLA") self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0)) # failed with response time only @@ -312,7 +285,7 @@ class TestServiceLevelAgreement(ERPNextTestSuite): # fulfilled with response time only creation = datetime.datetime(2019, 3, 4, 12, 0) - lead = make_lead(creation=creation, index=2, company=self.company) + lead = make_lead(creation=creation, index=2, company="_Test Support SLA") self.assertEqual(lead.service_level_agreement, lead_sla.name) self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0)) @@ -339,7 +312,7 @@ class TestServiceLevelAgreement(ERPNextTestSuite): apply_sla_for_resolution=0, ) creation = datetime.datetime(2019, 3, 4, 12, 0) - lead = make_lead(creation=creation, index=4, company=self.company) + lead = make_lead(creation=creation, index=4, company="_Test Support SLA") applied_sla = frappe.db.get_value("Lead", lead.name, "service_level_agreement") self.assertFalse(applied_sla) diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index 6b591cd9500..df2d6c135d4 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -241,6 +241,7 @@ class BootStrapTestData: self.make_sales_person() self.make_activity_type() self.make_address() + self.update_support_settings() self.update_selling_settings() self.update_stock_settings() self.update_system_settings() @@ -271,6 +272,11 @@ class BootStrapTestData: system_settings.rounding_method = "Banker's Rounding" system_settings.save() + def update_support_settings(self): + support_settings = frappe.get_doc("Support Settings") + support_settings.track_service_level_agreement = True + support_settings.save() + def update_selling_settings(self): selling_settings = frappe.get_doc("Selling Settings") selling_settings.selling_price_list = "Standard Selling" From 8ea9133caa734c026c1ede0ec9cadfeed6685d25 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 23 Mar 2026 15:46:02 +0530 Subject: [PATCH 10/14] refactor(test): make ledger merge deterministic (cherry picked from commit d3cf8cb85173cab7007a1af821e1f41f8ea4ccb6) --- erpnext/accounts/doctype/ledger_merge/ledger_merge.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/ledger_merge/ledger_merge.py b/erpnext/accounts/doctype/ledger_merge/ledger_merge.py index 3dd3883608c..dc3fd5a9d04 100644 --- a/erpnext/accounts/doctype/ledger_merge/ledger_merge.py +++ b/erpnext/accounts/doctype/ledger_merge/ledger_merge.py @@ -79,7 +79,8 @@ def start_merge(docname): {"ledger_merge": ledger_merge.name, "current": successful_merges, "total": total}, ) except Exception: - frappe.db.rollback() + if not frappe.in_test: + frappe.db.rollback() ledger_merge.log_error("Ledger merge failed") finally: if successful_merges == total: From 37ad0665c6a9e7a97fd895f2024fd729f57a493f Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 23 Mar 2026 15:55:52 +0530 Subject: [PATCH 11/14] refactor(test): make asset capitalization deterministic (cherry picked from commit 2c53cf3902cb67f0bb1b91817a3db3fa93cecd91) --- .../doctype/asset_capitalization/test_asset_capitalization.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py index f245ac4f0a2..e37ac4c2bf3 100644 --- a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py @@ -380,6 +380,7 @@ class TestAssetCapitalization(ERPNextTestSuite): "asset_type": "Composite Component", "purchase_date": pr.posting_date, "available_for_use_date": pr.posting_date, + "location": "Test Location", } ) consumed_asset_doc.save() From f0aa82cc6daf77896ed518101c11e116d71486d2 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 23 Mar 2026 16:14:11 +0530 Subject: [PATCH 12/14] refactor(test): make stock entry deterministic (cherry picked from commit 8fd65d7afa56b1c6b2b08d3b5c38eb0a824551c9) --- erpnext/setup/doctype/company/test_records.json | 10 +++++++++- erpnext/stock/doctype/stock_entry/test_stock_entry.py | 3 +-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/erpnext/setup/doctype/company/test_records.json b/erpnext/setup/doctype/company/test_records.json index bfcddfe0208..74615e60162 100644 --- a/erpnext/setup/doctype/company/test_records.json +++ b/erpnext/setup/doctype/company/test_records.json @@ -205,6 +205,14 @@ "doctype": "Company", "chart_of_accounts": "Standard", "create_chart_of_accounts_based_on": "Standard Template" + }, + { + "abbr": "TQC", + "company_name": "Test Quality Company", + "country": "India", + "default_currency": "INR", + "doctype": "Company", + "chart_of_accounts": "Standard", + "create_chart_of_accounts_based_on": "Standard Template" } - ] diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 5d8ebdda56f..48488a7c5b6 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -2422,12 +2422,11 @@ class TestStockEntry(ERPNextTestSuite): Unit test case to check the document naming rule with company condition For Quality Inspection, when created from Stock Entry. """ - from erpnext.accounts.report.trial_balance.test_trial_balance import create_company from erpnext.controllers.stock_controller import make_quality_inspections from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse # create a separate company to handle document naming rule with company condition - qc_company = create_company(company_name="Test Quality Company") + qc_company = "Test Quality Company" # create document naming rule based on that for Quality Inspection Doctype qc_naming_rule = frappe.new_doc( From 7f29245eb6f27c979a07903c8f908325c54c738c Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 23 Mar 2026 16:14:24 +0530 Subject: [PATCH 13/14] refactor(test): move location creation to bootstrap in asset movement (cherry picked from commit fd2b76a4d21f727c413b4db28587684ad60bf121) --- .../asset_movement/test_asset_movement.py | 17 ----------------- erpnext/tests/utils.py | 1 + 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/erpnext/assets/doctype/asset_movement/test_asset_movement.py b/erpnext/assets/doctype/asset_movement/test_asset_movement.py index 88dd93a93cb..76d37d3abb4 100644 --- a/erpnext/assets/doctype/asset_movement/test_asset_movement.py +++ b/erpnext/assets/doctype/asset_movement/test_asset_movement.py @@ -16,7 +16,6 @@ class TestAssetMovement(ERPNextTestSuite): frappe.db.set_value( "Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC" ) - make_location() def test_movement(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") @@ -40,10 +39,6 @@ class TestAssetMovement(ERPNextTestSuite): if asset.docstatus == 0: asset.submit() - # check asset movement is created - if not frappe.db.exists("Location", "Test Location 2"): - frappe.get_doc({"doctype": "Location", "location_name": "Test Location 2"}).insert() - create_asset_movement( purpose="Transfer", company=asset.company, @@ -122,9 +117,6 @@ class TestAssetMovement(ERPNextTestSuite): if asset.docstatus == 0: asset.submit() - if not frappe.db.exists("Location", "Test Location 2"): - frappe.get_doc({"doctype": "Location", "location_name": "Test Location 2"}).insert() - movement = frappe.get_doc({"doctype": "Asset Movement", "reference_name": pr.name}) self.assertRaises(frappe.ValidationError, movement.cancel) @@ -150,9 +142,6 @@ class TestAssetMovement(ERPNextTestSuite): asset = create_asset(item_code="Macbook Pro", do_not_save=1) asset.save().submit() - if not frappe.db.exists("Location", "Test Location 2"): - frappe.get_doc({"doctype": "Location", "location_name": "Test Location 2"}).insert() - asset_creation_date = frappe.db.get_value( "Asset Movement", [["Asset Movement Item", "asset", "=", asset.name], ["docstatus", "=", 1]], @@ -197,9 +186,3 @@ def create_asset_movement(**args): movement.submit() return movement - - -def make_location(): - for location in ["Pune", "Mumbai", "Nagpur"]: - if not frappe.db.exists("Location", location): - frappe.get_doc({"doctype": "Location", "location_name": location}).insert(ignore_permissions=True) diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index df2d6c135d4..6aefc4da247 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -975,6 +975,7 @@ class BootStrapTestData: def make_location(self): records = [ {"doctype": "Location", "location_name": "Test Location"}, + {"doctype": "Location", "location_name": "Test Location 2"}, {"doctype": "Location", "location_name": "Test Location Area", "is_group": 1, "is_container": 1}, { "doctype": "Location", From e91cbd94b403330fb47edbaa6ee116e61708233b Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 24 Mar 2026 16:05:54 +0530 Subject: [PATCH 14/14] refactor(test): process statement of acc remove commit (cherry picked from commit bc2b8da59716febb61fd217a53f63684c9e08952) --- .../process_statement_of_accounts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py index 9cf27216b1e..a40cd03240e 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py @@ -563,10 +563,10 @@ def send_emails(document_name, from_scheduler=False, posting_date=None): new_from_date = add_months(new_to_date, -1 * doc.filter_duration) doc.add_comment("Comment", "Emails sent on: " + frappe.utils.format_datetime(frappe.utils.now())) if doc.report == "General Ledger": - doc.db_set("to_date", new_to_date, commit=True) - doc.db_set("from_date", new_from_date, commit=True) + frappe.db.set_value(doc.doctype, doc.name, "to_date", new_to_date) + frappe.db.set_value(doc.doctype, doc.name, "from_date", new_from_date) else: - doc.db_set("posting_date", new_to_date, commit=True) + frappe.db.set_value(doc.doctype, doc.name, "posting_date", new_to_date) return True else: return False