diff --git a/.github/workflows/run-indinvidual-tests.yml b/.github/workflows/run-individual-tests.yml similarity index 82% rename from .github/workflows/run-indinvidual-tests.yml rename to .github/workflows/run-individual-tests.yml index 3e4b8371f8a..a70a2394757 100644 --- a/.github/workflows/run-indinvidual-tests.yml +++ b/.github/workflows/run-individual-tests.yml @@ -4,8 +4,8 @@ on: workflow_dispatch: concurrency: - group: server-individual-tests-develop-${{ github.event_name }}-${{ github.event.number || github.event_name == 'workflow_dispatch' && github.run_id || '' }} - cancel-in-progress: false + group: server-individual-tests-lightmode-develop + cancel-in-progress: true permissions: contents: read @@ -21,7 +21,7 @@ jobs: - id: set-matrix run: | # Use grep and find to get the list of test files - matrix=$(find . -path '*/doctype/*/test_*.py' | xargs grep -l 'def test_' | awk '{ + matrix=$(find . -path '*/test_*.py' | xargs grep -l 'def test_' | sort | awk '{ # Remove ./ prefix, file extension, and replace / with . gsub(/^\.\//, "", $0) gsub(/\.py$/, "", $0) @@ -58,6 +58,7 @@ jobs: strategy: fail-fast: false matrix: ${{fromJson(needs.discover.outputs.matrix)}} + max-parallel: 14 name: Test @@ -130,4 +131,13 @@ jobs: FRAPPE_BRANCH: ${{ github.event.inputs.branch }} - name: Run Tests - run: 'cd ~/frappe-bench/ && bench --site test_site run-tests --app erpnext --module ${{ matrix.test }}' + run: | + site_name=$(echo "${{matrix.test}}" | sed -e 's/.*\.\(test_.*$\)/\1/') + echo "$site_name" + mkdir ~/frappe-bench/sites/$site_name + cp -r "${GITHUB_WORKSPACE}/.github/helper/site_config_mariadb.json" ~/frappe-bench/sites/$site_name/site_config.json + cd ~/frappe-bench/ + bench --site $site_name reinstall --yes + bench --site $site_name set-config allow_tests true + bench --site $site_name run-tests --module ${{ matrix.test }} --lightmode + diff --git a/.github/workflows/server-tests-mariadb.yml b/.github/workflows/server-tests-mariadb.yml index 2bfe5e7065d..b8e88d1b5f3 100644 --- a/.github/workflows/server-tests-mariadb.yml +++ b/.github/workflows/server-tests-mariadb.yml @@ -129,7 +129,7 @@ jobs: FRAPPE_BRANCH: ${{ github.event.client_payload.sha || github.event.inputs.branch }} - name: Run Tests - run: 'cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --app erpnext --total-builds ${{ strategy.job-total }} --build-number ${{ matrix.container }} --with-coverage' + run: 'cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --lightmode --app erpnext --total-builds ${{ strategy.job-total }} --build-number ${{ matrix.container }} --with-coverage' env: TYPE: server diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py index c3e23fe6e50..3c841aef05f 100644 --- a/erpnext/accounts/deferred_revenue.py +++ b/erpnext/accounts/deferred_revenue.py @@ -524,7 +524,8 @@ def make_gl_entries( if gl_entries: try: make_gl_entries(gl_entries, cancel=(doc.docstatus == 2), merge_entries=True) - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() except Exception as e: if frappe.in_test: doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}") @@ -606,7 +607,8 @@ def book_revenue_via_journal_entry( if submit: journal_entry.submit() - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() except Exception: frappe.db.rollback() doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}") diff --git a/erpnext/accounts/doctype/account/test_account.py b/erpnext/accounts/doctype/account/test_account.py index 6deff1ac3e6..95f17967fa7 100644 --- a/erpnext/accounts/doctype/account/test_account.py +++ b/erpnext/accounts/doctype/account/test_account.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.doctype.account.account import ( @@ -12,11 +11,10 @@ from erpnext.accounts.doctype.account.account import ( update_account_number, ) from erpnext.stock import get_company_default_inventory_account, get_warehouse_account - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Company"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAccount(IntegrationTestCase): +class TestAccount(ERPNextTestSuite): def test_rename_account(self): if not frappe.db.exists("Account", "1210 - Debtors - _TC"): acc = frappe.new_doc("Account") diff --git a/erpnext/accounts/doctype/account/test_records.json b/erpnext/accounts/doctype/account/test_records.json deleted file mode 100644 index d15f7ad4c0a..00000000000 --- a/erpnext/accounts/doctype/account/test_records.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - { - "doctype": "Account", - "name": "_Test Account 1" - } -] diff --git a/erpnext/accounts/doctype/account_category/test_account_category.py b/erpnext/accounts/doctype/account_category/test_account_category.py index ea3c2c7783c..e695b11bcb5 100644 --- a/erpnext/accounts/doctype/account_category/test_account_category.py +++ b/erpnext/accounts/doctype/account_category/test_account_category.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestAccountCategory(IntegrationTestCase): - """ - Integration tests for AccountCategory. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/accounts/doctype/account_closing_balance/test_account_closing_balance.py b/erpnext/accounts/doctype/account_closing_balance/test_account_closing_balance.py index 53f4e5d15af..a39bd00579e 100644 --- a/erpnext/accounts/doctype/account_closing_balance/test_account_closing_balance.py +++ b/erpnext/accounts/doctype/account_closing_balance/test_account_closing_balance.py @@ -2,8 +2,9 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountClosingBalance(IntegrationTestCase): +class TestAccountClosingBalance(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index ff8094ba432..70253c674c5 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -103,10 +103,6 @@ class AccountingDimension(Document): if not self.fieldname: self.fieldname = scrub(self.label) - def on_update(self): - frappe.flags.accounting_dimensions = None - frappe.flags.accounting_dimensions_details = None - def make_dimension_in_accounting_doctypes(doc, doclist=None): if not doclist: @@ -241,34 +237,26 @@ def get_doctypes_with_dimensions(): return frappe.get_hooks("accounting_dimension_doctypes") -def get_accounting_dimensions(as_list=True, filters=None): - if not filters: - filters = {"disabled": 0} - - if frappe.flags.accounting_dimensions is None: - frappe.flags.accounting_dimensions = frappe.get_all( - "Accounting Dimension", - fields=["label", "fieldname", "disabled", "document_type"], - filters=filters, - ) +def get_accounting_dimensions(as_list=True): + accounting_dimensions = frappe.get_all( + "Accounting Dimension", + fields=["label", "fieldname", "disabled", "document_type"], + filters={"disabled": 0}, + ) if as_list: - return [d.fieldname for d in frappe.flags.accounting_dimensions] + return [d.fieldname for d in accounting_dimensions] else: - return frappe.flags.accounting_dimensions + return accounting_dimensions def get_checks_for_pl_and_bs_accounts(): - if frappe.flags.accounting_dimensions_details is None: - # nosemgrep - frappe.flags.accounting_dimensions_details = frappe.db.sql( - """SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs + return frappe.db.sql( + """SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c WHERE p.name = c.parent AND p.disabled = 0""", - as_dict=1, - ) - - return frappe.flags.accounting_dimensions_details + as_dict=1, + ) def get_dimension_with_children(doctype, dimensions): diff --git a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py index 769522e2642..81e639dc6b2 100644 --- a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py @@ -3,15 +3,13 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Cost Center", "Location", "Warehouse", "Department"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountingDimension(IntegrationTestCase): +class TestAccountingDimension(ERPNextTestSuite): def setUp(self): create_dimension() @@ -80,11 +78,6 @@ class TestAccountingDimension(IntegrationTestCase): si.save() self.assertRaises(frappe.ValidationError, si.submit) - def tearDown(self): - disable_dimension() - frappe.flags.accounting_dimensions_details = None - frappe.flags.dimension_filter_map = None - def create_dimension(): frappe.set_user("Administrator") diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py index 6eff320e3a3..3c6b29546ff 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py +++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py @@ -69,37 +69,34 @@ class AccountingDimensionFilter(Document): def get_dimension_filter_map(): - if not frappe.flags.get("dimension_filter_map"): - filters = frappe.db.sql( - """ - SELECT - a.applicable_on_account, d.dimension_value, p.accounting_dimension, - p.allow_or_restrict, p.fieldname, a.is_mandatory - FROM - `tabApplicable On Account` a, - `tabAccounting Dimension Filter` p - LEFT JOIN `tabAllowed Dimension` d ON d.parent = p.name - WHERE - p.name = a.parent - AND p.disabled = 0 - """, - as_dict=1, + filters = frappe.db.sql( + """ + SELECT + a.applicable_on_account, d.dimension_value, p.accounting_dimension, + p.allow_or_restrict, p.fieldname, a.is_mandatory + FROM + `tabApplicable On Account` a, + `tabAccounting Dimension Filter` p + LEFT JOIN `tabAllowed Dimension` d ON d.parent = p.name + WHERE + p.name = a.parent + AND p.disabled = 0 + """, + as_dict=1, + ) + + dimension_filter_map = {} + + for f in filters: + build_map( + dimension_filter_map, + f.fieldname, + f.applicable_on_account, + f.dimension_value, + f.allow_or_restrict, + f.is_mandatory, ) - - dimension_filter_map = {} - - for f in filters: - build_map( - dimension_filter_map, - f.fieldname, - f.applicable_on_account, - f.dimension_value, - f.allow_or_restrict, - f.is_mandatory, - ) - frappe.flags.dimension_filter_map = dimension_filter_map - - return frappe.flags.dimension_filter_map + return dimension_filter_map def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory): 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 bff288cf4d8..9bed10824bb 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 @@ -11,11 +11,10 @@ from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension imp ) from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Location", "Cost Center", "Department"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountingDimensionFilter(unittest.TestCase): +class TestAccountingDimensionFilter(ERPNextTestSuite): def setUp(self): create_dimension() create_accounting_dimension_filter() @@ -44,17 +43,6 @@ class TestAccountingDimensionFilter(unittest.TestCase): self.assertRaises(MandatoryAccountDimensionError, si.submit) self.invoice_list.append(si) - def tearDown(self): - disable_dimension_filter() - disable_dimension() - frappe.flags.accounting_dimensions_details = None - frappe.flags.dimension_filter_map = None - - for si in self.invoice_list: - si.load_from_db() - if si.docstatus == 1: - si.cancel() - def create_accounting_dimension_filter(): if not frappe.db.get_value("Accounting Dimension Filter", {"accounting_dimension": "Cost Center"}): diff --git a/erpnext/accounts/doctype/accounting_period/test_accounting_period.py b/erpnext/accounts/doctype/accounting_period/test_accounting_period.py index 1dde96c223d..84df275f305 100644 --- a/erpnext/accounts/doctype/accounting_period/test_accounting_period.py +++ b/erpnext/accounts/doctype/accounting_period/test_accounting_period.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, nowdate from erpnext.accounts.doctype.accounting_period.accounting_period import ( @@ -11,11 +10,10 @@ from erpnext.accounts.doctype.accounting_period.accounting_period import ( OverlapError, ) from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountingPeriod(IntegrationTestCase): +class TestAccountingPeriod(ERPNextTestSuite): def test_overlap(self): ap1 = create_accounting_period( start_date="2018-04-01", end_date="2018-06-30", company="Wind Power LLC" @@ -90,10 +88,6 @@ class TestAccountingPeriod(IntegrationTestCase): doc.submit() # Should not raise self.assertEqual(doc.docstatus, 1) - def tearDown(self): - for d in frappe.get_all("Accounting Period"): - frappe.delete_doc("Accounting Period", d.name) - def create_accounting_period(**args): args = frappe._dict(args) diff --git a/erpnext/accounts/doctype/accounts_settings/test_accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/test_accounts_settings.py index e555f0ded15..d57bd1cc009 100644 --- a/erpnext/accounts/doctype/accounts_settings/test_accounts_settings.py +++ b/erpnext/accounts/doctype/accounts_settings/test_accounts_settings.py @@ -1,17 +1,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountsSettings(IntegrationTestCase): - def tearDown(self): - # Just in case `save` method succeeds, we need to take things back to default so that other tests - # don't break - cur_settings = frappe.get_doc("Accounts Settings", "Accounts Settings") - cur_settings.allow_stale = 1 - cur_settings.save() - +class TestAccountsSettings(ERPNextTestSuite): def test_stale_days(self): cur_settings = frappe.get_doc("Accounts Settings", "Accounts Settings") cur_settings.allow_stale = 0 diff --git a/erpnext/accounts/doctype/advance_payment_ledger_entry/test_advance_payment_ledger_entry.py b/erpnext/accounts/doctype/advance_payment_ledger_entry/test_advance_payment_ledger_entry.py index f824e6893e4..53047b61718 100644 --- a/erpnext/accounts/doctype/advance_payment_ledger_entry/test_advance_payment_ledger_entry.py +++ b/erpnext/accounts/doctype/advance_payment_ledger_entry/test_advance_payment_ledger_entry.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate, today from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry @@ -10,14 +9,13 @@ from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order -# On IntegrationTestCase, the doctype test records and all +# On ERPNextTestSuite, the doctype test records and all # link-field test record depdendencies are recursively loaded # Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAdvancePaymentLedgerEntry(AccountsTestMixin, IntegrationTestCase): +class TestAdvancePaymentLedgerEntry(AccountsTestMixin, ERPNextTestSuite): """ Integration tests for AdvancePaymentLedgerEntry. Use this class for testing interactions between multiple components. @@ -30,9 +28,6 @@ class TestAdvancePaymentLedgerEntry(AccountsTestMixin, IntegrationTestCase): self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_sales_order(self, qty=1, rate=100, currency="INR", do_not_submit=False): """ Helper method diff --git a/erpnext/accounts/doctype/bank/test_bank.py b/erpnext/accounts/doctype/bank/test_bank.py index 98e83fd5837..1249b6cc34a 100644 --- a/erpnext/accounts/doctype/bank/test_bank.py +++ b/erpnext/accounts/doctype/bank/test_bank.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBank(IntegrationTestCase): +class TestBank(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_account/test_bank_account.py b/erpnext/accounts/doctype/bank_account/test_bank_account.py index 146f426e6c7..0645a110140 100644 --- a/erpnext/accounts/doctype/bank_account/test_bank_account.py +++ b/erpnext/accounts/doctype/bank_account/test_bank_account.py @@ -2,10 +2,8 @@ # See license.txt import unittest -import frappe -from frappe import ValidationError -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBankAccount(IntegrationTestCase): +class TestBankAccount(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_account_subtype/test_bank_account_subtype.py b/erpnext/accounts/doctype/bank_account_subtype/test_bank_account_subtype.py index d4a6c689bc3..0e6a2c52138 100644 --- a/erpnext/accounts/doctype/bank_account_subtype/test_bank_account_subtype.py +++ b/erpnext/accounts/doctype/bank_account_subtype/test_bank_account_subtype.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBankAccountSubtype(IntegrationTestCase): +class TestBankAccountSubtype(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_account_type/test_bank_account_type.py b/erpnext/accounts/doctype/bank_account_type/test_bank_account_type.py index 0d41686da59..0b602b3b9d6 100644 --- a/erpnext/accounts/doctype/bank_account_type/test_bank_account_type.py +++ b/erpnext/accounts/doctype/bank_account_type/test_bank_account_type.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBankAccountType(IntegrationTestCase): +class TestBankAccountType(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_clearance/test_bank_clearance.py b/erpnext/accounts/doctype/bank_clearance/test_bank_clearance.py index dda65594554..4982177e73b 100644 --- a/erpnext/accounts/doctype/bank_clearance/test_bank_clearance.py +++ b/erpnext/accounts/doctype/bank_clearance/test_bank_clearance.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, getdate from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center @@ -15,13 +14,12 @@ from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse -from erpnext.tests.utils import if_lending_app_installed, if_lending_app_not_installed +from erpnext.tests.utils import ERPNextTestSuite, if_lending_app_installed, if_lending_app_not_installed -class TestBankClearance(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestBankClearance(ERPNextTestSuite): + def setUp(self): + frappe.clear_cache() create_warehouse( warehouse_name="_Test Warehouse", properties={"parent_warehouse": "All Warehouses - _TC"}, diff --git a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py index eaf55ce7708..72dad011e56 100644 --- a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBankGuarantee(IntegrationTestCase): +class TestBankGuarantee(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py b/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py index 53586b333b4..5354aa0c4dd 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py +++ b/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py @@ -4,7 +4,6 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import ( @@ -13,9 +12,10 @@ from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool ) from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestBankReconciliationTool(AccountsTestMixin, IntegrationTestCase): +class TestBankReconciliationTool(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -24,9 +24,6 @@ class TestBankReconciliationTool(AccountsTestMixin, IntegrationTestCase): qb.from_(bank_dt).delete().where(bank_dt.name == "HDFC").run() self.create_bank_account() - def tearDown(self): - frappe.db.rollback() - def create_bank_account(self): bank = frappe.get_doc( { @@ -43,6 +40,7 @@ class TestBankReconciliationTool(AccountsTestMixin, IntegrationTestCase): "bank": bank.name, "is_company_account": True, "account": self.bank, # account from Chart of Accounts + "company": self.company, } ) .insert() diff --git a/erpnext/accounts/doctype/bank_statement_import/test_bank_statement_import.py b/erpnext/accounts/doctype/bank_statement_import/test_bank_statement_import.py index 3e1cee9115e..2ae00059c83 100644 --- a/erpnext/accounts/doctype/bank_statement_import/test_bank_statement_import.py +++ b/erpnext/accounts/doctype/bank_statement_import/test_bank_statement_import.py @@ -1,15 +1,14 @@ # Copyright (c) 2020, Frappe Technologies and Contributors # See license.txt -import unittest - from erpnext.accounts.doctype.bank_statement_import.bank_statement_import import ( is_mt940_format, preprocess_mt940_content, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestBankStatementImport(unittest.TestCase): +class TestBankStatementImport(ERPNextTestSuite): """Unit tests for Bank Statement Import functions""" def test_preprocess_mt940_content_with_long_statement_number(self): diff --git a/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py b/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py index da2c28a148c..bb1e436c5f7 100644 --- a/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py +++ b/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py @@ -2,27 +2,20 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import create_bank_account +from erpnext.tests.utils import ERPNextTestSuite IBAN_1 = "DE02000000003716541159" IBAN_2 = "DE02500105170137075030" -class TestAutoMatchParty(IntegrationTestCase): - @classmethod - def setUpClass(cls): +class TestAutoMatchParty(ERPNextTestSuite): + def setUp(self): create_bank_account() frappe.db.set_single_value("Accounts Settings", "enable_party_matching", 1) frappe.db.set_single_value("Accounts Settings", "enable_fuzzy_matching", 1) - return super().setUpClass() - - @classmethod - def tearDownClass(cls): - frappe.db.set_single_value("Accounts Settings", "enable_party_matching", 0) - frappe.db.set_single_value("Accounts Settings", "enable_fuzzy_matching", 0) def test_match_by_account_number(self): create_supplier_for_match(account_no=IBAN_1[11:]) diff --git a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py index e04c67e54d4..c69d255c51a 100644 --- a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py @@ -6,7 +6,6 @@ import json import frappe from frappe import utils from frappe.model.docstatus import DocStatus -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import ( get_linked_payments, @@ -19,12 +18,10 @@ from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_paymen from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice -from erpnext.tests.utils import if_lending_app_installed - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Cost Center"] +from erpnext.tests.utils import ERPNextTestSuite, if_lending_app_installed -class TestBankTransaction(IntegrationTestCase): +class TestBankTransaction(ERPNextTestSuite): def setUp(self): make_pos_profile() diff --git a/erpnext/accounts/doctype/bisect_accounting_statements/test_bisect_accounting_statements.py b/erpnext/accounts/doctype/bisect_accounting_statements/test_bisect_accounting_statements.py index fd1793b2560..55e4811a87f 100644 --- a/erpnext/accounts/doctype/bisect_accounting_statements/test_bisect_accounting_statements.py +++ b/erpnext/accounts/doctype/bisect_accounting_statements/test_bisect_accounting_statements.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestBisectAccountingStatements(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestBisectAccountingStatements(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bisect_nodes/test_bisect_nodes.py b/erpnext/accounts/doctype/bisect_nodes/test_bisect_nodes.py index 1f37009d8e2..082b2a28f1f 100644 --- a/erpnext/accounts/doctype/bisect_nodes/test_bisect_nodes.py +++ b/erpnext/accounts/doctype/bisect_nodes/test_bisect_nodes.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestBisectNodes(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestBisectNodes(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index ba9b4c04e08..9632981b1c1 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -19,12 +19,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestBudget(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_monthly_distribution() - cls.make_projects() - def setUp(self): frappe.db.set_single_value("Accounts Settings", "use_legacy_budget_controller", False) self.company = "_Test Company" diff --git a/erpnext/accounts/doctype/cashier_closing/test_cashier_closing.py b/erpnext/accounts/doctype/cashier_closing/test_cashier_closing.py index 56cf2b53919..1c826e31add 100644 --- a/erpnext/accounts/doctype/cashier_closing/test_cashier_closing.py +++ b/erpnext/accounts/doctype/cashier_closing/test_cashier_closing.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCashierClosing(IntegrationTestCase): +class TestCashierClosing(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/chart_of_accounts_importer/test_chart_of_accounts_importer.py b/erpnext/accounts/doctype/chart_of_accounts_importer/test_chart_of_accounts_importer.py index 214de348169..f96d46e90a9 100644 --- a/erpnext/accounts/doctype/chart_of_accounts_importer/test_chart_of_accounts_importer.py +++ b/erpnext/accounts/doctype/chart_of_accounts_importer/test_chart_of_accounts_importer.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestChartofAccountsImporter(IntegrationTestCase): +class TestChartofAccountsImporter(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/cheque_print_template/test_cheque_print_template.py b/erpnext/accounts/doctype/cheque_print_template/test_cheque_print_template.py index b7ee19d4422..54c62141e1c 100644 --- a/erpnext/accounts/doctype/cheque_print_template/test_cheque_print_template.py +++ b/erpnext/accounts/doctype/cheque_print_template/test_cheque_print_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestChequePrintTemplate(IntegrationTestCase): +class TestChequePrintTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/cost_center/test_cost_center.py b/erpnext/accounts/doctype/cost_center/test_cost_center.py index 375541a3960..cfde7238eab 100644 --- a/erpnext/accounts/doctype/cost_center/test_cost_center.py +++ b/erpnext/accounts/doctype/cost_center/test_cost_center.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestCostCenter(IntegrationTestCase): +class TestCostCenter(ERPNextTestSuite): def test_cost_center_creation_against_child_node(self): cost_center = frappe.get_doc( { diff --git a/erpnext/accounts/doctype/cost_center/test_records.json b/erpnext/accounts/doctype/cost_center/test_records.json deleted file mode 100644 index 941a85b382d..00000000000 --- a/erpnext/accounts/doctype/cost_center/test_records.json +++ /dev/null @@ -1,23 +0,0 @@ -[ - { - "company": "_Test Company", - "cost_center_name": "_Test Cost Center", - "doctype": "Cost Center", - "is_group": 0, - "parent_cost_center": "_Test Company - _TC" - }, - { - "company": "_Test Company", - "cost_center_name": "_Test Cost Center 2", - "doctype": "Cost Center", - "is_group": 0, - "parent_cost_center": "_Test Company - _TC" - }, - { - "company": "_Test Company", - "cost_center_name": "_Test Write Off Cost Center", - "doctype": "Cost Center", - "is_group": 0, - "parent_cost_center": "_Test Company - _TC" - } -] diff --git a/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py index 680e2113ec1..4047e6c7169 100644 --- a/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py +++ b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py @@ -4,7 +4,6 @@ import unittest import frappe from frappe.query_builder.functions import Sum -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center @@ -16,9 +15,10 @@ from erpnext.accounts.doctype.cost_center_allocation.cost_center_allocation impo WrongPercentageAllocation, ) from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestCostCenterAllocation(IntegrationTestCase): +class TestCostCenterAllocation(ERPNextTestSuite): def setUp(self): cost_centers = [ "Main Cost Center 1", @@ -191,7 +191,7 @@ class TestCostCenterAllocation(IntegrationTestCase): coa2.cancel() jv.cancel() - @IntegrationTestCase.change_settings("System Settings", {"rounding_method": "Commercial Rounding"}) + @ERPNextTestSuite.change_settings("System Settings", {"rounding_method": "Commercial Rounding"}) def test_debit_credit_on_cost_center_allocation_for_commercial_rounding(self): from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice diff --git a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py index ce57a27a536..770c24cd740 100644 --- a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py +++ b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py @@ -3,11 +3,9 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite def test_create_test_data(): @@ -88,6 +86,7 @@ def test_create_test_data(): "partner_name": "_Test Coupon Partner", "commission_rate": 2, "referral_code": "COPART", + "territory": "All Territories", } ) sales_partner.insert() @@ -110,13 +109,10 @@ def test_create_test_data(): coupon_code.insert() -class TestCouponCode(IntegrationTestCase): +class TestCouponCode(ERPNextTestSuite): def setUp(self): test_create_test_data() - def tearDown(self): - frappe.set_user("Administrator") - def test_sales_order_with_coupon_code(self): frappe.db.set_value("Coupon Code", "SAVE30", "used", 0) diff --git a/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py b/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py index 3097f72d628..0c1c163a398 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py +++ b/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCurrencyExchangeSettings(IntegrationTestCase): +class TestCurrencyExchangeSettings(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/dunning/test_dunning.py b/erpnext/accounts/doctype/dunning/test_dunning.py index 4ba44a2a3c9..6eaf1d8798e 100644 --- a/erpnext/accounts/doctype/dunning/test_dunning.py +++ b/erpnext/accounts/doctype/dunning/test_dunning.py @@ -4,37 +4,20 @@ import json import frappe from frappe.model import mapper -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, nowdate, today from erpnext import get_default_cost_center from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry -from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import ( - unlink_payment_on_cancel_of_invoice, -) from erpnext.accounts.doctype.sales_invoice.sales_invoice import ( create_dunning as create_dunning_from_sales_invoice, ) from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( create_sales_invoice_against_cost_center, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Company", "Cost Center"] +from erpnext.tests.utils import ERPNextTestSuite -class TestDunning(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - create_dunning_type("First Notice", fee=0.0, interest=0.0, is_default=1) - create_dunning_type("Second Notice", fee=10.0, interest=10.0, is_default=0) - unlink_payment_on_cancel_of_invoice() - - @classmethod - def tearDownClass(cls): - unlink_payment_on_cancel_of_invoice(0) - super().tearDownClass() - +class TestDunning(ERPNextTestSuite): def test_dunning_without_fees(self): dunning = create_dunning(overdue_days=20) diff --git a/erpnext/accounts/doctype/dunning_type/test_dunning_type.py b/erpnext/accounts/doctype/dunning_type/test_dunning_type.py index 5a95aa68ea9..4cf60c86600 100644 --- a/erpnext/accounts/doctype/dunning_type/test_dunning_type.py +++ b/erpnext/accounts/doctype/dunning_type/test_dunning_type.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestDunningType(IntegrationTestCase): +class TestDunningType(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/dunning_type/test_records.json b/erpnext/accounts/doctype/dunning_type/test_records.json deleted file mode 100644 index 7f28aab873c..00000000000 --- a/erpnext/accounts/doctype/dunning_type/test_records.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "doctype": "Dunning Type", - "dunning_type": "_Test First Notice", - "company": "_Test Company", - "is_default": 1, - "dunning_fee": 0.0, - "rate_of_interest": 0.0, - "dunning_letter_text": [ - { - "language": "en", - "body_text": "We have still not received payment for our invoice", - "closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees." - } - ], - "income_account": "Sales - _TC", - "cost_center": "_Test Cost Center - _TC" - }, - { - "doctype": "Dunning Type", - "dunning_type": "_Test Second Notice", - "company": "_Test Company", - "is_default": 0, - "dunning_fee": 10.0, - "rate_of_interest": 10.0, - "dunning_letter_text": [ - { - "language": "en", - "body_text": "We have still not received payment for our invoice", - "closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees." - } - ], - "income_account": "Sales - _TC", - "cost_center": "_Test Cost Center - _TC" - } -] diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/test_exchange_rate_revaluation.py b/erpnext/accounts/doctype/exchange_rate_revaluation/test_exchange_rate_revaluation.py index 96079284dd9..1310a8b482b 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/test_exchange_rate_revaluation.py +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/test_exchange_rate_revaluation.py @@ -5,15 +5,15 @@ import frappe from frappe.query_builder import functions from frappe.query_builder.utils import DocType -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): +class TestExchangeRateRevaluation(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_usd_receivable_account() @@ -22,14 +22,13 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): self.clear_old_entries() self.set_system_and_company_settings() - def tearDown(self): - frappe.db.rollback() - def set_system_and_company_settings(self): # set number and currency precision system_settings = frappe.get_doc("System Settings") system_settings.float_precision = 2 system_settings.currency_precision = 2 + system_settings.language = "en" + system_settings.time_zone = "Asia/Kolkata" system_settings.save() # Using Exchange Gain/Loss account for unrealized as well. @@ -37,7 +36,7 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): company_doc.unrealized_exchange_gain_loss_account = company_doc.exchange_gain_loss_account company_doc.save() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) @@ -91,7 +90,7 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): )[0] self.assertEqual(acc_balance.balance, 8500.0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) @@ -164,7 +163,7 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): self.assertEqual(acc_balance.balance, 0.0) self.assertEqual(acc_balance.balance_in_account_currency, 0.0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) @@ -259,7 +258,7 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): self.assertEqual(flt(acc_balance.balance, precision), 0.0) self.assertEqual(flt(acc_balance.balance_in_account_currency, precision), 0.0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) diff --git a/erpnext/accounts/doctype/finance_book/test_finance_book.py b/erpnext/accounts/doctype/finance_book/test_finance_book.py index e2c156a1df5..e803eabf93a 100644 --- a/erpnext/accounts/doctype/finance_book/test_finance_book.py +++ b/erpnext/accounts/doctype/finance_book/test_finance_book.py @@ -3,12 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestFinanceBook(IntegrationTestCase): +class TestFinanceBook(ERPNextTestSuite): def test_finance_book(self): finance_book = create_finance_book() diff --git a/erpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py b/erpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py index dcfe884bdf3..a23c6bb6883 100644 --- a/erpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py +++ b/erpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py @@ -19,12 +19,6 @@ from erpnext.accounts.doctype.financial_report_template.test_financial_report_te from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.utils import get_currency_precision, get_fiscal_year -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - class TestDependencyResolver(FinancialReportTemplateTestCase): """Test cases for DependencyResolver class""" diff --git a/erpnext/accounts/doctype/financial_report_template/test_financial_report_template.py b/erpnext/accounts/doctype/financial_report_template/test_financial_report_template.py index ef5404bd478..9372c503d12 100644 --- a/erpnext/accounts/doctype/financial_report_template/test_financial_report_template.py +++ b/erpnext/accounts/doctype/financial_report_template/test_financial_report_template.py @@ -2,29 +2,16 @@ # For license information, please see license.txt import frappe -from frappe.tests import IntegrationTestCase -from frappe.tests.utils import make_test_records -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] +from erpnext.tests.utils import ERPNextTestSuite -class TestFinancialReportTemplate(IntegrationTestCase): - pass - - -class FinancialReportTemplateTestCase(IntegrationTestCase): +class FinancialReportTemplateTestCase(ERPNextTestSuite): """Utility class with common setup and helper methods for all test classes""" - @classmethod - def setUpClass(cls): + def setUp(self): """Set up test data""" - make_test_records("Company") - make_test_records("Fiscal Year") - cls.create_test_template() + self.create_test_template() @classmethod def create_test_template(cls): diff --git a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py index 22624e270aa..b6ce0696bdb 100644 --- a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py +++ b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py @@ -3,13 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import now_datetime -IGNORE_TEST_RECORD_DEPENDENCIES = ["Company"] +from erpnext.tests.utils import ERPNextTestSuite -class TestFiscalYear(IntegrationTestCase): +class TestFiscalYear(ERPNextTestSuite): def test_extra_year(self): if frappe.db.exists("Fiscal Year", "_Test Fiscal Year 2000"): frappe.delete_doc("Fiscal Year", "_Test Fiscal Year 2000") diff --git a/erpnext/accounts/doctype/gl_entry/test_gl_entry.py b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py index 11269f005db..bd391b4b8f4 100644 --- a/erpnext/accounts/doctype/gl_entry/test_gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py @@ -4,13 +4,13 @@ import unittest import frappe from frappe.model.naming import parse_naming_series -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.gl_entry.gl_entry import rename_gle_sle_docs from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestGLEntry(IntegrationTestCase): +class TestGLEntry(ERPNextTestSuite): def test_round_off_entry(self): frappe.db.set_value("Company", "_Test Company", "round_off_account", "_Test Write Off - _TC") frappe.db.set_value("Company", "_Test Company", "round_off_cost_center", "_Test Cost Center - _TC") diff --git a/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py index f34e2fd2434..00946e5fec1 100644 --- a/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py +++ b/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py @@ -3,16 +3,16 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, nowdate from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_against_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries +from erpnext.tests.utils import ERPNextTestSuite -class TestInvoiceDiscounting(IntegrationTestCase): +class TestInvoiceDiscounting(ERPNextTestSuite): def setUp(self): self.ar_credit = create_account( account_name="_Test Accounts Receivable Credit", diff --git a/erpnext/accounts/doctype/item_tax_template/test_item_tax_template.py b/erpnext/accounts/doctype/item_tax_template/test_item_tax_template.py index d5d8701fdc2..07032b79db2 100644 --- a/erpnext/accounts/doctype/item_tax_template/test_item_tax_template.py +++ b/erpnext/accounts/doctype/item_tax_template/test_item_tax_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestItemTaxTemplate(IntegrationTestCase): +class TestItemTaxTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/item_tax_template/test_records.json b/erpnext/accounts/doctype/item_tax_template/test_records.json deleted file mode 100644 index 4d9537d4b89..00000000000 --- a/erpnext/accounts/doctype/item_tax_template/test_records.json +++ /dev/null @@ -1,79 +0,0 @@ -[ - { - "doctype": "Item Tax Template", - "title": "_Test Account Excise Duty @ 10", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 10, - "tax_type": "_Test Account Excise Duty - _TC" - } - ] - }, - { - "doctype": "Item Tax Template", - "title": "_Test Account Excise Duty @ 12", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 12, - "tax_type": "_Test Account Excise Duty - _TC" - } - ] - }, - { - "doctype": "Item Tax Template", - "title": "_Test Account Excise Duty @ 15", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 15, - "tax_type": "_Test Account Excise Duty - _TC" - } - ] - }, - { - "doctype": "Item Tax Template", - "title": "_Test Account Excise Duty @ 20", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 20, - "tax_type": "_Test Account Excise Duty - _TC" - } - ] - }, - { - "doctype": "Item Tax Template", - "title": "_Test Item Tax Template 1", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 5, - "tax_type": "_Test Account Excise Duty - _TC" - }, - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 10, - "tax_type": "_Test Account Education Cess - _TC" - }, - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 15, - "tax_type": "_Test Account S&H Education Cess - _TC" - } - ] - } -] diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index 1a048a237bf..53d6013e1e2 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -2,19 +2,20 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt, nowdate from erpnext.accounts.doctype.account.test_account import get_inventory_account from erpnext.accounts.doctype.journal_entry.journal_entry import StockAccountInvalidTransaction from erpnext.exceptions import InvalidAccountCurrency from erpnext.selling.doctype.customer.test_customer import make_customer, set_credit_limit +from erpnext.tests.utils import ERPNextTestSuite -class TestJournalEntry(IntegrationTestCase): - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) +class TestJournalEntry(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Journal Entry") + + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_journal_entry_with_against_jv(self): jv_invoice = frappe.copy_doc(self.globalTestRecords["Journal Entry"][2]) base_jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][0]) @@ -149,7 +150,6 @@ class TestJournalEntry(IntegrationTestCase): if account_bal == stock_bal: self.assertRaises(StockAccountInvalidTransaction, jv.save) - frappe.db.rollback() else: jv.submit() jv.cancel() diff --git a/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py b/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py index 95a287435ff..946f4a64a43 100644 --- a/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py +++ b/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestJournalEntryTemplate(IntegrationTestCase): +class TestJournalEntryTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/ledger_health/test_ledger_health.py b/erpnext/accounts/doctype/ledger_health/test_ledger_health.py index 0eec86ccc0f..84fd3925ded 100644 --- a/erpnext/accounts/doctype/ledger_health/test_ledger_health.py +++ b/erpnext/accounts/doctype/ledger_health/test_ledger_health.py @@ -3,23 +3,20 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.utils import run_ledger_health_checks +from erpnext.tests.utils import ERPNextTestSuite -class TestLedgerHealth(AccountsTestMixin, IntegrationTestCase): +class TestLedgerHealth(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.configure_monitoring_tool() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def configure_monitoring_tool(self): monitor_settings = frappe.get_doc("Ledger Health Monitor") monitor_settings.enable_health_monitor = True diff --git a/erpnext/accounts/doctype/ledger_health_monitor/test_ledger_health_monitor.py b/erpnext/accounts/doctype/ledger_health_monitor/test_ledger_health_monitor.py index bc2193f10ce..191a06510b9 100644 --- a/erpnext/accounts/doctype/ledger_health_monitor/test_ledger_health_monitor.py +++ b/erpnext/accounts/doctype/ledger_health_monitor/test_ledger_health_monitor.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestLedgerHealthMonitor(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestLedgerHealthMonitor(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/ledger_merge/test_ledger_merge.py b/erpnext/accounts/doctype/ledger_merge/test_ledger_merge.py index fd5001f97bc..28822dff52d 100644 --- a/erpnext/accounts/doctype/ledger_merge/test_ledger_merge.py +++ b/erpnext/accounts/doctype/ledger_merge/test_ledger_merge.py @@ -3,12 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.ledger_merge.ledger_merge import start_merge +from erpnext.tests.utils import ERPNextTestSuite -class TestLedgerMerge(IntegrationTestCase): +class TestLedgerMerge(ERPNextTestSuite): def test_merge_success(self): if not frappe.db.exists("Account", "Indirect Expenses - _TC"): acc = frappe.new_doc("Account") @@ -101,16 +101,3 @@ class TestLedgerMerge(IntegrationTestCase): self.assertFalse(frappe.db.exists("Account", "Indirect Test Income - _TC")) self.assertTrue(frappe.db.exists("Account", "Administrative Test Income - _TC")) - - def tearDown(self): - for entry in frappe.db.get_all("Ledger Merge"): - frappe.delete_doc("Ledger Merge", entry.name) - - test_accounts = [ - "Indirect Test Expenses - _TC", - "Administrative Test Expenses - _TC", - "Indirect Test Income - _TC", - "Administrative Test Income - _TC", - ] - for account in test_accounts: - frappe.delete_doc_if_exists("Account", account) diff --git a/erpnext/accounts/doctype/loyalty_point_entry/test_loyalty_point_entry.py b/erpnext/accounts/doctype/loyalty_point_entry/test_loyalty_point_entry.py index c085e6caf5e..090c905c013 100644 --- a/erpnext/accounts/doctype/loyalty_point_entry/test_loyalty_point_entry.py +++ b/erpnext/accounts/doctype/loyalty_point_entry/test_loyalty_point_entry.py @@ -3,31 +3,20 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today -from erpnext.accounts.doctype.loyalty_program.test_loyalty_program import create_records from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice +from erpnext.tests.utils import ERPNextTestSuite -class TestLoyaltyPointEntry(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestLoyaltyPointEntry(ERPNextTestSuite): + def setUp(self): # Create test records - create_records() - cls.loyalty_program_name = "Test Single Loyalty" - cls.customer_name = "Test Loyalty Customer" - customer = frappe.get_doc("Customer", cls.customer_name) - customer.db_set("loyalty_program", cls.loyalty_program_name) - - @classmethod - def tearDownClass(cls): - # Delete all Loyalty Point Entries - frappe.db.sql("DELETE FROM `tabLoyalty Point Entry` WHERE customer = %s", cls.customer_name) - frappe.db.sql("DELETE FROM `tabSales Invoice` WHERE customer = %s", cls.customer_name) - frappe.db.commit() - # cls.customer.delete() + self.loyalty_program_name = "Test Single Loyalty" + self.customer_name = "Test Loyalty Customer" + customer = frappe.get_doc("Customer", self.customer_name) + customer.loyalty_program = self.loyalty_program_name + customer.save() def create_test_invoice(self, redeem=None): if redeem: @@ -69,9 +58,10 @@ class TestLoyaltyPointEntry(IntegrationTestCase): self.assertEqual(entry.discretionary_reason, "Customer Appreciation") def test_redeem_loyalty_points(self): - self.create_test_invoice(redeem=10) + self.create_test_invoice() + self.create_test_invoice(redeem=7) doc = frappe.get_last_doc("Loyalty Point Entry") - self.assertEqual(doc.loyalty_points, -10) + self.assertEqual(doc.loyalty_points, -7) # Check balance balance = frappe.db.sql( @@ -83,4 +73,4 @@ class TestLoyaltyPointEntry(IntegrationTestCase): (self.customer_name,), )[0][0] - self.assertEqual(balance, 75) # 85 added, 10 redeemed + self.assertEqual(balance, 3) # 10 added, 7 redeemed diff --git a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py index 604e95df6b8..28731e4db51 100644 --- a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py +++ b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import cint, flt, getdate, today from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( @@ -11,15 +10,10 @@ from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( get_loyalty_program_details_with_points, ) from erpnext.accounts.party import get_dashboard_info +from erpnext.tests.utils import ERPNextTestSuite -class TestLoyaltyProgram(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - # create relevant item, customer, loyalty program, etc - create_records() - +class TestLoyaltyProgram(ERPNextTestSuite): def test_loyalty_points_earned_single_tier(self): frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") # create a new sales invoice @@ -323,96 +317,3 @@ def create_sales_invoice_record(qty=1): ], } ) - - -def create_records(): - # create a new loyalty Account - if not frappe.db.exists("Account", "Loyalty - _TC"): - frappe.get_doc( - { - "doctype": "Account", - "account_name": "Loyalty", - "parent_account": "Direct Expenses - _TC", - "company": "_Test Company", - "is_group": 0, - "account_type": "Expense Account", - } - ).insert() - - # create a new loyalty program Single tier - if not frappe.db.exists("Loyalty Program", "Test Single Loyalty"): - frappe.get_doc( - { - "doctype": "Loyalty Program", - "loyalty_program_name": "Test Single Loyalty", - "auto_opt_in": 1, - "from_date": today(), - "loyalty_program_type": "Single Tier Program", - "conversion_factor": 1, - "expiry_duration": 10, - "company": "_Test Company", - "cost_center": "Main - _TC", - "expense_account": "Loyalty - _TC", - "collection_rules": [{"tier_name": "Bronce", "collection_factor": 1000, "min_spent": 0}], - } - ).insert() - - # create a new customer - if not frappe.db.exists("Customer", "Test Loyalty Customer"): - frappe.get_doc( - { - "customer_group": "_Test Customer Group", - "customer_name": "Test Loyalty Customer", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory", - } - ).insert() - - # create a new loyalty program Multiple tier - if not frappe.db.exists("Loyalty Program", "Test Multiple Loyalty"): - frappe.get_doc( - { - "doctype": "Loyalty Program", - "loyalty_program_name": "Test Multiple Loyalty", - "auto_opt_in": 1, - "from_date": today(), - "loyalty_program_type": "Multiple Tier Program", - "conversion_factor": 1, - "expiry_duration": 10, - "company": "_Test Company", - "cost_center": "Main - _TC", - "expense_account": "Loyalty - _TC", - "collection_rules": [ - {"tier_name": "Bronze", "collection_factor": 1000, "min_spent": 0}, - {"tier_name": "Silver", "collection_factor": 1000, "min_spent": 10000}, - {"tier_name": "Gold", "collection_factor": 1000, "min_spent": 19000}, - ], - } - ).insert() - - # create an item - if not frappe.db.exists("Item", "Loyal Item"): - frappe.get_doc( - { - "doctype": "Item", - "item_code": "Loyal Item", - "item_name": "Loyal Item", - "item_group": "All Item Groups", - "company": "_Test Company", - "is_stock_item": 1, - "opening_stock": 100, - "valuation_rate": 10000, - } - ).insert() - - # create item price - if not frappe.db.exists("Item Price", {"price_list": "Standard Selling", "item_code": "Loyal Item"}): - frappe.get_doc( - { - "doctype": "Item Price", - "price_list": "Standard Selling", - "item_code": "Loyal Item", - "price_list_rate": 10000, - } - ).insert() diff --git a/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py b/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py index ee2a594f8f0..2f485f10f81 100644 --- a/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py +++ b/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestModeofPayment(IntegrationTestCase): +class TestModeofPayment(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/monthly_distribution/test_monthly_distribution.py b/erpnext/accounts/doctype/monthly_distribution/test_monthly_distribution.py index 06c153940a8..30d35527136 100644 --- a/erpnext/accounts/doctype/monthly_distribution/test_monthly_distribution.py +++ b/erpnext/accounts/doctype/monthly_distribution/test_monthly_distribution.py @@ -2,9 +2,8 @@ # See license.txt import unittest -import frappe -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestMonthlyDistribution(IntegrationTestCase): +class TestMonthlyDistribution(ERPNextTestSuite): pass 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 730d5db8ae6..3d57c781983 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 @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( create_dimension, @@ -11,17 +10,14 @@ from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension imp from erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool import ( get_temporary_opening_account, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Customer", "Supplier", "Accounting Dimension"] +from erpnext.tests.utils import ERPNextTestSuite -class TestOpeningInvoiceCreationTool(IntegrationTestCase): - @classmethod - def setUpClass(cls): +class TestOpeningInvoiceCreationTool(ERPNextTestSuite): + def setUp(self): if not frappe.db.exists("Company", "_Test Opening Invoice Company"): make_company() create_dimension() - return super().setUpClass() def make_invoices( self, @@ -149,9 +145,6 @@ class TestOpeningInvoiceCreationTool(IntegrationTestCase): } self.check_expected_values(invoices, expected_value, invoice_type="Sales") - def tearDown(self): - disable_dimension() - def get_opening_invoice_creation_dict(**args): party = "Customer" if args.get("invoice_type", "Sales") == "Sales" else "Supplier" diff --git a/erpnext/accounts/doctype/party_link/test_party_link.py b/erpnext/accounts/doctype/party_link/test_party_link.py index 1c93c65e3c3..c1f59a2209a 100644 --- a/erpnext/accounts/doctype/party_link/test_party_link.py +++ b/erpnext/accounts/doctype/party_link/test_party_link.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPartyLink(IntegrationTestCase): +class TestPartyLink(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index f6c240c0714..12f5276fbfb 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -4,7 +4,6 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, nowdate from erpnext.accounts.doctype.account.test_account import create_account @@ -24,14 +23,10 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( ) from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.setup.doctype.employee.test_employee import make_employee - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Currency Exchange"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentEntry(IntegrationTestCase): - def tearDown(self): - frappe.db.rollback() - +class TestPaymentEntry(ERPNextTestSuite): def get_journals_for(self, voucher_type: str, voucher_no: str) -> list: journals = [] if voucher_type and voucher_no: @@ -427,7 +422,7 @@ class TestPaymentEntry(IntegrationTestCase): self.assertEqual(si.payment_schedule[0].outstanding, 0) self.assertEqual(si.payment_schedule[0].discounted_amount, 50) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "allow_multi_currency_invoices_against_single_party_account": 1, @@ -645,6 +640,7 @@ class TestPaymentEntry(IntegrationTestCase): def test_payment_entry_retrieves_last_exchange_rate(self): from erpnext.setup.doctype.currency_exchange.test_currency_exchange import save_new_records + self.load_test_records("Currency Exchange") save_new_records(self.globalTestRecords["Currency Exchange"]) pe = frappe.new_doc("Payment Entry") @@ -982,6 +978,7 @@ class TestPaymentEntry(IntegrationTestCase): def test_gl_of_multi_currency_payment_transaction(self): from erpnext.setup.doctype.currency_exchange.test_currency_exchange import save_new_records + self.load_test_records("Currency Exchange") save_new_records(self.globalTestRecords["Currency Exchange"]) paid_from = create_account( parent_account="Current Liabilities - _TC", @@ -1158,7 +1155,7 @@ class TestPaymentEntry(IntegrationTestCase): } self.assertDictEqual(ref_details, expected_response) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "unlink_payment_on_cancellation_of_invoice": 1, @@ -1253,7 +1250,7 @@ class TestPaymentEntry(IntegrationTestCase): si3.cancel() si3.delete() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "unlink_payment_on_cancellation_of_invoice": 1, @@ -1949,7 +1946,7 @@ class TestPaymentEntry(IntegrationTestCase): # 'Is Opening' should always be 'No' for normal advance payments self.assertEqual(gl_with_opening_set, []) - @IntegrationTestCase.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) def test_delete_linked_exchange_gain_loss_journal(self): from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( diff --git a/erpnext/accounts/doctype/payment_gateway_account/test_payment_gateway_account.py b/erpnext/accounts/doctype/payment_gateway_account/test_payment_gateway_account.py index 030844e7148..ad4373edd75 100644 --- a/erpnext/accounts/doctype/payment_gateway_account/test_payment_gateway_account.py +++ b/erpnext/accounts/doctype/payment_gateway_account/test_payment_gateway_account.py @@ -2,10 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase - -IGNORE_TEST_RECORD_DEPENDENCIES = ["Payment Gateway"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentGatewayAccount(IntegrationTestCase): +class TestPaymentGatewayAccount(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py b/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py index 1de103764a4..c2528040e98 100644 --- a/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py +++ b/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py @@ -3,7 +3,6 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -11,9 +10,10 @@ from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_pay from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.stock.doctype.item.test_item import create_item +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentLedgerEntry(IntegrationTestCase): +class TestPaymentLedgerEntry(ERPNextTestSuite): def setUp(self): self.ple = qb.DocType("Payment Ledger Entry") self.create_company() @@ -21,9 +21,6 @@ class TestPaymentLedgerEntry(IntegrationTestCase): self.create_customer() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_company(self): company_name = "_Test Payment Ledger" company = None @@ -445,7 +442,7 @@ class TestPaymentLedgerEntry(IntegrationTestCase): self.assertEqual(pl_entries_for_crnote[0], expected_values[0]) self.assertEqual(pl_entries_for_crnote[1], expected_values[1]) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1, "delete_linked_ledger_entries": 1}, ) @@ -474,7 +471,7 @@ class TestPaymentLedgerEntry(IntegrationTestCase): si.delete() self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, si.doctype, si.name) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1, "delete_linked_ledger_entries": 1}, ) @@ -507,7 +504,7 @@ class TestPaymentLedgerEntry(IntegrationTestCase): si.delete() self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, si.doctype, si.name) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "unlink_payment_on_cancellation_of_invoice": 1, diff --git a/erpnext/accounts/doctype/payment_order/test_payment_order.py b/erpnext/accounts/doctype/payment_order/test_payment_order.py index f12491fdf15..b11500cfd20 100644 --- a/erpnext/accounts/doctype/payment_order/test_payment_order.py +++ b/erpnext/accounts/doctype/payment_order/test_payment_order.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import ( @@ -15,9 +14,10 @@ from erpnext.accounts.doctype.payment_entry.payment_entry import ( make_payment_order, ) from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentOrder(IntegrationTestCase): +class TestPaymentOrder(ERPNextTestSuite): def setUp(self): # generate and use a uniq hash identifier for 'Bank Account' and it's linked GL 'Account' to avoid validation error uniq_identifier = frappe.generate_hash(length=10) @@ -26,9 +26,6 @@ class TestPaymentOrder(IntegrationTestCase): gl_account=self.gl_account, bank_account_name="Checking Account " + uniq_identifier ) - def tearDown(self): - frappe.db.rollback() - def test_payment_order_creation_against_payment_entry(self): purchase_invoice = make_purchase_invoice() payment_entry = get_payment_entry( diff --git a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py index 3682e7c63a9..1bbf228d73a 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py @@ -4,7 +4,6 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_years, flt, getdate, nowdate, today from frappe.utils.data import getdate as convert_to_date @@ -17,11 +16,10 @@ from erpnext.accounts.party import get_party_account from erpnext.accounts.utils import get_fiscal_year from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.stock.doctype.item.test_item import create_item - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentReconciliation(IntegrationTestCase): +class TestPaymentReconciliation(ERPNextTestSuite): def setUp(self): self.create_company() self.create_item() @@ -30,9 +28,6 @@ class TestPaymentReconciliation(IntegrationTestCase): self.create_cost_center() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_company(self): company = None if frappe.db.exists("Company", "_Test Payment Reconciliation"): @@ -1235,7 +1230,7 @@ class TestPaymentReconciliation(IntegrationTestCase): payment_vouchers = [x.get("reference_name") for x in pr.get("payments")] self.assertCountEqual(payment_vouchers, [je2.name, pe2.name]) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "allow_multi_currency_invoices_against_single_party_account": 1, diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index 41375d9d9af..453a52518a7 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -7,7 +7,6 @@ import unittest from unittest.mock import patch import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, nowdate from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -18,8 +17,7 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.setup.utils import get_exchange_rate - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Currency Exchange", "Journal Entry", "Contact", "Address"] +from erpnext.tests.utils import ERPNextTestSuite PAYMENT_URL = "https://example.com/payment" @@ -64,7 +62,7 @@ payment_method = [ ] -class TestPaymentRequest(IntegrationTestCase): +class TestPaymentRequest(ERPNextTestSuite): def setUp(self): for payment_gateway in payment_gateways: if not frappe.db.get_value("Payment Gateway", payment_gateway["gateway"], "name"): @@ -101,9 +99,6 @@ class TestPaymentRequest(IntegrationTestCase): self._get_payment_gateway_controller = _get_payment_gateway_controller.start() self.addCleanup(_get_payment_gateway_controller.stop) - def tearDown(self): - frappe.db.rollback() - def test_payment_request_linkings(self): so_inr = make_sales_order(currency="INR", do_not_save=True) so_inr.disable_rounded_total = 1 @@ -504,7 +499,7 @@ class TestPaymentRequest(IntegrationTestCase): return_doc=1, ) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} ) def test_multiple_payment_if_partially_paid_for_multi_currency(self): @@ -622,7 +617,7 @@ class TestPaymentRequest(IntegrationTestCase): self.assertEqual(pr.outstanding_amount, 0) self.assertEqual(pr.grand_total, 20000) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} ) def test_single_payment_with_payment_term_for_multi_currency(self): diff --git a/erpnext/accounts/doctype/payment_term/test_payment_term.py b/erpnext/accounts/doctype/payment_term/test_payment_term.py index 08f51cfb4e9..62129971c16 100644 --- a/erpnext/accounts/doctype/payment_term/test_payment_term.py +++ b/erpnext/accounts/doctype/payment_term/test_payment_term.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentTerm(IntegrationTestCase): +class TestPaymentTerm(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/payment_term/test_records.json b/erpnext/accounts/doctype/payment_term/test_records.json deleted file mode 100644 index ef6e0693b3c..00000000000 --- a/erpnext/accounts/doctype/payment_term/test_records.json +++ /dev/null @@ -1,34 +0,0 @@ -[ - { - "doctype":"Payment Term", - "due_date_based_on":"Day(s) after invoice date", - "payment_term_name":"_Test N30", - "description":"_Test Net 30 Days", - "invoice_portion":50, - "credit_days":30 - }, - { - "doctype":"Payment Term", - "due_date_based_on":"Day(s) after invoice date", - "payment_term_name":"_Test COD", - "description":"_Test Cash on Delivery", - "invoice_portion":50, - "credit_days":0 - }, - { - "doctype":"Payment Term", - "due_date_based_on":"Month(s) after the end of the invoice month", - "payment_term_name":"_Test EONM", - "description":"_Test End of Next Month", - "invoice_portion":100, - "credit_months":1 - }, - { - "doctype":"Payment Term", - "due_date_based_on":"Day(s) after invoice date", - "payment_term_name":"_Test N30 1", - "description":"_Test Net 30 Days", - "invoice_portion":100, - "credit_days":30 - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/payment_terms_template/test_payment_terms_template.py b/erpnext/accounts/doctype/payment_terms_template/test_payment_terms_template.py index fb0020f78ac..36c21f7ee78 100644 --- a/erpnext/accounts/doctype/payment_terms_template/test_payment_terms_template.py +++ b/erpnext/accounts/doctype/payment_terms_template/test_payment_terms_template.py @@ -3,13 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentTermsTemplate(IntegrationTestCase): - def tearDown(self): - frappe.delete_doc("Payment Terms Template", "_Test Payment Terms Template For Test", force=1) - +class TestPaymentTermsTemplate(ERPNextTestSuite): def test_create_template(self): template = frappe.get_doc( { diff --git a/erpnext/accounts/doctype/payment_terms_template/test_records.json b/erpnext/accounts/doctype/payment_terms_template/test_records.json deleted file mode 100644 index fea0b35c112..00000000000 --- a/erpnext/accounts/doctype/payment_terms_template/test_records.json +++ /dev/null @@ -1,60 +0,0 @@ -[ - { - "doctype":"Payment Terms Template", - "terms":[ - { - "doctype":"Payment Terms Template Detail", - "due_date_based_on":"Day(s) after invoice date", - "idx":1, - "description":"Cash on Delivery", - "invoice_portion":50, - "credit_days":0, - "credit_months":0, - "payment_term":"_Test COD" - }, - { - "doctype":"Payment Terms Template Detail", - "due_date_based_on":"Day(s) after invoice date", - "idx":2, - "description":"Net 30 Days ", - "invoice_portion":50, - "credit_days":30, - "credit_months":0, - "payment_term":"_Test N30" - } - ], - "template_name":"_Test Payment Term Template" - }, - { - "doctype":"Payment Terms Template", - "terms":[ - { - "doctype":"Payment Terms Template Detail", - "due_date_based_on":"Month(s) after the end of the invoice month", - "idx":1, - "description":"_Test End of Next Months", - "invoice_portion":100, - "credit_days":0, - "credit_months":1, - "payment_term":"_Test EONM" - } - ], - "template_name":"_Test Payment Term Template 1" - }, - { - "doctype":"Payment Terms Template", - "terms":[ - { - "doctype":"Payment Terms Template Detail", - "due_date_based_on":"Day(s) after invoice date", - "idx":1, - "description":"_Test Net Within 30 days", - "invoice_portion":100, - "credit_days":30, - "credit_months":0, - "payment_term":"_Test N30 1" - } - ], - "template_name":"_Test Payment Term Template 3" - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/pegged_currencies/test_pegged_currencies.py b/erpnext/accounts/doctype/pegged_currencies/test_pegged_currencies.py index 32bb3f34fd5..e695b11bcb5 100644 --- a/erpnext/accounts/doctype/pegged_currencies/test_pegged_currencies.py +++ b/erpnext/accounts/doctype/pegged_currencies/test_pegged_currencies.py @@ -2,28 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase, UnitTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class UnitTestPeggedCurrencies(UnitTestCase): - """ - Unit tests for PeggedCurrencies. - Use this class for testing individual functions and methods. - """ - - pass - - -class IntegrationTestPeggedCurrencies(IntegrationTestCase): - """ - Integration tests for PeggedCurrencies. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py index e9bc137fcd4..1fcff98a467 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py +++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py @@ -3,16 +3,16 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.finance_book.test_finance_book import create_finance_book from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.utils import get_fiscal_year +from erpnext.tests.utils import ERPNextTestSuite -class TestPeriodClosingVoucher(IntegrationTestCase): +class TestPeriodClosingVoucher(ERPNextTestSuite): def setUp(self): super().setUp() frappe.db.set_single_value("Accounts Settings", "use_legacy_controller_for_pcv", 1) @@ -391,6 +391,3 @@ def create_cost_center(cc_name): ) costcenter.insert(ignore_if_duplicate=True) return costcenter.name - - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Customer", "Cost Center"] 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 148a5a83030..af5f73a39ec 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 @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( create_dimension, @@ -22,26 +21,14 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle get_batch_from_bundle, ) from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSClosingEntry(IntegrationTestCase): - @classmethod - def setUpClass(cls): - frappe.db.sql("delete from `tabPOS Opening Entry`") - cls.enterClassContext(cls.change_settings("POS Settings", {"invoice_type": "POS Invoice"})) - - @classmethod - def tearDownClass(cls): - frappe.db.sql("delete from `tabPOS Opening Entry`") - +class TestPOSClosingEntry(ERPNextTestSuite): def setUp(self): - # Make stock available for POS Sales - frappe.db.sql("delete from `tabPOS Opening Entry`") + init_user_and_profile() make_stock_entry(target="_Test Warehouse - _TC", qty=2, basic_rate=100) - - def tearDown(self): - frappe.set_user("Administrator") - frappe.db.sql("delete from `tabPOS Profile`") + frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice") def test_pos_closing_entry(self): test_user, pos_profile = init_user_and_profile() @@ -58,6 +45,7 @@ class TestPOSClosingEntry(IntegrationTestCase): pos_inv2.submit() pcv_doc = make_closing_entry_from_opening(opening_entry) + pcv_doc.flags.in_test = True payment = pcv_doc.payment_reconciliation[0] self.assertEqual(payment.mode_of_payment, "Cash") @@ -66,6 +54,7 @@ class TestPOSClosingEntry(IntegrationTestCase): if d.mode_of_payment == "Cash": d.closing_amount = 6700 + pcv_doc.flags.in_test = True pcv_doc.submit() self.assertEqual(pcv_doc.total_quantity, 2) @@ -84,6 +73,7 @@ class TestPOSClosingEntry(IntegrationTestCase): pos_inv.submit() pcv_doc = make_closing_entry_from_opening(opening_entry) + pcv_doc.flags.in_test = True pcv_doc.submit() self.assertTrue(pcv_doc.name) @@ -116,6 +106,7 @@ class TestPOSClosingEntry(IntegrationTestCase): pos_return.submit() pcv_doc = make_closing_entry_from_opening(opening_entry) + pcv_doc.flags.in_test = True pcv_doc.submit() opening_entry = create_opening_entry(pos_profile, test_user.name) @@ -145,6 +136,7 @@ class TestPOSClosingEntry(IntegrationTestCase): if d.mode_of_payment == "Cash": d.closing_amount = 6700 + pcv_doc.flags.in_test = True pcv_doc.submit() pos_inv1.load_from_db() @@ -198,6 +190,7 @@ class TestPOSClosingEntry(IntegrationTestCase): pcv_doc = make_closing_entry_from_opening(opening_entry) # will assert coz the new mandatory accounting dimension bank is not set in POS Profile + pcv_doc.flags.in_test = True self.assertRaises(frappe.ValidationError, pcv_doc.submit) accounting_dimension_department = frappe.get_doc( @@ -265,6 +258,7 @@ class TestPOSClosingEntry(IntegrationTestCase): self.assertEqual(batch_qty_with_pos, 0.0) pcv_doc = make_closing_entry_from_opening(opening_entry) + pcv_doc.flags.in_test = True pcv_doc.submit() piv_merge = frappe.db.get_value("POS Invoice Merge Log", {"pos_closing_entry": pcv_doc.name}, "name") @@ -288,6 +282,7 @@ class TestPOSClosingEntry(IntegrationTestCase): frappe.flags.print_message = True pcv_doc.reload() + pcv_doc.flags.in_test = True pcv_doc.cancel() batch_qty_with_pos = get_batch_qty(batch_no, "_Test Warehouse - _TC", item_code) @@ -302,7 +297,7 @@ class TestPOSClosingEntry(IntegrationTestCase): batch_qty_with_pos = get_batch_qty(batch_no, "_Test Warehouse - _TC", item_code) self.assertEqual(batch_qty_with_pos, 10.0) - @IntegrationTestCase.change_settings("POS Settings", {"invoice_type": "Sales Invoice"}) + @ERPNextTestSuite.change_settings("POS Settings", {"invoice_type": "Sales Invoice"}) def test_closing_entries_with_sales_invoice(self): test_user, pos_profile = init_user_and_profile() opening_entry = create_opening_entry(pos_profile, test_user.name) @@ -330,6 +325,7 @@ class TestPOSClosingEntry(IntegrationTestCase): if d.mode_of_payment == "Cash": d.closing_amount = 1500 + pcv_doc.flags.in_test = True pcv_doc.submit() self.assertEqual(pcv_doc.total_quantity, 15) @@ -473,7 +469,7 @@ def init_user_and_profile(**args): user = "test@example.com" test_user = frappe.get_doc("User", user) - roles = ("Accounts Manager", "Accounts User", "Sales Manager") + roles = ("Accounts Manager", "Accounts User", "Sales Manager", "Stock User", "Item Manager") test_user.add_roles(*roles) frappe.set_user(user) diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py index 1a94e1c9990..8cf4d0cb90f 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -5,7 +5,6 @@ import unittest import frappe from frappe import _ -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.mode_of_payment.test_mode_of_payment import ( set_default_account_for_mode_of_payment, @@ -22,37 +21,34 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle make_serial_batch_bundle, ) from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSInvoice(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - cls.enterClassContext(cls.change_settings("POS Settings", invoice_type="POS Invoice")) - make_stock_entry(target="_Test Warehouse - _TC", item_code="_Test Item", qty=800, basic_rate=100) - frappe.db.sql("delete from `tabTax Rule`") - +class POSInvoiceTestMixin(ERPNextTestSuite): + def setUp(self): from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile - from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import create_opening_entry - cls.test_user, cls.pos_profile = init_user_and_profile() - cls.opening_entry = create_opening_entry(cls.pos_profile, cls.test_user.name) - mode_of_payment = frappe.get_doc("Mode of Payment", "Bank Draft") - set_default_account_for_mode_of_payment(mode_of_payment, "_Test Company", "_Test Bank - _TC") + self.load_test_records("Stock Entry") + self.test_user, self.pos_profile = init_user_and_profile() - @classmethod - def tearDownClass(cls): - frappe.db.sql("delete from `tabPOS Invoice`") - opening_entry_doc = frappe.get_doc("POS Opening Entry", cls.opening_entry.name) - opening_entry_doc.cancel() - - def tearDown(self): if frappe.session.user != "Administrator": frappe.set_user("Administrator") - if frappe.db.get_single_value("Selling Settings", "validate_selling_price"): - frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) + frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice") + make_stock_entry(target="_Test Warehouse - _TC", item_code="_Test Item", qty=800, basic_rate=100) + frappe.db.sql("delete from `tabTax Rule`") + + mode_of_payment = frappe.get_doc("Mode of Payment", "Bank Draft") + set_default_account_for_mode_of_payment(mode_of_payment, "_Test Company", "_Test Bank - _TC") + + +class TestPOSInvoice(POSInvoiceTestMixin): + def setUp(self): + super().setUp() + from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import create_opening_entry + + self.opening_entry = create_opening_entry(self.pos_profile, self.test_user.name) def test_timestamp_change(self): w = create_pos_invoice(do_not_save=1) @@ -642,9 +638,7 @@ class TestPOSInvoice(IntegrationTestCase): from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( get_loyalty_program_details_with_points, ) - from erpnext.accounts.doctype.loyalty_program.test_loyalty_program import create_records - create_records() frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") before_lp_details = get_loyalty_program_details_with_points( "Test Loyalty Customer", company="_Test Company", loyalty_program="Test Single Loyalty" @@ -681,6 +675,7 @@ class TestPOSInvoice(IntegrationTestCase): get_loyalty_program_details_with_points, ) + frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") # add 10 loyalty points pos_inv = create_pos_invoice(customer="Test Loyalty Customer", rate=10000, do_not_save=1) pos_inv.append( @@ -710,134 +705,6 @@ class TestPOSInvoice(IntegrationTestCase): ) self.assertEqual(after_redeem_lp_details.loyalty_points, 9) - def test_merging_into_sales_invoice_with_discount(self): - from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( - init_user_and_profile, - ) - from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( - consolidate_pos_invoices, - ) - - frappe.db.sql("delete from `tabPOS Invoice`") - test_user, pos_profile = init_user_and_profile() - pos_inv = create_pos_invoice(rate=300, additional_discount_percentage=10, do_not_submit=1) - pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 270}) - pos_inv.save() - pos_inv.submit() - - pos_inv2 = create_pos_invoice(rate=3200, do_not_submit=1) - pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 3200}) - pos_inv2.save() - pos_inv2.submit() - - consolidate_pos_invoices() - - pos_inv.load_from_db() - rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") - self.assertEqual(rounded_total, 3470) - - def test_merging_into_sales_invoice_with_discount_and_inclusive_tax(self): - from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( - init_user_and_profile, - ) - from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( - consolidate_pos_invoices, - ) - - frappe.db.sql("delete from `tabPOS Invoice`") - test_user, pos_profile = init_user_and_profile() - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) - pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 300}) - pos_inv.append( - "taxes", - { - "charge_type": "On Net Total", - "account_head": "_Test Account Service Tax - _TC", - "cost_center": "_Test Cost Center - _TC", - "description": "Service Tax", - "rate": 14, - "included_in_print_rate": 1, - }, - ) - pos_inv.save() - pos_inv.submit() - - pos_inv2 = create_pos_invoice(rate=300, qty=2, do_not_submit=1) - pos_inv2.additional_discount_percentage = 10 - pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 540}) - pos_inv2.append( - "taxes", - { - "charge_type": "On Net Total", - "account_head": "_Test Account Service Tax - _TC", - "cost_center": "_Test Cost Center - _TC", - "description": "Service Tax", - "rate": 14, - "included_in_print_rate": 1, - }, - ) - pos_inv2.save() - pos_inv2.submit() - - consolidate_pos_invoices() - - pos_inv.load_from_db() - rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") - self.assertEqual(rounded_total, 840) - - def test_merging_with_validate_selling_price(self): - from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( - init_user_and_profile, - ) - from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( - consolidate_pos_invoices, - ) - - if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"): - frappe.db.set_single_value("Selling Settings", "validate_selling_price", 1) - - item = "Test Selling Price Validation" - make_item(item, {"is_stock_item": 1}) - make_purchase_receipt(item_code=item, warehouse="_Test Warehouse - _TC", qty=1, rate=300) - frappe.db.sql("delete from `tabPOS Invoice`") - test_user, pos_profile = init_user_and_profile() - pos_inv = create_pos_invoice(item=item, rate=300, do_not_submit=1) - pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 300}) - pos_inv.append( - "taxes", - { - "charge_type": "On Net Total", - "account_head": "_Test Account Service Tax - _TC", - "cost_center": "_Test Cost Center - _TC", - "description": "Service Tax", - "rate": 14, - "included_in_print_rate": 1, - }, - ) - self.assertRaises(frappe.ValidationError, pos_inv.submit) - - pos_inv2 = create_pos_invoice(item=item, rate=400, do_not_submit=1) - pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 400}) - pos_inv2.append( - "taxes", - { - "charge_type": "On Net Total", - "account_head": "_Test Account Service Tax - _TC", - "cost_center": "_Test Cost Center - _TC", - "description": "Service Tax", - "rate": 14, - "included_in_print_rate": 1, - }, - ) - pos_inv2.save() - pos_inv2.submit() - - consolidate_pos_invoices() - - pos_inv2.load_from_db() - rounded_total = frappe.db.get_value("Sales Invoice", pos_inv2.consolidated_invoice, "rounded_total") - self.assertEqual(rounded_total, 400) - def test_pos_batch_reservation(self): from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import ( get_auto_batch_nos, @@ -1004,40 +871,39 @@ class TestPOSInvoice(IntegrationTestCase): def test_ignore_pricing_rule(self): from erpnext.accounts.doctype.pricing_rule.test_pricing_rule import make_pricing_rule - item_price = frappe.get_doc( - { - "doctype": "Item Price", - "item_code": "_Test Item", - "price_list": "_Test Price List", - "price_list_rate": "450", - } - ) - item_price.insert() + if not frappe.db.exists( + "Item Price", + {"item_code": "_Test Item", "price_list": "_Test Price List", "price_list_rate": "450"}, + ): + item_price = frappe.get_doc( + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Price List", + "price_list_rate": "450", + } + ) + item_price.insert() + pr = make_pricing_rule(selling=1, priority=5, discount_percentage=10) pr.save() - try: - pos_inv = create_pos_invoice(qty=1, do_not_submit=1) - pos_inv.items[0].rate = 300 - pos_inv.save() - self.assertEqual(pos_inv.items[0].discount_percentage, 10) - # rate shouldn't change - self.assertEqual(pos_inv.items[0].rate, 405) + pos_inv = create_pos_invoice(qty=1, do_not_submit=1) + pos_inv.items[0].rate = 300 + pos_inv.save() + self.assertEqual(pos_inv.items[0].discount_percentage, 10) + # rate shouldn't change + self.assertEqual(pos_inv.items[0].rate, 405) - pos_inv.ignore_pricing_rule = 1 - pos_inv.save() - self.assertEqual(pos_inv.ignore_pricing_rule, 1) - # rate should reset since pricing rules are ignored - self.assertEqual(pos_inv.items[0].rate, 450) + pos_inv.ignore_pricing_rule = 1 + pos_inv.save() + self.assertEqual(pos_inv.ignore_pricing_rule, 1) + # rate should reset since pricing rules are ignored + self.assertEqual(pos_inv.items[0].rate, 450) - pos_inv.items[0].rate = 300 - pos_inv.save() - self.assertEqual(pos_inv.items[0].rate, 300) - - finally: - item_price.delete() - pos_inv.delete() - pr.delete() + pos_inv.items[0].rate = 300 + pos_inv.save() + self.assertEqual(pos_inv.items[0].rate, 300) def test_delivered_serial_no_case(self): from erpnext.accounts.doctype.pos_invoice_merge_log.test_pos_invoice_merge_log import ( @@ -1046,32 +912,26 @@ class TestPOSInvoice(IntegrationTestCase): from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item - frappe.db.savepoint("before_test_delivered_serial_no_case") - try: - se = make_serialized_item(self) - serial_no = get_serial_nos_from_bundle(se.get("items")[0].serial_and_batch_bundle)[0] + se = make_serialized_item(self) + serial_no = get_serial_nos_from_bundle(se.get("items")[0].serial_and_batch_bundle)[0] - dn = create_delivery_note(item_code="_Test Serialized Item With Series", serial_no=[serial_no]) - delivered_serial_no = get_serial_nos_from_bundle(dn.get("items")[0].serial_and_batch_bundle)[0] + dn = create_delivery_note(item_code="_Test Serialized Item With Series", serial_no=[serial_no]) + delivered_serial_no = get_serial_nos_from_bundle(dn.get("items")[0].serial_and_batch_bundle)[0] - self.assertEqual(serial_no, delivered_serial_no) + self.assertEqual(serial_no, delivered_serial_no) - init_user_and_profile() + init_user_and_profile() - pos_inv = create_pos_invoice( - item_code="_Test Serialized Item With Series", - serial_no=[serial_no], - qty=1, - rate=100, - do_not_submit=True, - ignore_sabb_validation=True, - ) + pos_inv = create_pos_invoice( + item_code="_Test Serialized Item With Series", + serial_no=[serial_no], + qty=1, + rate=100, + do_not_submit=True, + ignore_sabb_validation=True, + ) - self.assertRaises(frappe.ValidationError, pos_inv.submit) - - finally: - frappe.db.rollback(save_point="before_test_delivered_serial_no_case") - frappe.set_user("Administrator") + self.assertRaises(frappe.ValidationError, pos_inv.submit) def test_bundle_stock_availability_validation(self): from erpnext.accounts.doctype.pos_invoice.pos_invoice import ProductBundleStockValidationError diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice_merge.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice_merge.py new file mode 100644 index 00000000000..5c490d303be --- /dev/null +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice_merge.py @@ -0,0 +1,164 @@ +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +import frappe + +from erpnext.accounts.doctype.pos_invoice.test_pos_invoice import POSInvoiceTestMixin, create_pos_invoice +from erpnext.stock.doctype.item.test_item import make_item +from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite + + +class TestPOSInvoiceMerging(POSInvoiceTestMixin): + def clear_pos_data(self): + frappe.db.sql("delete from `tabPOS Opening Entry`;") + frappe.db.sql("delete from `tabPOS Closing Entry`;") + frappe.db.sql("delete from `tabPOS Invoice`;") + + def setUp(self): + self.clear_pos_data() + super().setUp() + + from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import create_opening_entry + + self.opening_entry = create_opening_entry(self.pos_profile, self.test_user.name) + + def test_merging_into_sales_invoice_with_discount(self): + from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import ( + make_closing_entry_from_opening, + ) + from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( + init_user_and_profile, + ) + from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( + consolidate_pos_invoices, + ) + + frappe.db.sql("delete from `tabPOS Invoice`") + test_user, pos_profile = init_user_and_profile() + pos_inv = create_pos_invoice(rate=300, additional_discount_percentage=10, do_not_submit=1) + pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 270}) + pos_inv.save() + pos_inv.submit() + + pos_inv2 = create_pos_invoice(rate=3200, do_not_submit=1) + pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 3200}) + pos_inv2.save() + pos_inv2.submit() + + closing_entry = make_closing_entry_from_opening(self.opening_entry) + consolidate_pos_invoices(closing_entry=closing_entry) # does DB commit + + pos_inv.load_from_db() + rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") + self.assertEqual(rounded_total, 3470) + + def test_merging_into_sales_invoice_with_discount_and_inclusive_tax(self): + from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import ( + make_closing_entry_from_opening, + ) + from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( + init_user_and_profile, + ) + from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( + consolidate_pos_invoices, + ) + + frappe.db.sql("delete from `tabPOS Invoice`") + test_user, pos_profile = init_user_and_profile() + pos_inv = create_pos_invoice(rate=300, do_not_submit=1) + pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 300}) + pos_inv.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "_Test Account Service Tax - _TC", + "cost_center": "_Test Cost Center - _TC", + "description": "Service Tax", + "rate": 14, + "included_in_print_rate": 1, + }, + ) + pos_inv.save() + pos_inv.submit() + + pos_inv2 = create_pos_invoice(rate=300, qty=2, do_not_submit=1) + pos_inv2.additional_discount_percentage = 10 + pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 540}) + pos_inv2.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "_Test Account Service Tax - _TC", + "cost_center": "_Test Cost Center - _TC", + "description": "Service Tax", + "rate": 14, + "included_in_print_rate": 1, + }, + ) + pos_inv2.save() + pos_inv2.submit() + + self.closing_entry = make_closing_entry_from_opening(self.opening_entry) + consolidate_pos_invoices(closing_entry=self.closing_entry) # does DB commit + + pos_inv.load_from_db() + rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") + self.assertEqual(rounded_total, 840) + + def test_merging_with_validate_selling_price(self): + from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import ( + make_closing_entry_from_opening, + ) + from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( + init_user_and_profile, + ) + from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( + consolidate_pos_invoices, + ) + + if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"): + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 1) + + item = "Test Selling Price Validation" + make_item(item, {"is_stock_item": 1}) + make_purchase_receipt(item_code=item, warehouse="_Test Warehouse - _TC", qty=1, rate=300) + frappe.db.sql("delete from `tabPOS Invoice`") + test_user, pos_profile = init_user_and_profile() + pos_inv = create_pos_invoice(item=item, rate=300, do_not_submit=1) + pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 300}) + pos_inv.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "_Test Account Service Tax - _TC", + "cost_center": "_Test Cost Center - _TC", + "description": "Service Tax", + "rate": 14, + "included_in_print_rate": 1, + }, + ) + self.assertRaises(frappe.ValidationError, pos_inv.submit) + + pos_inv2 = create_pos_invoice(item=item, rate=400, do_not_submit=1) + pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 400}) + pos_inv2.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "_Test Account Service Tax - _TC", + "cost_center": "_Test Cost Center - _TC", + "description": "Service Tax", + "rate": 14, + "included_in_print_rate": 1, + }, + ) + pos_inv2.save() + pos_inv2.submit() + + self.closing_entry = make_closing_entry_from_opening(self.opening_entry) + consolidate_pos_invoices(closing_entry=self.closing_entry) # does DB commit + + pos_inv2.load_from_db() + rounded_total = frappe.db.get_value("Sales Invoice", pos_inv2.consolidated_invoice, "rounded_total") + self.assertEqual(rounded_total, 400) diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index 0874955ec47..e41548b89f6 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -283,7 +283,7 @@ class POSInvoiceMergeLog(Document): base_rounding_adjustment += doc.base_rounding_adjustment base_rounded_total += doc.base_rounded_total - for d in doc.get("item_wise_tax_details"): + for d in doc.get("item_wise_tax_details") or []: row = frappe._dict( item=old_new_item_map[d.item_row], tax=old_new_tax_map[d.tax_row], @@ -572,7 +572,7 @@ def split_invoices(invoices): def create_merge_logs(invoice_by_customer, closing_entry=None): - try: + def merge_and_close(): for customer, invoices_acc_dim in invoice_by_customer.items(): for invoices in invoices_acc_dim.values(): for _invoices in split_invoices(invoices): @@ -594,25 +594,30 @@ def create_merge_logs(invoice_by_customer, closing_entry=None): closing_entry.db_set("error_message", "") closing_entry.update_opening_entry() - except Exception as e: - frappe.db.rollback() - message_log = frappe.message_log.pop() if frappe.message_log else str(e) - error_message = get_error_message(message_log) + if frappe.in_test: + merge_and_close() + else: + try: + merge_and_close() + except Exception as e: + frappe.db.rollback() + message_log = frappe.message_log.pop() if frappe.message_log else str(e) + error_message = get_error_message(message_log) - if closing_entry: - closing_entry.set_status(update=True, status="Failed") - if isinstance(error_message, list): - error_message = json.dumps(error_message) - closing_entry.db_set("error_message", error_message) - raise + if closing_entry: + closing_entry.set_status(update=True, status="Failed") + if isinstance(error_message, list): + error_message = json.dumps(error_message) + closing_entry.db_set("error_message", error_message) + raise - finally: - frappe.db.commit() - frappe.publish_realtime("closing_process_complete", user=frappe.session.user) + finally: + frappe.db.commit() + frappe.publish_realtime("closing_process_complete", user=frappe.session.user) def cancel_merge_logs(merge_logs, closing_entry=None): - try: + def merge_cancel_and_close(): for log in merge_logs: merge_log = frappe.get_doc("POS Invoice Merge Log", log) if merge_log.docstatus == 2: @@ -626,19 +631,24 @@ def cancel_merge_logs(merge_logs, closing_entry=None): closing_entry.db_set("error_message", "") closing_entry.update_opening_entry(for_cancel=True) - except Exception as e: - frappe.db.rollback() - message_log = frappe.message_log.pop() if frappe.message_log else str(e) - error_message = get_error_message(message_log) + if frappe.flags.in_test: + merge_cancel_and_close() + else: + try: + merge_cancel_and_close() + except Exception as e: + frappe.db.rollback() + message_log = frappe.message_log.pop() if frappe.message_log else str(e) + error_message = get_error_message(message_log) - if closing_entry: - closing_entry.set_status(update=True, status="Submitted") - closing_entry.db_set("error_message", error_message) - raise + if closing_entry: + closing_entry.set_status(update=True, status="Submitted") + closing_entry.db_set("error_message", error_message) + raise - finally: - frappe.db.commit() - frappe.publish_realtime("closing_process_complete", user=frappe.session.user) + finally: + frappe.db.commit() + frappe.publish_realtime("closing_process_complete", user=frappe.session.user) def enqueue_job(job, **kwargs): diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py index 5403b10476c..757860a76c6 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py @@ -3,7 +3,6 @@ import json import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.mode_of_payment.test_mode_of_payment import ( set_default_account_for_mode_of_payment, @@ -19,30 +18,25 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle get_serial_nos_from_bundle, ) from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSInvoiceMergeLog(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - frappe.db.sql("delete from `tabPOS Opening Entry`") - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - cls.enterClassContext(cls.change_settings("POS Settings", invoice_type="POS Invoice")) - mode_of_payment = frappe.get_doc("Mode of Payment", "Bank Draft") - set_default_account_for_mode_of_payment(mode_of_payment, "_Test Company", "_Test Bank - _TC") - +class TestPOSInvoiceMergeLog(ERPNextTestSuite): def setUp(self): - frappe.db.sql("delete from `tabPOS Invoice`") + mode_of_payment = frappe.get_doc("Mode of Payment", "Bank Draft") + self.test_user, self.pos_profile = init_user_and_profile() + self.opening_entry = create_opening_entry(self.pos_profile, self.test_user.name) - def tearDown(self): - frappe.set_user("Administrator") - frappe.db.sql("delete from `tabPOS Profile`") - frappe.db.sql("delete from `tabPOS Invoice`") + set_default_account_for_mode_of_payment(mode_of_payment, "_Test Company", "_Test Bank - _TC") + frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice") + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) + + def make_closing_entry(self): + closing_entry = make_closing_entry_from_opening(self.opening_entry) + closing_entry.insert().submit() + return closing_entry def test_consolidated_invoice_creation(self): - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.save() @@ -58,9 +52,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): pos_inv3.save() pos_inv3.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() pos_inv.load_from_db() self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) @@ -71,9 +63,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): self.assertFalse(pos_inv.consolidated_invoice == pos_inv3.consolidated_invoice) def test_consolidated_credit_note_creation(self): - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.save() @@ -98,9 +87,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): pos_inv_cn.paid_amount = -300 pos_inv_cn.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() pos_inv.load_from_db() self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) @@ -118,9 +105,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): self.assertEqual(consolidated_credit_note.payments[1].amount, -200) def test_consolidated_invoice_item_taxes(self): - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - inv = create_pos_invoice(qty=1, rate=100, do_not_save=True) inv.append( @@ -157,9 +141,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv2.save() inv2.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() @@ -207,9 +189,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): qty=10, ) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - inv = create_pos_invoice(qty=3, rate=10000, do_not_save=True) inv.append( "taxes", @@ -244,9 +223,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv2.insert() inv2.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) @@ -264,9 +241,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): qty=10, ) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - inv = create_pos_invoice(qty=6, rate=10000, do_not_save=True) inv.append( "taxes", @@ -306,16 +280,14 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv3.insert() inv3.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) self.assertNotEqual(consolidated_invoice.outstanding_amount, 800) self.assertEqual(consolidated_invoice.status, "Paid") - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "System Settings", {"number_format": "#,###.###", "currency_precision": 3, "float_precision": 3} ) def test_consolidation_round_off_error_3(self): @@ -325,8 +297,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): rate=8000, qty=10, ) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) item_rates = [69, 59, 29] for _i in [1, 2]: @@ -363,9 +333,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv.save() inv.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) @@ -383,9 +351,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): qty=10, ) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - inv = create_pos_invoice(qty=1, rate=69.5, do_not_save=True) inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 70}) inv.insert() @@ -396,9 +361,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv2.insert() inv2.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) @@ -415,14 +378,12 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): The second and third POS Invoice should be consolidated with a single Merge Log """ + self.load_test_records("Stock Entry") from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item se = make_serialized_item(self) serial_no = get_serial_nos_from_bundle(se.get("items")[0].serial_and_batch_bundle)[0] - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice( item_code="_Test Serialized Item With Series", serial_no=[serial_no], @@ -449,9 +410,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): pos_inv2.save() pos_inv2.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() pos_inv.load_from_db() pos_inv2.load_from_db() @@ -470,9 +429,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): create_cost_center(cost_center_name="_Test POS Cost Center 1", is_group=0) create_cost_center(cost_center_name="_Test POS Cost Center 2", is_group=0) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.cost_center = "_Test POS Cost Center 1 - _TC" @@ -491,9 +447,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): pos_inv3.save() pos_inv3.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() pos_inv.load_from_db() self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) @@ -512,17 +466,12 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): """ Test if the company is fetched from POS Closing Entry """ - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.save() pos_inv.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + closing_entry = self.make_closing_entry() self.assertTrue(frappe.db.exists("POS Invoice Merge Log", {"pos_closing_entry": closing_entry.name})) diff --git a/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py b/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py index 2b23f94932f..775a18901c8 100644 --- a/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py +++ b/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py @@ -4,35 +4,21 @@ import unittest import frappe from frappe.core.doctype.user_permission.test_user_permission import create_user -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.pos_invoice.test_pos_invoice import create_pos_invoice from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSOpeningEntry(IntegrationTestCase): - @classmethod - def setUpClass(cls): - frappe.db.sql("delete from `tabPOS Opening Entry`") - cls.enterClassContext(cls.change_settings("POS Settings", {"invoice_type": "POS Invoice"})) - - @classmethod - def tearDownClass(cls): - frappe.db.sql("delete from `tabPOS Opening Entry`") - +class TestPOSOpeningEntry(ERPNextTestSuite): def setUp(self): - # Make stock available for POS Sales - frappe.db.sql("delete from `tabPOS Opening Entry`") + frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice") make_stock_entry(target="_Test Warehouse - _TC", qty=2, basic_rate=100) from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile self.init_user_and_profile = init_user_and_profile - def tearDown(self): - frappe.set_user("Administrator") - frappe.db.sql("delete from `tabPOS Profile`") - def test_pos_opening_entry(self): test_user, pos_profile = self.init_user_and_profile() opening_entry = create_opening_entry(pos_profile, test_user.name) @@ -61,7 +47,9 @@ class TestPOSOpeningEntry(IntegrationTestCase): self.assertEqual(opening_entry_1.status, "Open") self.assertEqual(opening_entry_1.user, test_user.name) - cashier_user = create_user("test_cashier@example.com", "Accounts Manager", "Sales Manager") + cashier_user = create_user( + "test_cashier@example.com", "Accounts Manager", "Sales Manager", "Stock User", "System Manager" + ) frappe.set_user(cashier_user.name) pos_profile2 = make_pos_profile(name="_Test POS Profile 2") diff --git a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py index 1f02ba7e0a7..f547de9a97e 100644 --- a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py @@ -3,19 +3,18 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import cint from erpnext.accounts.doctype.pos_profile.pos_profile import ( get_child_nodes, ) from erpnext.stock.get_item_details import get_pos_profile - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSProfile(IntegrationTestCase): +class TestPOSProfile(ERPNextTestSuite): def test_pos_profile(self): + frappe.set_user("Administrator") make_pos_profile() pos_profile = get_pos_profile("_Test Company") or {} @@ -37,8 +36,6 @@ class TestPOSProfile(IntegrationTestCase): self.assertEqual(len(items), products_count[0][0]) self.assertEqual(len(customers), customers_count[0][0]) - frappe.db.sql("delete from `tabPOS Profile`") - def test_disabled_pos_profile_creation(self): make_pos_profile(name="_Test POS Profile 001", disabled=1) diff --git a/erpnext/accounts/doctype/pos_profile_user/test_pos_profile_user.py b/erpnext/accounts/doctype/pos_profile_user/test_pos_profile_user.py index b9747ff5799..2e3b68eeac5 100644 --- a/erpnext/accounts/doctype/pos_profile_user/test_pos_profile_user.py +++ b/erpnext/accounts/doctype/pos_profile_user/test_pos_profile_user.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSProfileUser(IntegrationTestCase): +class TestPOSProfileUser(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/pos_settings/test_pos_settings.py b/erpnext/accounts/doctype/pos_settings/test_pos_settings.py index 1ae75140714..9335efbed07 100644 --- a/erpnext/accounts/doctype/pos_settings/test_pos_settings.py +++ b/erpnext/accounts/doctype/pos_settings/test_pos_settings.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSSettings(IntegrationTestCase): +class TestPOSSettings(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index aa4cd12afc2..6ff1ed85d55 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -5,7 +5,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice @@ -13,17 +12,15 @@ from erpnext.controllers.sales_and_purchase_return import make_return_doc from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.get_item_details import get_item_details +from erpnext.tests.utils import ERPNextTestSuite -class TestPricingRule(IntegrationTestCase): +class TestPricingRule(ERPNextTestSuite): def setUp(self): delete_existing_pricing_rules() setup_pricing_rule_data() self.enterClassContext(self.change_settings("Selling Settings", validate_selling_price=0)) - def tearDown(self): - delete_existing_pricing_rules() - def test_pricing_rule_for_discount(self): from frappe import MandatoryError @@ -416,6 +413,7 @@ class TestPricingRule(IntegrationTestCase): self.assertEqual(item.discount_amount, 110) self.assertEqual(item.rate, 990) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_pricing_rule_for_product_discount_on_same_item(self): frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") test_record = { @@ -1191,6 +1189,7 @@ class TestPricingRule(IntegrationTestCase): si.delete() rule.delete() + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_pricing_rule_for_product_free_item_rounded_qty_and_recursion(self): frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") test_record = { @@ -1236,6 +1235,7 @@ class TestPricingRule(IntegrationTestCase): so.save() self.assertEqual(len(so.items), 1) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_pricing_rule_for_product_free_item_round_free_qty(self): frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") test_record = { @@ -1522,9 +1522,6 @@ class TestPricingRule(IntegrationTestCase): pi.cancel() -EXTRA_TEST_RECORD_DEPENDENCIES = ["UTM Campaign"] - - def make_pricing_rule(**args): args = frappe._dict(args) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index efbd0ce5fae..56ba6a040dc 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -243,8 +243,10 @@ def get_other_conditions(conditions, values, args): if group_condition: conditions += " and " + group_condition - date = args.get("transaction_date") or frappe.get_value( - args.get("doctype"), args.get("name"), "posting_date", ignore=True + date = ( + args.get("transaction_date") + or args.get("posting_date") + or frappe.get_value(args.get("doctype"), args.get("name"), "posting_date", ignore=True) ) if date: conditions += """ and %(transaction_date)s between ifnull(`tabPricing Rule`.valid_from, '2000-01-01') diff --git a/erpnext/accounts/doctype/process_deferred_accounting/test_process_deferred_accounting.py b/erpnext/accounts/doctype/process_deferred_accounting/test_process_deferred_accounting.py index 8d35b7fcf85..ef98a010511 100644 --- a/erpnext/accounts/doctype/process_deferred_accounting/test_process_deferred_accounting.py +++ b/erpnext/accounts/doctype/process_deferred_accounting/test_process_deferred_accounting.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( @@ -11,9 +10,10 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( create_sales_invoice, ) from erpnext.stock.doctype.item.test_item import create_item +from erpnext.tests.utils import ERPNextTestSuite -class TestProcessDeferredAccounting(IntegrationTestCase): +class TestProcessDeferredAccounting(ERPNextTestSuite): def test_creation_of_ledger_entry_on_submit(self): """test creation of gl entries on submission of document""" change_acc_settings(acc_frozen_till_date="2023-05-31", book_deferred_entries_based_on="Months") @@ -53,6 +53,7 @@ class TestProcessDeferredAccounting(IntegrationTestCase): start_date="2023-05-01", end_date="2023-06-30", type="Income", + company="_Test Company", ) process_deferred_accounting.insert() @@ -83,6 +84,7 @@ class TestProcessDeferredAccounting(IntegrationTestCase): start_date="2019-01-01", end_date="2019-01-31", type="Income", + company="_Test Company", ) pda.submit() pda.cancel() diff --git a/erpnext/accounts/doctype/process_payment_reconciliation/test_process_payment_reconciliation.py b/erpnext/accounts/doctype/process_payment_reconciliation/test_process_payment_reconciliation.py index d54ff6f902e..eff49ecadc5 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation/test_process_payment_reconciliation.py +++ b/erpnext/accounts/doctype/process_payment_reconciliation/test_process_payment_reconciliation.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestProcessPaymentReconciliation(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestProcessPaymentReconciliation(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/process_payment_reconciliation_log/test_process_payment_reconciliation_log.py b/erpnext/accounts/doctype/process_payment_reconciliation_log/test_process_payment_reconciliation_log.py index 66a4dca21e1..26c4b5a4a1c 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation_log/test_process_payment_reconciliation_log.py +++ b/erpnext/accounts/doctype/process_payment_reconciliation_log/test_process_payment_reconciliation_log.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestProcessPaymentReconciliationLog(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestProcessPaymentReconciliationLog(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/process_period_closing_voucher/test_process_period_closing_voucher.py b/erpnext/accounts/doctype/process_period_closing_voucher/test_process_period_closing_voucher.py index 17ce2c13b09..e695b11bcb5 100644 --- a/erpnext/accounts/doctype/process_period_closing_voucher/test_process_period_closing_voucher.py +++ b/erpnext/accounts/doctype/process_period_closing_voucher/test_process_period_closing_voucher.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestProcessPeriodClosingVoucher(IntegrationTestCase): - """ - Integration tests for ProcessPeriodClosingVoucher. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/test_process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/test_process_statement_of_accounts.py index 2d599fee1af..c16933c7836 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/test_process_statement_of_accounts.py +++ b/erpnext/accounts/doctype/process_statement_of_accounts/test_process_statement_of_accounts.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, getdate, today from erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts import ( @@ -12,26 +11,16 @@ from erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of ) from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestProcessStatementOfAccounts(AccountsTestMixin, IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestProcessStatementOfAccounts(AccountsTestMixin, ERPNextTestSuite): + def setUp(self): + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) letterhead = frappe.get_doc("Letter Head", "Company Letterhead - Grey") letterhead.is_default = 0 letterhead.save() - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - @classmethod - def tearDownClass(cls): - super().tearDownClass() - letterhead = frappe.get_doc("Letter Head", "Company Letterhead - Grey") - letterhead.is_default = 1 - letterhead.save() - frappe.db.commit() # nosemgrep - - def setUp(self): self.create_company() self.create_customer() self.create_customer(customer_name="Other Customer") @@ -101,9 +90,6 @@ class TestProcessStatementOfAccounts(AccountsTestMixin, IntegrationTestCase): for age_range in expected_ageing: self.assertEqual(expected_ageing[age_range], ageing.get(age_range)) - def tearDown(self): - frappe.db.rollback() - def create_process_soa(**args): args = frappe._dict(args) diff --git a/erpnext/accounts/doctype/process_subscription/test_process_subscription.py b/erpnext/accounts/doctype/process_subscription/test_process_subscription.py index 5ec80641192..8c7604b8f5c 100644 --- a/erpnext/accounts/doctype/process_subscription/test_process_subscription.py +++ b/erpnext/accounts/doctype/process_subscription/test_process_subscription.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestProcessSubscription(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestProcessSubscription(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py b/erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py index 413ce1af792..cebdaa4fca8 100644 --- a/erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py +++ b/erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py @@ -3,13 +3,13 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.promotional_scheme.promotional_scheme import TransactionExists from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.tests.utils import ERPNextTestSuite -class TestPromotionalScheme(IntegrationTestCase): +class TestPromotionalScheme(ERPNextTestSuite): def setUp(self): if frappe.db.exists("Promotional Scheme", "_Test Scheme"): frappe.delete_doc("Promotional Scheme", "_Test Scheme") diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index cb771bdc35a..33117c639dc 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, cint, flt, getdate, nowdate, today import erpnext @@ -37,24 +36,15 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle ) from erpnext.stock.doctype.stock_entry.test_stock_entry import get_qty_after_transaction from erpnext.stock.tests.test_utils import StockTestMixin - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Cost Center", "Payment Term", "Payment Terms Template"] -IGNORE_TEST_RECORD_DEPENDENCIES = ["Serial No"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin): + def setUp(self): unlink_payment_on_cancel_of_invoice() frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1) - - @classmethod - def tearDownClass(cls): - unlink_payment_on_cancel_of_invoice(0) - - def tearDown(self): - frappe.db.rollback() + self.load_test_records("Purchase Invoice") + self.load_test_records("Journal Entry") def test_purchase_invoice_qty(self): pi = make_purchase_invoice(qty=0, do_not_save=True) @@ -352,6 +342,9 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): self.assertEqual(expected_values[gle.account][1], gle.debit) self.assertEqual(expected_values[gle.account][2], gle.credit) + @ERPNextTestSuite.change_settings( + "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} + ) def test_purchase_invoice_with_exchange_rate_difference(self): from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as create_purchase_invoice, @@ -375,7 +368,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): # fetching the latest GL Entry with exchange gain and loss account account amount = frappe.db.get_value( - "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "debit" + "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "credit" ) discrepancy_caused_by_exchange_rate_diff = abs( pi.items[0].base_net_amount - pr.items[0].base_net_amount @@ -421,14 +414,14 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): # fetching the latest GL Entry with exchange gain and loss account account amount = frappe.db.get_value( - "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "debit" + "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "credit" ) discrepancy_caused_by_exchange_rate_diff = abs( pi.items[1].base_net_amount - pr.items[1].base_net_amount ) - self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount) + self.assertEqual(flt(discrepancy_caused_by_exchange_rate_diff, 2), amount) def test_purchase_invoice_change_naming_series(self): pi = frappe.copy_doc(self.globalTestRecords["Purchase Invoice"][1]) @@ -509,9 +502,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): self.assertEqual(tax.tax_amount, expected_values[i][1]) self.assertEqual(tax.total, expected_values[i][2]) - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_purchase_invoice_with_advance(self): jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][1]) jv.insert() @@ -562,9 +553,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): ) ) - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_invoice_with_advance_and_multi_payment_terms(self): jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][1]) jv.insert() @@ -1289,9 +1278,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): acc_settings.submit_journal_entriessubmit_journal_entries = 0 acc_settings.save() - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_gain_loss_with_advance_entry(self): unlink_enabled = frappe.db.get_single_value( "Accounts Settings", "unlink_payment_on_cancellation_of_invoice" @@ -1492,9 +1479,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): ) frappe.db.set_value("Company", "_Test Company", "exchange_gain_loss_account", original_account) - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_purchase_invoice_advance_taxes(self): from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -2160,7 +2145,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): rate = flt(sle.stock_value_difference) / flt(sle.actual_qty) self.assertAlmostEqual(rate, 500) - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) def test_payment_allocation_for_payment_terms(self): from erpnext.buying.doctype.purchase_order.test_purchase_order import ( create_pr_against_po, @@ -2287,6 +2272,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): def test_create_purchase_invoice_without_mandatory(self): pi = frappe.new_doc("Purchase Invoice") + pi.company = "_Test Company" pi.flags.ignore_mandatory = True pi.insert(ignore_permissions=True) @@ -2295,7 +2281,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): pi.delete() - @IntegrationTestCase.change_settings("Buying Settings", {"supplier_group": None}) + @ERPNextTestSuite.change_settings("Buying Settings", {"supplier_group": None}) def test_purchase_invoice_without_supplier_group(self): # Create a Supplier test_supplier_name = "_Test Supplier Without Supplier Group" @@ -2415,6 +2401,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): "doctype": "Serial No", "item_code": serial_item, "serial_no": serial_no, + "company": "_Test Company", } ).insert() @@ -2467,11 +2454,6 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): self.assertEqual(row.rejected_serial_no, serial_nos[2]) def test_make_pr_and_pi_from_po(self): - from erpnext.assets.doctype.asset.test_asset import create_asset_category - - if not frappe.db.exists("Asset Category", "Computers"): - create_asset_category() - item = create_item( item_code="_Test_Item", is_stock_item=0, is_fixed_asset=1, asset_category="Computers" ) @@ -2642,7 +2624,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): frappe.db.set_single_value("Buying Settings", "maintain_same_rate", 1) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Buying Settings", {"maintain_same_rate": 0, "set_landed_cost_based_on_purchase_invoice_rate": 1} ) def test_pr_status_rate_adjusted_from_pi(self): diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.py b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.py index 80ce28c4ffd..5dbd05a17f6 100644 --- a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.py +++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseTaxesandChargesTemplate(IntegrationTestCase): +class TestPurchaseTaxesandChargesTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/repost_accounting_ledger/test_repost_accounting_ledger.py b/erpnext/accounts/doctype/repost_accounting_ledger/test_repost_accounting_ledger.py index cde007d14f6..b60c13fc8b8 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger/test_repost_accounting_ledger.py +++ b/erpnext/accounts/doctype/repost_accounting_ledger/test_repost_accounting_ledger.py @@ -4,7 +4,6 @@ import frappe from frappe import qb from frappe.query_builder.functions import Sum -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, nowdate, today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -14,23 +13,17 @@ from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.utils import get_fiscal_year from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries, make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestRepostAccountingLedger(AccountsTestMixin, IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - +class TestRepostAccountingLedger(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) update_repost_settings() - def tearDown(self): - frappe.db.rollback() - def test_01_basic_functions(self): si = create_sales_invoice( item=self.item, @@ -121,7 +114,7 @@ class TestRepostAccountingLedger(AccountsTestMixin, IntegrationTestCase): ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name}) self.assertRaises(frappe.ValidationError, ral.save) - @IntegrationTestCase.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) def test_04_pcv_validation(self): # Clear old GL entries so PCV can be submitted. gl = frappe.qb.DocType("GL Entry") diff --git a/erpnext/accounts/doctype/repost_accounting_ledger_settings/test_repost_accounting_ledger_settings.py b/erpnext/accounts/doctype/repost_accounting_ledger_settings/test_repost_accounting_ledger_settings.py index 2dd4c50ba7e..6a8698e96af 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger_settings/test_repost_accounting_ledger_settings.py +++ b/erpnext/accounts/doctype/repost_accounting_ledger_settings/test_repost_accounting_ledger_settings.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestRepostAccountingLedgerSettings(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestRepostAccountingLedgerSettings(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/repost_payment_ledger/test_repost_payment_ledger.py b/erpnext/accounts/doctype/repost_payment_ledger/test_repost_payment_ledger.py index a09ba71e27c..8c2b8946121 100644 --- a/erpnext/accounts/doctype/repost_payment_ledger/test_repost_payment_ledger.py +++ b/erpnext/accounts/doctype/repost_payment_ledger/test_repost_payment_ledger.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestRepostPaymentLedger(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestRepostPaymentLedger(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 75a9fae92e9..ba5aa9dfd93 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -2777,7 +2777,7 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None): "doctype": target_doctype, "postprocess": update_details, "set_target_warehouse": "set_from_warehouse", - "field_no_map": ["taxes_and_charges", "set_warehouse", "shipping_address"], + "field_no_map": ["taxes_and_charges", "set_warehouse", "shipping_address", "cost_center"], }, doctype + " Item": item_field_map, }, diff --git a/erpnext/accounts/doctype/sales_invoice/test_records.json b/erpnext/accounts/doctype/sales_invoice/test_records.json index 814c6757d38..9aee69cd053 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_records.json +++ b/erpnext/accounts/doctype/sales_invoice/test_records.json @@ -383,5 +383,390 @@ "price_list_currency": "INR", "selling_price_list": "_Test Price List", "territory": "_Test Territory" + }, + { + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "cost_center": "_Test Cost Center - _TC", + "customer": "_Test Customer", + "customer_name": "_Test Customer", + "debit_to": "Debtors - _TC", + "doctype": "Sales Invoice", + "items": [ + { + "amount": 500.0, + "base_amount": 500.0, + "base_rate": 500.0, + "cost_center": "_Test Cost Center - _TC", + "description": "138-CMS Shoe", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "138-CMS Shoe", + "item_name": "138-CMS Shoe", + "parentfield": "items", + "qty": 1.0, + "rate": 500.0, + "uom": "_Test UOM", + "conversion_factor": 1, + "stock_uom": "_Test UOM" + } + ], + "base_grand_total": 561.8, + "grand_total": 561.8, + "is_pos": 0, + "naming_series": "T-SINV-", + "base_net_total": 500.0, + "taxes": [ + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "cost_center": "_Test Cost Center - _TC", + "rate": 6 + }, + { + "account_head": "_Test Account Service Tax - _TC", + "charge_type": "On Net Total", + "description": "Service Tax", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "cost_center": "_Test Cost Center - _TC", + "rate": 6.36 + } + ], + "plc_conversion_rate": 1.0, + "price_list_currency": "INR", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory" + }, + { + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "customer": "_Test Customer", + "customer_name": "_Test Customer", + "debit_to": "Debtors - _TC", + "doctype": "Sales Invoice", + "cost_center": "_Test Cost Center - _TC", + "items": [ + { + "amount": 500.0, + "base_amount": 500.0, + "base_rate": 500.0, + "cost_center": "_Test Cost Center - _TC", + "description": "_Test Item", + "doctype": "Sales Invoice Item", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "income_account": "Sales - _TC", + "item_code": "_Test Item", + "item_name": "_Test Item", + "parentfield": "items", + "price_list_rate": 500.0, + "qty": 1.0, + "uom": "_Test UOM", + "conversion_factor": 1, + "stock_uom": "_Test UOM" + } + ], + "base_grand_total": 630.0, + "grand_total": 630.0, + "is_pos": 0, + "naming_series": "T-SINV-", + "base_net_total": 500.0, + "taxes": [ + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "cost_center": "_Test Cost Center - _TC", + "rate": 16 + }, + { + "account_head": "_Test Account Service Tax - _TC", + "charge_type": "On Net Total", + "description": "Service Tax", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "cost_center": "_Test Cost Center - _TC", + "rate": 10 + } + ], + "plc_conversion_rate": 1.0, + "price_list_currency": "INR", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory" + }, + { + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "customer": "_Test Customer", + "customer_name": "_Test Customer", + "debit_to": "Debtors - _TC", + "doctype": "Sales Invoice", + "cost_center": "_Test Cost Center - _TC", + "items": [ + { + "cost_center": "_Test Cost Center - _TC", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "_Test Item Home Desktop 100", + "item_name": "_Test Item Home Desktop 100", + "item_tax_template": "_Test Account Excise Duty @ 10 - _TC", + "parentfield": "items", + "price_list_rate": 50, + "qty": 10, + "rate": 50, + "uom": "_Test UOM 1", + "conversion_factor": 1, + "stock_uom": "_Test UOM 1" + }, + { + "cost_center": "_Test Cost Center - _TC", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "_Test Item Home Desktop 200", + "item_name": "_Test Item Home Desktop 200", + "parentfield": "items", + "price_list_rate": 150, + "qty": 5, + "uom": "_Test UOM", + "conversion_factor": 1, + "rate": 150, + "stock_uom": "_Test UOM" + } + ], + "grand_total": 0, + "is_pos": 0, + "naming_series": "T-SINV-", + "taxes": [ + { + "account_head": "_Test Account Shipping Charges - _TC", + "charge_type": "Actual", + "cost_center": "_Test Cost Center - _TC", + "description": "Shipping Charges", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "tax_amount": 100 + }, + { + "account_head": "_Test Account Customs Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Customs Duty", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 10 + }, + { + "account_head": "_Test Account Excise Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Excise Duty", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 12 + }, + { + "account_head": "_Test Account Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "Education Cess", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 2, + "row_id": 3 + }, + { + "account_head": "_Test Account S&H Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "S&H Education Cess", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 1, + "row_id": 3 + }, + { + "account_head": "_Test Account CST - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "CST", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 2, + "row_id": 5 + }, + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 12.5 + }, + { + "account_head": "_Test Account Discount - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Discount", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": -10, + "row_id": 7 + } + ], + "plc_conversion_rate": 1.0, + "price_list_currency": "INR", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory" + }, + { + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "customer": "_Test Customer", + "customer_name": "_Test Customer", + "debit_to": "Debtors - _TC", + "doctype": "Sales Invoice", + "cost_center": "_Test Cost Center - _TC", + "items": [ + { + "cost_center": "_Test Cost Center - _TC", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "_Test Item Home Desktop 100", + "item_name": "_Test Item Home Desktop 100", + "item_tax_template": "_Test Account Excise Duty @ 10 - _TC", + "parentfield": "items", + "price_list_rate": 62.5, + "qty": 10, + "uom": "_Test UOM 1", + "conversion_factor": 1, + "stock_uom": "_Test UOM 1" + }, + { + "cost_center": "_Test Cost Center - _TC", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "_Test Item Home Desktop 200", + "item_name": "_Test Item Home Desktop 200", + "parentfield": "items", + "price_list_rate": 190.66, + "qty": 5, + "uom": "_Test UOM", + "conversion_factor": 1, + "stock_uom": "_Test UOM" + } + ], + "grand_total": 0, + "is_pos": 0, + "naming_series": "T-SINV-", + "taxes": [ + { + "account_head": "_Test Account Excise Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Excise Duty", + "doctype": "Sales Taxes and Charges", + "idx": 1, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 12 + }, + { + "account_head": "_Test Account Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "Education Cess", + "doctype": "Sales Taxes and Charges", + "idx": 2, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 2, + "row_id": 1 + }, + { + "account_head": "_Test Account S&H Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "S&H Education Cess", + "doctype": "Sales Taxes and Charges", + "idx": 3, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 1, + "row_id": 1 + }, + { + "account_head": "_Test Account CST - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "CST", + "doctype": "Sales Taxes and Charges", + "idx": 4, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 2, + "row_id": 3 + }, + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "idx": 5, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 12.5 + }, + { + "account_head": "_Test Account Customs Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Customs Duty", + "doctype": "Sales Taxes and Charges", + "idx": 6, + "parentfield": "taxes", + "rate": 10 + }, + { + "account_head": "_Test Account Shipping Charges - _TC", + "charge_type": "Actual", + "cost_center": "_Test Cost Center - _TC", + "description": "Shipping Charges", + "doctype": "Sales Taxes and Charges", + "idx": 7, + "parentfield": "taxes", + "tax_amount": 100 + }, + { + "account_head": "_Test Account Discount - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Discount", + "doctype": "Sales Taxes and Charges", + "idx": 8, + "parentfield": "taxes", + "rate": -10, + "row_id": 7 + } + ], + "plc_conversion_rate": 1.0, + "price_list_currency": "INR", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory" } ] diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index c00924a4394..3616f196bb7 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -7,7 +7,6 @@ import json import frappe from frappe import qb from frappe.model.dynamic_links import get_dynamic_link_map -from frappe.tests import IntegrationTestCase, change_settings from frappe.utils import add_days, cint, flt, format_date, getdate, nowdate, today import erpnext @@ -23,7 +22,7 @@ from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import ( from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_inter_company_transaction from erpnext.accounts.utils import PaymentEntryUnlinkError from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries -from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data +from erpnext.assets.doctype.asset.test_asset import create_asset from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( get_depr_schedule, ) @@ -53,6 +52,11 @@ from erpnext.tests.utils import ERPNextTestSuite class TestSalesInvoice(ERPNextTestSuite): def setUp(self): + self.load_test_records("Journal Entry") + self.load_test_records("Stock Entry") + self.load_test_records("Sales Invoice") + unlink_payment_on_cancel_of_invoice() + from erpnext.stock.doctype.stock_ledger_entry.test_stock_ledger_entry import create_items create_items(["_Test Internal Transfer Item"], uoms=[{"uom": "Box", "conversion_factor": 10}]) @@ -65,8 +69,9 @@ class TestSalesInvoice(ERPNextTestSuite): ) for company in frappe.get_all("Company", pluck="name"): frappe.db.set_value("Company", company, "accounts_frozen_till_date", None) + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) - @change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"maintain_same_internal_transaction_rate": 1, "maintain_same_rate_action": "Stop"}, ) @@ -86,9 +91,6 @@ class TestSalesInvoice(ERPNextTestSuite): pi.submit() self.assertIn("Rate must be same", str(e.exception)) - def tearDown(self): - frappe.db.rollback() - def make(self): w = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][0]) w.is_pos = 0 @@ -96,18 +98,6 @@ class TestSalesInvoice(ERPNextTestSuite): w.submit() return w - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - cls.make_employees() - cls.make_sales_person() - unlink_payment_on_cancel_of_invoice() - - @classmethod - def tearDownClass(self): - unlink_payment_on_cancel_of_invoice(0) - def test_sales_invoice_qty(self): si = create_sales_invoice(qty=0, do_not_save=True) with self.assertRaises(InvalidQtyError): @@ -229,9 +219,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertRaises(frappe.LinkExistsError, si.cancel) unlink_payment_on_cancel_of_invoice() - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_payment_entry_unlink_against_standalone_credit_note(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry @@ -273,6 +261,9 @@ class TestSalesInvoice(ERPNextTestSuite): si1.load_from_db() self.assertRaises(PaymentEntryUnlinkError, si1.cancel) + @ERPNextTestSuite.change_settings( + "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} + ) def test_sales_invoice_calculation_export_currency(self): si = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][2]) si.currency = "USD" @@ -536,6 +527,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertTrue(gle) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_tax_calculation_with_multiple_items(self): si = create_sales_invoice(qty=84, rate=4.6, do_not_save=True) item_row = si.get("items")[0] @@ -564,6 +556,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(si.grand_total, 5474.0) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_tax_calculation_with_item_tax_template(self): si = create_sales_invoice(qty=84, rate=4.6, do_not_save=True) item_row = si.get("items")[0] @@ -630,6 +623,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(si.rounding_adjustment, 0.43) self.assertEqual(si.rounded_total, 5676.0) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_tax_calculation_with_multiple_items_and_discount(self): si = create_sales_invoice(qty=1, rate=75, do_not_save=True) item_row = si.get("items")[0] @@ -754,6 +748,9 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(si.base_grand_total, 1622.97) self.assertEqual(si.grand_total, 1622.97) + @ERPNextTestSuite.change_settings( + "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} + ) def test_sales_invoice_calculation_export_currency_with_tax_inclusive_price(self): # prepare si = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][3]) @@ -844,7 +841,7 @@ class TestSalesInvoice(ERPNextTestSuite): w = self.make() self.assertEqual(w.outstanding_amount, w.base_rounded_total) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"add_taxes_from_item_tax_template": 0, "add_taxes_from_taxes_and_charges_template": 0}, ) @@ -1401,9 +1398,7 @@ class TestSalesInvoice(ERPNextTestSuite): dn.submit() return dn - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_sales_invoice_with_advance(self): jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][0]) jv.insert() @@ -1624,7 +1619,6 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertRaises(frappe.ValidationError, cr_note.save) def test_gle_made_when_asset_is_returned(self): - create_asset_data() asset = create_asset(item_code="Macbook Pro") si = create_sales_invoice(item_code="Macbook Pro", asset=asset.name, qty=1, rate=90000) @@ -2131,17 +2125,21 @@ class TestSalesInvoice(ERPNextTestSuite): si.insert() return si + @ERPNextTestSuite.change_settings("Selling Settings", {"sales_update_frequency": "Each Transaction"}) def test_company_monthly_sales(self): - existing_current_month_sales = frappe.get_cached_value( - "Company", "_Test Company", "total_monthly_sales" - ) + from erpnext.setup.doctype.company.company import update_company_current_month_sales + + company = "_Test Company" + + update_company_current_month_sales(company) + existing_current_month_sales = frappe.db.get_value("Company", company, "total_monthly_sales") si = create_sales_invoice() - current_month_sales = frappe.get_cached_value("Company", "_Test Company", "total_monthly_sales") + current_month_sales = frappe.db.get_value("Company", company, "total_monthly_sales") self.assertEqual(current_month_sales, existing_current_month_sales + si.base_grand_total) si.cancel() - current_month_sales = frappe.get_cached_value("Company", "_Test Company", "total_monthly_sales") + current_month_sales = frappe.db.get_value("Company", company, "total_monthly_sales") self.assertEqual(current_month_sales, existing_current_month_sales) def test_rounding_adjustment(self): @@ -2188,6 +2186,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(expected_values[gle.account][1], gle.debit) self.assertEqual(expected_values[gle.account][2], gle.credit) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_rounding_adjustment_2(self): si = create_sales_invoice(rate=400, do_not_save=True) for rate in [400.25, 600.30, 100.65]: @@ -2245,6 +2244,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(expected_account_values[0], gle.debit) self.assertEqual(expected_account_values[1], gle.credit) + @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 @@ -2484,7 +2484,7 @@ class TestSalesInvoice(ERPNextTestSuite): for gle in gl_entries: self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"book_deferred_entries_based_on": "Days", "book_deferred_entries_via_journal_entry": 0}, ) @@ -2540,7 +2540,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertRaises(frappe.ValidationError, si.save) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"book_deferred_entries_based_on": "Months", "book_deferred_entries_via_journal_entry": 0}, ) @@ -3005,7 +3005,7 @@ class TestSalesInvoice(ERPNextTestSuite): si.submit() - @IntegrationTestCase.change_settings("Selling Settings", {"enable_discount_accounting": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"enable_discount_accounting": 1}) def test_sales_invoice_with_discount_accounting_enabled(self): discount_account = create_account( account_name="Discount Account", @@ -3022,7 +3022,7 @@ class TestSalesInvoice(ERPNextTestSuite): check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1)) - @IntegrationTestCase.change_settings("Selling Settings", {"enable_discount_accounting": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"enable_discount_accounting": 1}) def test_additional_discount_for_sales_invoice_with_discount_accounting_enabled(self): from erpnext.accounts.doctype.repost_accounting_ledger.test_repost_accounting_ledger import ( update_repost_settings, @@ -3113,7 +3113,6 @@ class TestSalesInvoice(ERPNextTestSuite): Tests if an Asset set to depreciate yearly on June 30, that gets sold on Sept 30, creates an additional depreciation entry on its date of sale. """ - create_asset_data() asset = create_asset(item_code="Macbook Pro", calculate_depreciation=1, submit=1) post_depreciation_entries(getdate("2021-09-30")) @@ -3139,7 +3138,6 @@ class TestSalesInvoice(ERPNextTestSuite): Tests if an Asset set to depreciate yearly on Dec 31, that gets sold on Dec 31 after two years, created an additional depreciation entry on its date of sale. """ - create_asset_data() asset = create_asset( item_code="Macbook Pro", calculate_depreciation=1, @@ -3460,7 +3458,8 @@ class TestSalesInvoice(ERPNextTestSuite): si.submit() frappe.db.set_value("Company", "_Test Company", "accounts_frozen_till_date", None) - @IntegrationTestCase.change_settings("Accounts Settings", {"over_billing_allowance": 0}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"over_billing_allowance": 0}) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_over_billing_case_against_delivery_note(self): """ Test a case where duplicating the item with qty = 1 in the invoice @@ -3486,7 +3485,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertTrue("cannot overbill" in str(err.exception).lower()) dn.cancel() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "book_deferred_entries_via_journal_entry": 1, @@ -3604,9 +3603,7 @@ class TestSalesInvoice(ERPNextTestSuite): account.disabled = 0 account.save() - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_gain_loss_with_advance_entry(self): from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry @@ -3769,7 +3766,7 @@ class TestSalesInvoice(ERPNextTestSuite): set_advance_flag(company="_Test Company", flag=0, default_account="") - @IntegrationTestCase.change_settings("Selling Settings", {"customer_group": None, "territory": None}) + @ERPNextTestSuite.change_settings("Selling Settings", {"customer_group": None, "territory": None}) def test_sales_invoice_without_customer_group_and_territory(self): # create a customer if not frappe.db.exists("Customer", "_Test Simple Customer"): @@ -3787,7 +3784,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(si.customer_group, None) self.assertEqual(si.territory, None) - @IntegrationTestCase.change_settings("Selling Settings", {"allow_negative_rates_for_items": 0}) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_negative_rates_for_items": 0}) def test_sales_return_negative_rate(self): si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True) self.assertRaises(frappe.ValidationError, si.save) @@ -3884,19 +3881,18 @@ class TestSalesInvoice(ERPNextTestSuite): def test_loyalty_points_redemption_with_shopping_cart(self): from erpnext.accounts.doctype.loyalty_program.test_loyalty_program import ( - create_records, create_sales_invoice_record, ) 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 # Set up loyalty program - create_records() - frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") + loyalty_customer = frappe.get_doc("Customer", {"customer_name": "Test Loyalty Customer"}).name + frappe.db.set_value("Customer", loyalty_customer, "loyalty_program", "Test Single Loyalty") create_sales_invoice_record(10).insert().submit() # Create a sales order - so = make_sales_order(qty=10, do_not_save=True, customer="Test Loyalty Customer") + so = make_sales_order(qty=10, do_not_save=True, customer=loyalty_customer) so.name = "_T-Sales Order LP-0001" so.order_type = "Shopping Cart" so.loyalty_points = 50 @@ -4174,12 +4170,14 @@ class TestSalesInvoice(ERPNextTestSuite): si.save() return si + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_rounding_validation_for_opening_with_inclusive_tax(self): si = self._create_opening_invoice_with_inclusive_tax() # 'Round Off for Opening' not set in Company master # Ledger level validation must be thrown self.assertRaises(frappe.ValidationError, si.submit) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_ledger_entries_on_opening_invoice_with_rounding_loss_by_inclusive_tax(self): si = self._create_opening_invoice_with_inclusive_tax() # 'Round Off for Opening' is set in Company master @@ -4201,7 +4199,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(len(actual), 4) self.assertEqual(expected, actual) - @IntegrationTestCase.change_settings("Accounts Settings", {"enable_common_party_accounting": True}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"enable_common_party_accounting": True}) def test_common_party_with_foreign_currency_jv(self): from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( @@ -4283,7 +4281,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertTrue(jv) self.assertEqual(jv[0], si.grand_total) - @IntegrationTestCase.change_settings("Accounts Settings", {"enable_common_party_accounting": True}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"enable_common_party_accounting": True}) def test_common_party_with_different_currency_in_debtor_and_creditor(self): from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( @@ -4392,6 +4390,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertTrue(all([x == "Credit Note" for x in gl_entries])) + @ERPNextTestSuite.change_settings("Selling Settings", {"sales_update_frequency": "Each Transaction"}) def test_total_billed_amount(self): si = create_sales_invoice(do_not_submit=True) @@ -4407,6 +4406,8 @@ class TestSalesInvoice(ERPNextTestSuite): doc = frappe.get_doc("Project", project.name) self.assertEqual(doc.total_billed_amount, si.grand_total) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) + @ERPNextTestSuite.change_settings("Selling Settings", {"sales_update_frequency": "Each Transaction"}) def test_total_billed_amount_with_different_projects(self): # This test case is for checking the scenario where project is set at document level and for **some** child items only, not all from copy import copy @@ -4745,7 +4746,7 @@ class TestSalesInvoice(ERPNextTestSuite): doc.db_set("do_not_use_batchwise_valuation", original_value) - @change_settings("Selling Settings", {"set_zero_rate_for_expired_batch": True}) + @ERPNextTestSuite.change_settings("Selling Settings", {"set_zero_rate_for_expired_batch": True}) def test_zero_valuation_for_standalone_credit_note_with_expired_batch(self): item_code = "_Test Item for Expiry Batch Zero Valuation" make_item_for_si( @@ -4805,6 +4806,33 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(stock_ledger_entry.incoming_rate, 0.0) + def test_inter_company_transaction_cost_center(self): + si = create_sales_invoice( + company="Wind Power LLC", + customer="_Test Internal Customer", + debit_to="Debtors - WP", + warehouse="Stores - WP", + income_account="Sales - WP", + expense_account="Cost of Goods Sold - WP", + parent_cost_center="Main - WP", + cost_center="Main - WP", + currency="USD", + do_not_save=1, + ) + + si.selling_price_list = "_Test Price List Rest of the World" + si.submit() + + cost_center = frappe.db.get_value("Company", "_Test Company 1", "cost_center") + frappe.db.set_value("Company", "_Test Company 1", "cost_center", None) + + target_doc = make_inter_company_transaction("Sales Invoice", si.name) + + self.assertEqual(target_doc.cost_center, None) + self.assertEqual(target_doc.items[0].cost_center, None) + + frappe.db.set_value("Company", "_Test Company 1", "cost_center", cost_center) + def make_item_for_si(item_code, properties=None): from erpnext.stock.doctype.item.test_item import make_item @@ -4989,9 +5017,6 @@ def create_sales_invoice_against_cost_center(**args): return si -EXTRA_TEST_RECORD_DEPENDENCIES = ["Journal Entry", "Contact", "Address"] - - def get_outstanding_amount(against_voucher_type, against_voucher, account, party, party_type): bal = flt( frappe.db.sql( diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_records.json b/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_records.json deleted file mode 100644 index 74db08d5b86..00000000000 --- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_records.json +++ /dev/null @@ -1,209 +0,0 @@ -[ - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 6 - }, - { - "account_head": "_Test Account Service Tax - _TC", - "charge_type": "On Net Total", - "description": "Service Tax", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 6.36 - } - ], - "title": "_Test Sales Taxes and Charges Template" - }, - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account Shipping Charges - _TC", - "charge_type": "Actual", - "cost_center": "_Test Cost Center - _TC", - "description": "Shipping Charges", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "tax_amount": 100 - }, - { - "account_head": "_Test Account Customs Duty - _TC", - "charge_type": "On Net Total", - "cost_center": "_Test Cost Center - _TC", - "description": "Customs Duty", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 10 - }, - { - "account_head": "_Test Account Excise Duty - _TC", - "charge_type": "On Net Total", - "cost_center": "_Test Cost Center - _TC", - "description": "Excise Duty", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 12 - }, - { - "account_head": "_Test Account Education Cess - _TC", - "charge_type": "On Previous Row Amount", - "cost_center": "_Test Cost Center - _TC", - "description": "Education Cess", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 2, - "row_id": 3 - }, - { - "account_head": "_Test Account S&H Education Cess - _TC", - "charge_type": "On Previous Row Amount", - "cost_center": "_Test Cost Center - _TC", - "description": "S&H Education Cess", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 1, - "row_id": 3 - }, - { - "account_head": "_Test Account CST - _TC", - "charge_type": "On Previous Row Total", - "cost_center": "_Test Cost Center - _TC", - "description": "CST", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 2, - "row_id": 5 - }, - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "cost_center": "_Test Cost Center - _TC", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 12.5 - }, - { - "account_head": "_Test Account Discount - _TC", - "charge_type": "On Previous Row Total", - "cost_center": "_Test Cost Center - _TC", - "description": "Discount", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": -10, - "row_id": 7 - } - ], - "title": "_Test India Tax Master" - }, - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 12 - }, - { - "account_head": "_Test Account Service Tax - _TC", - "charge_type": "On Net Total", - "description": "Service Tax", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 4 - } - ], - "title": "_Test Sales Taxes and Charges Template - Rest of the World" - }, - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 12 - }, - { - "account_head": "_Test Account Service Tax - _TC", - "charge_type": "On Net Total", - "description": "Service Tax", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 4 - } - ], - "title": "_Test Sales Taxes and Charges Template 1" - }, - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 12 - }, - { - "account_head": "_Test Account Service Tax - _TC", - "charge_type": "On Net Total", - "description": "Service Tax", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 4 - } - ], - "title": "_Test Sales Taxes and Charges Template 2" - }, - { - "doctype" : "Sales Taxes and Charges Template", - "title": "_Test Tax 1", - "company": "_Test Company", - "taxes":[{ - "charge_type": "Actual", - "account_head": "Sales Expenses - _TC", - "cost_center": "Main - _TC", - "description": "Test Shopping cart taxes with Tax Rule", - "tax_amount": 1000 - }] - }, - { - "doctype" : "Sales Taxes and Charges Template", - "title": "_Test Tax 2", - "company": "_Test Company", - "taxes":[{ - "charge_type": "Actual", - "account_head": "Sales Expenses - _TC", - "cost_center": "Main - _TC", - "description": "Test Shopping cart taxes with Tax Rule", - "tax_amount": 200 - }] - } -] diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.py b/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.py index 1684ca82cbd..6c9c1d8c206 100644 --- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.py +++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.py @@ -2,9 +2,8 @@ # See license.txt import unittest -import frappe -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesTaxesandChargesTemplate(IntegrationTestCase): +class TestSalesTaxesandChargesTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/share_transfer/test_share_transfer.py b/erpnext/accounts/doctype/share_transfer/test_share_transfer.py index 7cd76cc6b47..a227a9f3059 100644 --- a/erpnext/accounts/doctype/share_transfer/test_share_transfer.py +++ b/erpnext/accounts/doctype/share_transfer/test_share_transfer.py @@ -3,14 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.share_transfer.share_transfer import ShareDontExists - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Share Type", "Shareholder"] +from erpnext.tests.utils import ERPNextTestSuite -class TestShareTransfer(IntegrationTestCase): +class TestShareTransfer(ERPNextTestSuite): def setUp(self): frappe.db.sql("delete from `tabShare Transfer`") frappe.db.sql("delete from `tabShare Balance`") diff --git a/erpnext/accounts/doctype/share_type/test_records.json b/erpnext/accounts/doctype/share_type/test_records.json deleted file mode 100644 index 88cb8c056fe..00000000000 --- a/erpnext/accounts/doctype/share_type/test_records.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "doctype": "Share Type", - "title": "Class A" - }, - { - "doctype": "Share Type", - "title": "Class B" - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/share_type/test_share_type.py b/erpnext/accounts/doctype/share_type/test_share_type.py index e6f1f71f4bb..3aa79f53018 100644 --- a/erpnext/accounts/doctype/share_type/test_share_type.py +++ b/erpnext/accounts/doctype/share_type/test_share_type.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestShareType(IntegrationTestCase): +class TestShareType(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/shareholder/test_records.json b/erpnext/accounts/doctype/shareholder/test_records.json deleted file mode 100644 index 39b72d47770..00000000000 --- a/erpnext/accounts/doctype/shareholder/test_records.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "doctype": "Shareholder", - "naming_series": "SH-", - "title": "Iron Man", - "company": "_Test Company" - }, - { - "doctype": "Shareholder", - "naming_series": "SH-", - "title": "Thor", - "company": "_Test Company" - }, - { - "doctype": "Shareholder", - "naming_series": "SH-", - "title": "Hulk", - "company": "_Test Company" - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/shareholder/test_shareholder.py b/erpnext/accounts/doctype/shareholder/test_shareholder.py index 3c0f34858f9..4c4cc0b789e 100644 --- a/erpnext/accounts/doctype/shareholder/test_shareholder.py +++ b/erpnext/accounts/doctype/shareholder/test_shareholder.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestShareholder(IntegrationTestCase): +class TestShareholder(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py index d9b7b0a408f..3ec11364afa 100644 --- a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py +++ b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py @@ -152,7 +152,9 @@ class ShippingRule(Document): frappe.throw(_("Shipping rule only applicable for Buying")) shipping_charge["doctype"] = "Purchase Taxes and Charges" - shipping_charge["category"] = "Valuation and Total" + shipping_charge["category"] = ( + "Valuation and Total" if doc.get_stock_items() or doc.get_asset_items() else "Total" + ) shipping_charge["add_deduct_tax"] = "Add" existing_shipping_charge = doc.get("taxes", filters=shipping_charge) diff --git a/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py b/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py index be05f5662db..62d9c7805b1 100644 --- a/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py +++ b/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py @@ -3,16 +3,19 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.shipping_rule.shipping_rule import ( FromGreaterThanToError, ManyBlankToValuesError, OverlappingConditionError, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestShippingRule(IntegrationTestCase): +class TestShippingRule(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Shipping Rule") + def test_from_greater_than_to(self): shipping_rule = frappe.copy_doc(self.globalTestRecords["Shipping Rule"][0]) shipping_rule.name = self.globalTestRecords["Shipping Rule"][0].get("name") diff --git a/erpnext/accounts/doctype/subscription/test_subscription.py b/erpnext/accounts/doctype/subscription/test_subscription.py index 2f1c1742d0b..dbec8be72c6 100644 --- a/erpnext/accounts/doctype/subscription/test_subscription.py +++ b/erpnext/accounts/doctype/subscription/test_subscription.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils.data import ( add_days, add_months, @@ -19,20 +18,16 @@ from frappe.utils.data import ( from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.subscription.subscription import get_prorata_factor - -EXTRA_TEST_RECORD_DEPENDENCIES = ("UOM", "Item Group", "Item") +from erpnext.tests.utils import ERPNextTestSuite -class TestSubscription(IntegrationTestCase): +class TestSubscription(ERPNextTestSuite): def setUp(self): make_plans() create_parties() reset_settings() frappe.db.set_value("Company", "_Test Company", "accounts_frozen_till_date", None) - def tearDown(self): - frappe.db.rollback() - def test_create_subscription_with_trial_with_correct_period(self): subscription = create_subscription( trial_period_start=nowdate(), trial_period_end=add_months(nowdate(), 1) @@ -472,7 +467,7 @@ class TestSubscription(IntegrationTestCase): currency = frappe.db.get_value("Sales Invoice", subscription.invoices[0].name, "currency") self.assertEqual(currency, "USD") - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}, ) diff --git a/erpnext/accounts/doctype/subscription_invoice/test_subscription_invoice.py b/erpnext/accounts/doctype/subscription_invoice/test_subscription_invoice.py index a176a99a9b8..983526fc297 100644 --- a/erpnext/accounts/doctype/subscription_invoice/test_subscription_invoice.py +++ b/erpnext/accounts/doctype/subscription_invoice/test_subscription_invoice.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSubscriptionInvoice(IntegrationTestCase): +class TestSubscriptionInvoice(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/subscription_plan/test_subscription_plan.py b/erpnext/accounts/doctype/subscription_plan/test_subscription_plan.py index 19b9285b1d8..f2ae2ce85b8 100644 --- a/erpnext/accounts/doctype/subscription_plan/test_subscription_plan.py +++ b/erpnext/accounts/doctype/subscription_plan/test_subscription_plan.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSubscriptionPlan(IntegrationTestCase): +class TestSubscriptionPlan(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/subscription_settings/test_subscription_settings.py b/erpnext/accounts/doctype/subscription_settings/test_subscription_settings.py index 5d6607cb0cd..ce9193e1130 100644 --- a/erpnext/accounts/doctype/subscription_settings/test_subscription_settings.py +++ b/erpnext/accounts/doctype/subscription_settings/test_subscription_settings.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSubscriptionSettings(IntegrationTestCase): +class TestSubscriptionSettings(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/tax_category/test_records.json b/erpnext/accounts/doctype/tax_category/test_records.json deleted file mode 100644 index 1bb7f5ed876..00000000000 --- a/erpnext/accounts/doctype/tax_category/test_records.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "doctype": "Tax Category", - "title": "_Test Tax Category 1" - }, - { - "doctype": "Tax Category", - "title": "_Test Tax Category 2" - }, - { - "doctype": "Tax Category", - "title": "_Test Tax Category 3" - } -] diff --git a/erpnext/accounts/doctype/tax_category/test_tax_category.py b/erpnext/accounts/doctype/tax_category/test_tax_category.py index fbe654999f1..3eba2808ddb 100644 --- a/erpnext/accounts/doctype/tax_category/test_tax_category.py +++ b/erpnext/accounts/doctype/tax_category/test_tax_category.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxCategory(IntegrationTestCase): +class TestTaxCategory(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/tax_rule/test_records.json b/erpnext/accounts/doctype/tax_rule/test_records.json deleted file mode 100644 index e80b12f73ea..00000000000 --- a/erpnext/accounts/doctype/tax_rule/test_records.json +++ /dev/null @@ -1,28 +0,0 @@ -[ - { - "doctype": "Tax Rule", - "tax_type" : "Sales", - "sales_tax_template": "_Test Tax 1 - _TC", - "use_for_shopping_cart": 1, - "billing_city": "_Test City", - "billing_state": "Test State", - "billing_country": "India", - "shipping_city": "_Test City", - "shipping_country": "India", - "priority": 1, - "company": "_Test Company" - }, - { - "doctype": "Tax Rule", - "tax_type" : "Sales", - "sales_tax_template": "_Test Tax 2 - _TC", - "use_for_shopping_cart": 0, - "billing_city": "_Test City", - "billing_country": "India", - "shipping_city": "_Test City", - "shipping_state": "Test State", - "shipping_country": "India", - "priority": 2, - "company": "_Test Company" - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/tax_rule/test_tax_rule.py b/erpnext/accounts/doctype/tax_rule/test_tax_rule.py index 2602ea14861..ed3d004cc7e 100644 --- a/erpnext/accounts/doctype/tax_rule/test_tax_rule.py +++ b/erpnext/accounts/doctype/tax_rule/test_tax_rule.py @@ -3,25 +3,16 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.tax_rule.tax_rule import ConflictingTaxRule, get_tax_template from erpnext.crm.doctype.opportunity.opportunity import make_quotation from erpnext.crm.doctype.opportunity.test_opportunity import make_opportunity +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxRule(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - frappe.db.set_single_value("Shopping Cart Settings", "enabled", 0) - - @classmethod - def tearDownClass(cls): - frappe.db.sql("delete from `tabTax Rule`") - +class TestTaxRule(ERPNextTestSuite): def setUp(self): - frappe.db.sql("delete from `tabTax Rule`") + frappe.db.set_single_value("Shopping Cart Settings", "enabled", 0) def test_conflict(self): tax_rule1 = make_tax_rule( 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 a9773ceae60..66dc090f7c7 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 @@ -5,28 +5,21 @@ import datetime import frappe from frappe.custom.doctype.custom_field.custom_field import create_custom_fields -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_months, today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.utils import get_fiscal_year from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_invoice - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Supplier Group", "Customer Group"] +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxWithholdingCategory(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestTaxWithholdingCategory(ERPNextTestSuite): + def setUp(self): # create relevant supplier, etc create_records() create_tax_withholding_category_records() make_pan_no_field() - def tearDown(self): - frappe.db.rollback() - def validate_tax_withholding_entries(self, doctype, docname, expected_entries): """Validate tax withholding entries for a document""" entries = frappe.get_all( @@ -1036,6 +1029,7 @@ class TestTaxWithholdingCategory(IntegrationTestCase): self.cleanup_invoices(invoices) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": 1}) def test_tds_calculation_on_net_total_partial_tds(self): self.setup_party_with_category("Supplier", "Test TDS Supplier4", "Cumulative Threshold TDS") invoices = [] @@ -2049,7 +2043,7 @@ class TestTaxWithholdingCategory(IntegrationTestCase): self.assertEqual(pi2.taxes, []) self.assertEqual(payment.taxes[0].tax_amount, 6000) - @IntegrationTestCase.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) def test_tds_payment_entry_cancellation(self): """ Test payment entry cancellation clears withholding references from matched entries @@ -2227,7 +2221,7 @@ class TestTaxWithholdingCategory(IntegrationTestCase): self.validate_tax_withholding_entries("Purchase Invoice", pi1.name, expected_entries) self.cleanup_invoices(invoices) - @IntegrationTestCase.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) def test_tds_purchase_invoice_cancellation(self): """ Test that after cancellation, new documents get automatically adjusted against remaining entries diff --git a/erpnext/accounts/doctype/tax_withholding_entry/test_tax_withholding_entry.py b/erpnext/accounts/doctype/tax_withholding_entry/test_tax_withholding_entry.py index 8a09f46e079..3f52eb77ee5 100644 --- a/erpnext/accounts/doctype/tax_withholding_entry/test_tax_withholding_entry.py +++ b/erpnext/accounts/doctype/tax_withholding_entry/test_tax_withholding_entry.py @@ -1,17 +1,10 @@ # Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -# import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] +from erpnext.tests.utils import ERPNextTestSuite -class IntegrationTestTaxWithholdingEntry(IntegrationTestCase): +class IntegrationTestTaxWithholdingEntry(ERPNextTestSuite): """ Integration tests for TaxWithholdingEntry. Use this class for testing interactions between multiple components. diff --git a/erpnext/accounts/doctype/tax_withholding_group/test_tax_withholding_group.py b/erpnext/accounts/doctype/tax_withholding_group/test_tax_withholding_group.py index 268febe3d7e..eacdf7f36fc 100644 --- a/erpnext/accounts/doctype/tax_withholding_group/test_tax_withholding_group.py +++ b/erpnext/accounts/doctype/tax_withholding_group/test_tax_withholding_group.py @@ -1,17 +1,10 @@ # Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -# import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] +from erpnext.tests.utils import ERPNextTestSuite -class IntegrationTestTaxWithholdingGroup(IntegrationTestCase): +class IntegrationTestTaxWithholdingGroup(ERPNextTestSuite): """ Integration tests for TaxWithholdingGroup. Use this class for testing interactions between multiple components. diff --git a/erpnext/accounts/doctype/unreconcile_payment/test_unreconcile_payment.py b/erpnext/accounts/doctype/unreconcile_payment/test_unreconcile_payment.py index acd30cc47b7..7f931b7556e 100644 --- a/erpnext/accounts/doctype/unreconcile_payment/test_unreconcile_payment.py +++ b/erpnext/accounts/doctype/unreconcile_payment/test_unreconcile_payment.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry @@ -12,9 +11,10 @@ from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order 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.tests.utils import ERPNextTestSuite -class TestUnreconcilePayment(AccountsTestMixin, IntegrationTestCase): +class TestUnreconcilePayment(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -23,9 +23,6 @@ class TestUnreconcilePayment(AccountsTestMixin, IntegrationTestCase): self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, do_not_submit=False): si = create_sales_invoice( item=self.item, diff --git a/erpnext/accounts/report/account_balance/test_account_balance.py b/erpnext/accounts/report/account_balance/test_account_balance.py index 37d6f292fb6..f166421b0de 100644 --- a/erpnext/accounts/report/account_balance/test_account_balance.py +++ b/erpnext/accounts/report/account_balance/test_account_balance.py @@ -1,14 +1,14 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.account_balance.account_balance import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountBalance(IntegrationTestCase): +class TestAccountBalance(ERPNextTestSuite): def test_account_balance(self): frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company 2'") frappe.db.sql("delete from `tabGL Entry` where company='_Test Company 2'") diff --git a/erpnext/accounts/report/accounts_payable/test_accounts_payable.py b/erpnext/accounts/report/accounts_payable/test_accounts_payable.py index 8da40ea3aa4..87a4b989661 100644 --- a/erpnext/accounts/report/accounts_payable/test_accounts_payable.py +++ b/erpnext/accounts/report/accounts_payable/test_accounts_payable.py @@ -1,13 +1,13 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.report.accounts_payable.accounts_payable import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountsPayable(AccountsTestMixin, IntegrationTestCase): +class TestAccountsPayable(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -15,9 +15,6 @@ class TestAccountsPayable(AccountsTestMixin, IntegrationTestCase): self.create_supplier(currency="USD", supplier_name="Test Supplier2") self.create_usd_payable_account() - def tearDown(self): - frappe.db.rollback() - def test_accounts_payable_for_foreign_currency_supplier(self): pi = self.create_purchase_invoice(do_not_submit=True) pi.currency = "USD" diff --git a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py index 907840e8ff4..d38ce924cf0 100644 --- a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py @@ -1,6 +1,5 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, getdate, today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -8,9 +7,10 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal from erpnext.accounts.report.accounts_receivable.accounts_receivable import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): +class TestAccountsReceivable(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -18,9 +18,6 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): self.create_usd_receivable_account() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, no_payment_schedule=False, do_not_submit=False, **args): frappe.set_user("Administrator") si = create_sales_invoice( @@ -199,7 +196,7 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): row = report[1] self.assertTrue(len(row) == 0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}, ) @@ -448,7 +445,7 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): ], ) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) diff --git a/erpnext/accounts/report/accounts_receivable_summary/test_accounts_receivable_summary.py b/erpnext/accounts/report/accounts_receivable_summary/test_accounts_receivable_summary.py index d357c0d6273..96fa4ae8b64 100644 --- a/erpnext/accounts/report/accounts_receivable_summary/test_accounts_receivable_summary.py +++ b/erpnext/accounts/report/accounts_receivable_summary/test_accounts_receivable_summary.py @@ -1,14 +1,14 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.accounts_receivable_summary.accounts_receivable_summary import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): +class TestAccountsReceivable(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.maxDiff = None self.create_company() @@ -16,9 +16,6 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def test_01_receivable_summary_output(self): """ Test for Invoices, Paid, Advance and Outstanding @@ -112,7 +109,7 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): self.assertEqual(len(rpt_output), 1) self.assertDictEqual(rpt_output[0], expected_data) - @IntegrationTestCase.change_settings("Selling Settings", {"cust_master_name": "Naming Series"}) + @ERPNextTestSuite.change_settings("Selling Settings", {"cust_master_name": "Naming Series"}) def test_02_various_filters_and_output(self): filters = { "company": self.company, diff --git a/erpnext/accounts/report/balance_sheet/test_balance_sheet.py b/erpnext/accounts/report/balance_sheet/test_balance_sheet.py index cf225ba39da..dce9d8ab0fa 100644 --- a/erpnext/accounts/report/balance_sheet/test_balance_sheet.py +++ b/erpnext/accounts/report/balance_sheet/test_balance_sheet.py @@ -2,18 +2,16 @@ # MIT License. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils.data import today from erpnext.accounts.report.balance_sheet.balance_sheet import execute +from erpnext.tests.utils import ERPNextTestSuite COMPANY = "_Test Company 6" COMPANY_SHORT_NAME = "_TC6" -EXTRA_TEST_RECORD_DEPENDENCIES = ["Company"] - -class TestBalanceSheet(IntegrationTestCase): +class TestBalanceSheet(ERPNextTestSuite): def test_balance_sheet(self): frappe.db.sql(f"delete from `tabJournal Entry` where company='{COMPANY}'") frappe.db.sql(f"delete from `tabGL Entry` where company='{COMPANY}'") diff --git a/erpnext/accounts/report/bank_reconciliation_statement/test_bank_reconciliation_statement.py b/erpnext/accounts/report/bank_reconciliation_statement/test_bank_reconciliation_statement.py index 1fed7a43f7d..2e73a001107 100644 --- a/erpnext/accounts/report/bank_reconciliation_statement/test_bank_reconciliation_statement.py +++ b/erpnext/accounts/report/bank_reconciliation_statement/test_bank_reconciliation_statement.py @@ -2,15 +2,14 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.report.bank_reconciliation_statement.bank_reconciliation_statement import ( execute, ) -from erpnext.tests.utils import if_lending_app_installed +from erpnext.tests.utils import ERPNextTestSuite, if_lending_app_installed -class TestBankReconciliationStatement(IntegrationTestCase): +class TestBankReconciliationStatement(ERPNextTestSuite): @if_lending_app_installed def test_loan_entries_in_bank_reco_statement(self): from lending.loan_management.doctype.loan.test_loan import create_loan_accounts diff --git a/erpnext/accounts/report/consolidated_trial_balance/test_consolidated_trial_balance.py b/erpnext/accounts/report/consolidated_trial_balance/test_consolidated_trial_balance.py index d9d74f483b0..3166abf4061 100644 --- a/erpnext/accounts/report/consolidated_trial_balance/test_consolidated_trial_balance.py +++ b/erpnext/accounts/report/consolidated_trial_balance/test_consolidated_trial_balance.py @@ -3,36 +3,21 @@ import frappe from frappe import _ -from frappe.tests import IntegrationTestCase from frappe.utils import flt, today from erpnext.accounts.report.consolidated_trial_balance.consolidated_trial_balance import execute from erpnext.setup.utils import get_exchange_rate +from erpnext.tests.utils import ERPNextTestSuite class ForeignCurrencyTranslationReserveNotFoundError(frappe.ValidationError): pass -class TestConsolidatedTrialBalance(IntegrationTestCase): - @classmethod - def setUpClass(cls): - from erpnext.accounts.report.trial_balance.test_trial_balance import create_company +class TestConsolidatedTrialBalance(ERPNextTestSuite): + def setUp(self): from erpnext.accounts.utils import get_fiscal_year - # Group Company - create_company(company_name="Parent Group Company India", is_group=1) - - create_company(company_name="Child Company India", parent_company="Parent Group Company India") - - # Child Company with different currency - create_company( - company_name="Child Company US", - country="United States", - currency="USD", - parent_company="Parent Group Company India", - ) - create_journal_entry( company="Parent Group Company India", acc1="Marketing Expenses - PGCI", @@ -48,7 +33,7 @@ class TestConsolidatedTrialBalance(IntegrationTestCase): company="Child Company US", acc1="Marketing Expenses - CCU", acc2="Cash - CCU", amount=1000 ) - cls.fiscal_year = get_fiscal_year(today(), company="Parent Group Company India")[0] + self.fiscal_year = get_fiscal_year(today(), company="Parent Group Company India")[0] def test_single_company_report(self): filters = frappe._dict({"company": ["Parent Group Company India"], "fiscal_year": self.fiscal_year}) diff --git a/erpnext/accounts/report/customer_ledger_summary/test_customer_ledger_summary.py b/erpnext/accounts/report/customer_ledger_summary/test_customer_ledger_summary.py index 14e88afca39..0b114dd96d2 100644 --- a/erpnext/accounts/report/customer_ledger_summary/test_customer_ledger_summary.py +++ b/erpnext/accounts/report/customer_ledger_summary/test_customer_ledger_summary.py @@ -1,25 +1,22 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase -from frappe.utils import add_days, flt, getdate, today +from frappe.utils import today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.customer_ledger_summary.customer_ledger_summary import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.controllers.sales_and_purchase_return import make_return_doc +from erpnext.tests.utils import ERPNextTestSuite -class TestCustomerLedgerSummary(AccountsTestMixin, IntegrationTestCase): +class TestCustomerLedgerSummary(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, do_not_submit=False, **args): si = create_sales_invoice( item=self.item, diff --git a/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py b/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py index fcd9075a30f..15e216e333a 100644 --- a/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py +++ b/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py @@ -1,6 +1,5 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.doctype.account.test_account import create_account @@ -11,9 +10,10 @@ from erpnext.accounts.report.deferred_revenue_and_expense.deferred_revenue_and_e ) from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.utils import get_fiscal_year +from erpnext.tests.utils import ERPNextTestSuite -class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): +class TestDeferredRevenueAndExpense(ERPNextTestSuite, AccountsTestMixin): maxDiff = None def clear_old_entries(self): @@ -67,10 +67,7 @@ class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): self.setup_deferred_accounts_and_items() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - - @IntegrationTestCase.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) def test_deferred_revenue(self): self.create_item("_Test Internet Subscription", 0, self.warehouse, self.company) item = frappe.get_doc("Item", self.item) @@ -137,7 +134,7 @@ class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): ] self.assertEqual(report.period_total, expected) - @IntegrationTestCase.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) def test_deferred_expense(self): self.create_item("_Test Office Desk", 0, self.warehouse, self.company) item = frappe.get_doc("Item", self.item) @@ -207,7 +204,7 @@ class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): ] self.assertEqual(report.period_total, expected) - @IntegrationTestCase.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) def test_zero_months(self): self.create_item("_Test Internet Subscription", 0, self.warehouse, self.company) item = frappe.get_doc("Item", self.item) @@ -272,7 +269,7 @@ class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): ] self.assertEqual(report.period_total, expected) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"book_deferred_entries_based_on": "Months", "book_deferred_entries_via_journal_entry": 0}, ) diff --git a/erpnext/accounts/report/general_and_payment_ledger_comparison/test_general_and_payment_ledger_comparison.py b/erpnext/accounts/report/general_and_payment_ledger_comparison/test_general_and_payment_ledger_comparison.py index 8c33bc90965..dd836a6891e 100644 --- a/erpnext/accounts/report/general_and_payment_ledger_comparison/test_general_and_payment_ledger_comparison.py +++ b/erpnext/accounts/report/general_and_payment_ledger_comparison/test_general_and_payment_ledger_comparison.py @@ -1,6 +1,5 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice @@ -8,16 +7,14 @@ from erpnext.accounts.report.general_and_payment_ledger_comparison.general_and_p execute, ) from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestGeneralAndPaymentLedger(IntegrationTestCase, AccountsTestMixin): +class TestGeneralAndPaymentLedger(ERPNextTestSuite, AccountsTestMixin): def setUp(self): self.create_company() self.cleanup() - def tearDown(self): - frappe.db.rollback() - def cleanup(self): doctypes = [] doctypes.append(qb.DocType("GL Entry")) diff --git a/erpnext/accounts/report/general_ledger/test_general_ledger.py b/erpnext/accounts/report/general_ledger/test_general_ledger.py index 24280d4d620..8f558467192 100644 --- a/erpnext/accounts/report/general_ledger/test_general_ledger.py +++ b/erpnext/accounts/report/general_ledger/test_general_ledger.py @@ -3,15 +3,15 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import flt, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.general_ledger.general_ledger import execute from erpnext.controllers.sales_and_purchase_return import make_return_doc +from erpnext.tests.utils import ERPNextTestSuite -class TestGeneralLedger(IntegrationTestCase): +class TestGeneralLedger(ERPNextTestSuite): def setUp(self): self.company = "_Test Company" self.clear_old_entries() diff --git a/erpnext/accounts/report/gross_profit/test_gross_profit.py b/erpnext/accounts/report/gross_profit/test_gross_profit.py index bf52e127544..ac1ca89b5e4 100644 --- a/erpnext/accounts/report/gross_profit/test_gross_profit.py +++ b/erpnext/accounts/report/gross_profit/test_gross_profit.py @@ -1,6 +1,5 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, get_first_day, get_last_day, nowdate from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_delivery_note, make_sales_return @@ -10,9 +9,10 @@ from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestGrossProfit(IntegrationTestCase): +class TestGrossProfit(ERPNextTestSuite): def setUp(self): self.create_company() self.create_item() @@ -21,9 +21,6 @@ class TestGrossProfit(IntegrationTestCase): self.create_sales_invoice() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_company(self): company_name = "_Test Gross Profit" abbr = "_GP" @@ -391,6 +388,7 @@ class TestGrossProfit(IntegrationTestCase): report_output = {k: v for k, v in gp_entry[0].items() if k in expected_entry} self.assertEqual(report_output, expected_entry) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_crnote_against_invoice_with_multiple_instances_of_same_item(self): """ Item Qty for Sales Invoices with multiple instances of same item go in the -ve. Ideally, the credit noteshould cancel out the invoice items. diff --git a/erpnext/accounts/report/item_wise_purchase_register/test_item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/test_item_wise_purchase_register.py index 5a2fe7e23ce..eed45ea60bb 100644 --- a/erpnext/accounts/report/item_wise_purchase_register/test_item_wise_purchase_register.py +++ b/erpnext/accounts/report/item_wise_purchase_register/test_item_wise_purchase_register.py @@ -1,21 +1,18 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate, today from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.report.item_wise_purchase_register.item_wise_purchase_register import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestItemWisePurchaseRegister(AccountsTestMixin, IntegrationTestCase): +class TestItemWisePurchaseRegister(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_supplier() self.create_item() - def tearDown(self): - frappe.db.rollback() - def create_purchase_invoice(self, do_not_submit=False): pi = make_purchase_invoice( item=self.item, diff --git a/erpnext/accounts/report/item_wise_sales_register/test_item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/test_item_wise_sales_register.py index 09a2b4a46d6..689edeac1c4 100644 --- a/erpnext/accounts/report/item_wise_sales_register/test_item_wise_sales_register.py +++ b/erpnext/accounts/report/item_wise_sales_register/test_item_wise_sales_register.py @@ -1,21 +1,18 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.item_wise_sales_register.item_wise_sales_register import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestItemWiseSalesRegister(AccountsTestMixin, IntegrationTestCase): +class TestItemWiseSalesRegister(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, item=None, taxes=None, do_not_submit=False): si = create_sales_invoice( item=item or self.item, @@ -79,9 +76,13 @@ class TestItemWiseSalesRegister(AccountsTestMixin, IntegrationTestCase): self.assertDictEqual(report_output, expected_result) def test_grouped_report_handles_different_tax_descriptions(self): - self.create_item(item_name="_Test Item Tax Description A") + self.create_item( + item_name="_Test Item Tax Description A", company="_Test Company", warehouse="Stores - _TC" + ) first_item = self.item - self.create_item(item_name="_Test Item Tax Description B") + self.create_item( + item_name="_Test Item Tax Description B", company="_Test Company", warehouse="Stores - _TC" + ) second_item = self.item first_tax_description = "Tax Description A" diff --git a/erpnext/accounts/report/payment_ledger/test_payment_ledger.py b/erpnext/accounts/report/payment_ledger/test_payment_ledger.py index 1225fb70101..00206059672 100644 --- a/erpnext/accounts/report/payment_ledger/test_payment_ledger.py +++ b/erpnext/accounts/report/payment_ledger/test_payment_ledger.py @@ -1,13 +1,13 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.payment_ledger.payment_ledger import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentLedger(IntegrationTestCase): +class TestPaymentLedger(ERPNextTestSuite): def setUp(self): self.create_company() self.cleanup() diff --git a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py index 4f1a08370a4..90d28033f19 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py @@ -3,24 +3,21 @@ import frappe from frappe.desk.query_report import export_query -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, getdate, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.financial_statements import get_period_list from erpnext.accounts.report.profit_and_loss_statement.profit_and_loss_statement import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestProfitAndLossStatement(AccountsTestMixin, IntegrationTestCase): +class TestProfitAndLossStatement(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, qty=1, rate=150, no_payment_schedule=False, do_not_submit=False): frappe.set_user("Administrator") si = create_sales_invoice( diff --git a/erpnext/accounts/report/purchase_register/test_purchase_register.py b/erpnext/accounts/report/purchase_register/test_purchase_register.py index 6f61c44db02..400ee899fa1 100644 --- a/erpnext/accounts/report/purchase_register/test_purchase_register.py +++ b/erpnext/accounts/report/purchase_register/test_purchase_register.py @@ -2,13 +2,13 @@ # MIT License. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, today from erpnext.accounts.report.purchase_register.purchase_register import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseRegister(IntegrationTestCase): +class TestPurchaseRegister(ERPNextTestSuite): def test_purchase_register(self): frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company 6'") frappe.db.sql("delete from `tabGL Entry` where company='_Test Company 6'") diff --git a/erpnext/accounts/report/sales_payment_summary/test_sales_payment_summary.py b/erpnext/accounts/report/sales_payment_summary/test_sales_payment_summary.py index 481e9381ff1..da4b78f6987 100644 --- a/erpnext/accounts/report/sales_payment_summary/test_sales_payment_summary.py +++ b/erpnext/accounts/report/sales_payment_summary/test_sales_payment_summary.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -11,25 +10,10 @@ from erpnext.accounts.report.sales_payment_summary.sales_payment_summary import get_mode_of_payment_details, get_mode_of_payments, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Sales Invoice"] +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesPaymentSummary(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - create_records() - pes = frappe.get_all("Payment Entry") - jes = frappe.get_all("Journal Entry") - sis = frappe.get_all("Sales Invoice") - for pe in pes: - frappe.db.set_value("Payment Entry", pe.name, "docstatus", 2) - for je in jes: - frappe.db.set_value("Journal Entry", je.name, "docstatus", 2) - for si in sis: - frappe.db.set_value("Sales Invoice", si.name, "docstatus", 2) - +class TestSalesPaymentSummary(ERPNextTestSuite): def test_get_mode_of_payments(self): filters = get_filters() @@ -95,6 +79,7 @@ class TestSalesPaymentSummary(IntegrationTestCase): mopd = get_mode_of_payment_details(filters) mopd_values = next(iter(mopd.values())) + cc_init_amount = 0 for mopd_value in mopd_values: if mopd_value[0] == "Credit Card": cc_init_amount = mopd_value[1] @@ -111,6 +96,7 @@ class TestSalesPaymentSummary(IntegrationTestCase): mopd = get_mode_of_payment_details(filters) mopd_values = next(iter(mopd.values())) + cc_final_amount = 0 for mopd_value in mopd_values: if mopd_value[0] == "Credit Card": cc_final_amount = mopd_value[1] @@ -148,41 +134,3 @@ def create_sales_invoice_record(qty=1): ], } ) - - -def create_records(): - if frappe.db.exists("Customer", "Prestiga-Biz"): - return - - # customer - frappe.get_doc( - { - "customer_group": "_Test Customer Group", - "customer_name": "Prestiga-Biz", - "customer_type": "Company", - "doctype": "Customer", - "territory": "_Test Territory", - } - ).insert() - - # item - item = frappe.get_doc( - { - "doctype": "Item", - "item_code": "Consulting", - "item_name": "Consulting", - "item_group": "All Item Groups", - "company": "_Test Company", - "is_stock_item": 0, - } - ).insert() - - # item price - frappe.get_doc( - { - "doctype": "Item Price", - "price_list": "Standard Selling", - "item_code": item.item_code, - "price_list_rate": 10000, - } - ).insert() diff --git a/erpnext/accounts/report/sales_register/test_sales_register.py b/erpnext/accounts/report/sales_register/test_sales_register.py index 50f12e52e33..ca284cc636c 100644 --- a/erpnext/accounts/report/sales_register/test_sales_register.py +++ b/erpnext/accounts/report/sales_register/test_sales_register.py @@ -1,22 +1,19 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.sales_register.sales_register import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestItemWiseSalesRegister(AccountsTestMixin, IntegrationTestCase): +class TestItemWiseSalesRegister(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() self.create_child_cost_center() - def tearDown(self): - frappe.db.rollback() - def create_child_cost_center(self): cc_name = "South Wing" if frappe.db.exists("Cost Center", cc_name): diff --git a/erpnext/accounts/report/supplier_ledger_summary/test_supplier_ledger_summary.py b/erpnext/accounts/report/supplier_ledger_summary/test_supplier_ledger_summary.py index 376495b5cc9..418d86abb66 100644 --- a/erpnext/accounts/report/supplier_ledger_summary/test_supplier_ledger_summary.py +++ b/erpnext/accounts/report/supplier_ledger_summary/test_supplier_ledger_summary.py @@ -1,22 +1,19 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.report.supplier_ledger_summary.supplier_ledger_summary import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierLedgerSummary(AccountsTestMixin, IntegrationTestCase): +class TestSupplierLedgerSummary(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_supplier() self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_purchase_invoice(self, do_not_submit=False): frappe.set_user("Administrator") pi = make_purchase_invoice( diff --git a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py index 30a5df3fcb2..a2a732e8de6 100644 --- a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py +++ b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py @@ -2,7 +2,6 @@ # MIT License. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_to_date, today from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry @@ -14,9 +13,10 @@ from erpnext.accounts.doctype.tax_withholding_category.test_tax_withholding_cate from erpnext.accounts.report.tax_withholding_details.tax_withholding_details import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.utils import get_fiscal_year +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxWithholdingDetails(AccountsTestMixin, IntegrationTestCase): +class TestTaxWithholdingDetails(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.clear_old_entries() @@ -126,9 +126,6 @@ class TestTaxWithholdingDetails(AccountsTestMixin, IntegrationTestCase): ) self.assertSequenceEqual(voucher_actual_values, voucher_expected_values) - def tearDown(self): - self.clear_old_entries() - def create_tax_accounts(): account_names = ["TCS", "TDS"] diff --git a/erpnext/accounts/report/trial_balance/test_trial_balance.py b/erpnext/accounts/report/trial_balance/test_trial_balance.py index a7922b716e7..42cf62af0a0 100644 --- a/erpnext/accounts/report/trial_balance/test_trial_balance.py +++ b/erpnext/accounts/report/trial_balance/test_trial_balance.py @@ -2,13 +2,13 @@ # MIT License. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.report.trial_balance.trial_balance import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestTrialBalance(IntegrationTestCase): +class TestTrialBalance(ERPNextTestSuite): def setUp(self): from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center @@ -62,10 +62,6 @@ class TestTrialBalance(IntegrationTestCase): total_row = execute(filters)[1][-1] self.assertEqual(total_row["debit"], total_row["credit"]) - def tearDown(self): - clear_dimension_defaults("Branch") - disable_dimension() - def create_company(**args): args = frappe._dict(args) diff --git a/erpnext/accounts/test/test_reports.py b/erpnext/accounts/test/test_reports.py index c58269dde23..8c27452264c 100644 --- a/erpnext/accounts/test/test_reports.py +++ b/erpnext/accounts/test/test_reports.py @@ -1,8 +1,4 @@ -import unittest - -from frappe.tests import IntegrationTestCase - -from erpnext.tests.utils import ReportFilters, ReportName, execute_script_report +from erpnext.tests.utils import ERPNextTestSuite, ReportFilters, ReportName, execute_script_report DEFAULT_FILTERS = { "company": "_Test Company", @@ -36,7 +32,7 @@ REPORT_FILTER_TEST_CASES: list[tuple[ReportName, ReportFilters]] = [ OPTIONAL_FILTERS = {} -class TestReports(IntegrationTestCase): +class TestReports(ERPNextTestSuite): def test_execute_all_accounts_reports(self): """Test that all script report in stock modules are executable with supported filters""" for report, filter in REPORT_FILTER_TEST_CASES: diff --git a/erpnext/accounts/test/test_utils.py b/erpnext/accounts/test/test_utils.py index fd2dc61096e..eddd30b68b6 100644 --- a/erpnext/accounts/test/test_utils.py +++ b/erpnext/accounts/test/test_utils.py @@ -2,7 +2,6 @@ import unittest import frappe from frappe.test_runner import make_test_objects -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice @@ -16,18 +15,10 @@ from erpnext.accounts.utils import ( from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestUtils(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - make_test_objects("Address", ADDRESS_RECORDS) - - @classmethod - def tearDownClass(cls): - frappe.db.rollback() - +class TestUtils(ERPNextTestSuite): def test_get_party_shipping_address(self): address = get_party_shipping_address("Customer", "_Test Customer 1") self.assertEqual(address, "_Test Billing Address 2 Title-Billing") @@ -162,45 +153,3 @@ class TestUtils(IntegrationTestCase): self.assertEqual(get_zero_cutoff(None), 0.005) self.assertEqual(get_zero_cutoff("EUR"), 0.005) self.assertEqual(get_zero_cutoff("BHD"), 0.0005) - - -ADDRESS_RECORDS = [ - { - "doctype": "Address", - "address_type": "Billing", - "address_line1": "Address line 1", - "address_title": "_Test Billing Address Title", - "city": "Lagos", - "country": "Nigeria", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}], - }, - { - "doctype": "Address", - "address_type": "Shipping", - "address_line1": "Address line 2", - "address_title": "_Test Shipping Address 1 Title", - "city": "Lagos", - "country": "Nigeria", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}], - }, - { - "doctype": "Address", - "address_type": "Shipping", - "address_line1": "Address line 3", - "address_title": "_Test Shipping Address 2 Title", - "city": "Lagos", - "country": "Nigeria", - "is_shipping_address": "1", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}], - }, - { - "doctype": "Address", - "address_type": "Billing", - "address_line1": "Address line 4", - "address_title": "_Test Billing Address 2 Title", - "city": "Lagos", - "country": "Nigeria", - "is_shipping_address": "1", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}], - }, -] diff --git a/erpnext/accounts/test_party.py b/erpnext/accounts/test_party.py index 986a5b5d680..0f477103da4 100644 --- a/erpnext/accounts/test_party.py +++ b/erpnext/accounts/test_party.py @@ -1,10 +1,10 @@ import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.party import get_default_price_list +from erpnext.tests.utils import ERPNextTestSuite -class PartyTestCase(IntegrationTestCase): +class PartyTestCase(ERPNextTestSuite): def test_get_default_price_list_should_return_none_for_invalid_group(self): customer = frappe.get_doc( { diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 95011c8bba1..6954a1d752d 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -598,9 +598,7 @@ class Asset(AccountsController): def set_depreciation_rate(self): for d in self.get("finance_books"): self.validate_asset_finance_books(d) - d.rate_of_depreciation = flt( - self.get_depreciation_rate(d, on_validate=True), d.precision("rate_of_depreciation") - ) + d.rate_of_depreciation = self.get_depreciation_rate(d, on_validate=True) def validate_asset_finance_books(self, row): row.expected_value_after_useful_life = flt( @@ -990,7 +988,7 @@ class Asset(AccountsController): if isinstance(args, str): args = json.loads(args) - rate_field_precision = frappe.get_precision(args.doctype, "rate_of_depreciation") or 2 + rate_field_precision = frappe.get_single_value("System Settings", "float_precision") or 2 if args.get("depreciation_method") == "Double Declining Balance": return self.get_double_declining_balance_rate(args, rate_field_precision) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 6440fcfad62..852a28f9948 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import ( add_days, add_months, @@ -37,21 +36,14 @@ from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as make_invoice, ) from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class AssetSetup(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class AssetSetup(ERPNextTestSuite): + def setUp(self): set_depreciation_settings_in_company() - create_asset_data() enable_cwip_accounting("Computers") make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") - frappe.db.sql("delete from `tabTax Rule`") - - @classmethod - def tearDownClass(cls): - frappe.db.rollback() class TestAsset(AssetSetup): @@ -826,6 +818,9 @@ class TestAsset(AssetSetup): class TestDepreciationMethods(AssetSetup): + def setUp(self): + frappe.db.set_single_value("System Settings", "float_precision", 2) + def test_schedule_for_straight_line_method(self): asset = create_asset( calculate_depreciation=1, @@ -923,9 +918,9 @@ class TestDepreciationMethods(AssetSetup): self.assertEqual(asset.status, "Draft") expected_schedules = [ - ["2030-12-31", 66667.00, 66667.00], - ["2031-12-31", 22222.11, 88889.11], - ["2032-12-31", 1110.89, 90000.0], + ["2030-12-31", 66670.0, 66670.0], + ["2031-12-31", 22221.11, 88891.11], + ["2032-12-31", 1108.89, 90000.0], ] schedules = [ @@ -951,7 +946,7 @@ class TestDepreciationMethods(AssetSetup): self.assertEqual(asset.status, "Draft") - expected_schedules = [["2031-12-31", 33333.50, 83333.50], ["2032-12-31", 6666.50, 90000.0]] + expected_schedules = [["2031-12-31", 33335.0, 83335.0], ["2032-12-31", 6665.0, 90000.0]] schedules = [ [cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] @@ -1069,12 +1064,12 @@ class TestDepreciationMethods(AssetSetup): ) expected_schedules = [ - ["2022-02-28", 337.72, 337.72], - ["2022-03-31", 675.45, 1013.17], - ["2022-04-30", 675.45, 1688.62], - ["2022-05-31", 675.45, 2364.07], - ["2022-06-30", 675.45, 3039.52], - ["2022-07-15", 1960.48, 5000.0], + ["2022-02-28", 337.71, 337.71], + ["2022-03-31", 675.42, 1013.13], + ["2022-04-30", 675.42, 1688.55], + ["2022-05-31", 675.42, 2363.97], + ["2022-06-30", 675.42, 3039.39], + ["2022-07-15", 1960.61, 5000.0], ] schedules = [ @@ -1894,31 +1889,9 @@ def get_gl_entries(doctype, docname): ) -def create_asset_data(): - if not frappe.db.exists("Asset Category", "Computers"): - create_asset_category() - - if not frappe.db.exists("Item", "Macbook Pro"): - create_fixed_asset_item() - - if not frappe.db.exists("Location", "Test Location"): - frappe.get_doc({"doctype": "Location", "location_name": "Test Location"}).insert() - - if not frappe.db.exists("Finance Book", "Test Finance Book 1"): - frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 1"}).insert() - - if not frappe.db.exists("Finance Book", "Test Finance Book 2"): - frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 2"}).insert() - - if not frappe.db.exists("Finance Book", "Test Finance Book 3"): - frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 3"}).insert() - - def create_asset(**args): args = frappe._dict(args) - create_asset_data() - asset = frappe.get_doc( { "doctype": "Asset", diff --git a/erpnext/assets/doctype/asset_activity/test_asset_activity.py b/erpnext/assets/doctype/asset_activity/test_asset_activity.py index 1c7d472c88b..0344c7d984b 100644 --- a/erpnext/assets/doctype/asset_activity/test_asset_activity.py +++ b/erpnext/assets/doctype/asset_activity/test_asset_activity.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestAssetActivity(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestAssetActivity(ERPNextTestSuite): pass diff --git a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py index 914b87b728f..f245ac4f0a2 100644 --- a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py @@ -3,13 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import cint, flt, getdate, now_datetime +from frappe.utils import cint, flt, now_datetime from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries from erpnext.assets.doctype.asset.test_asset import ( create_asset, - create_asset_data, create_fixed_asset_item, set_depreciation_settings_in_company, ) @@ -21,12 +19,12 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_pu from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle import ( make_serial_batch_bundle, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetCapitalization(IntegrationTestCase): +class TestAssetCapitalization(ERPNextTestSuite): def setUp(self): set_depreciation_settings_in_company() - create_asset_data() create_asset_capitalization_data() frappe.db.sql("delete from `tabTax Rule`") diff --git a/erpnext/assets/doctype/asset_category/test_asset_category.py b/erpnext/assets/doctype/asset_category/test_asset_category.py index 0f903c7f03a..9f1e6821b43 100644 --- a/erpnext/assets/doctype/asset_category/test_asset_category.py +++ b/erpnext/assets/doctype/asset_category/test_asset_category.py @@ -3,10 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.assets.doctype.asset.test_asset import create_asset +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetCategory(IntegrationTestCase): +class TestAssetCategory(ERPNextTestSuite): def test_mandatory_fields(self): asset_category = frappe.new_doc("Asset Category") asset_category.asset_category_name = "Computers" diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py index 824c7cbba1f..449f6091d01 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py @@ -2,14 +2,13 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import cstr, date_diff, flt, getdate +from frappe.utils import cstr, flt, getdate from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.assets.doctype.asset.depreciation import ( post_depreciation_entries, ) -from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data +from erpnext.assets.doctype.asset.test_asset import create_asset from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( get_asset_depr_schedule_doc, get_depr_schedule, @@ -18,12 +17,10 @@ from erpnext.assets.doctype.asset_repair.test_asset_repair import create_asset_r from erpnext.assets.doctype.asset_value_adjustment.test_asset_value_adjustment import ( make_asset_value_adjustment, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetDepreciationSchedule(IntegrationTestCase): - def setUp(self): - create_asset_data() - +class TestAssetDepreciationSchedule(ERPNextTestSuite): def test_throw_error_if_another_asset_depr_schedule_exist(self): asset = create_asset(item_code="Macbook Pro", calculate_depreciation=1, submit=1) @@ -815,7 +812,6 @@ class TestAssetDepreciationSchedule(IntegrationTestCase): def test_depreciation_on_return_of_sold_asset(self): from erpnext.controllers.sales_and_purchase_return import make_return_doc - create_asset_data() asset = create_asset(item_code="Macbook Pro", calculate_depreciation=1, submit=1) post_depreciation_entries(getdate("2021-09-30")) diff --git a/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py b/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py index 391872c8438..7077789e387 100644 --- a/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py +++ b/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py @@ -3,14 +3,14 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, get_last_day, nowdate from erpnext.assets.doctype.asset_maintenance.asset_maintenance import calculate_next_due_date from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetMaintenance(IntegrationTestCase): +class TestAssetMaintenance(ERPNextTestSuite): def setUp(self): set_depreciation_settings_in_company() self.pr = make_purchase_receipt( diff --git a/erpnext/assets/doctype/asset_maintenance/test_records.json b/erpnext/assets/doctype/asset_maintenance/test_records.json deleted file mode 100644 index 8306fad6cba..00000000000 --- a/erpnext/assets/doctype/asset_maintenance/test_records.json +++ /dev/null @@ -1,68 +0,0 @@ -[ - { - "doctype": "Asset Category", - "asset_category_name": "Equipment", - "total_number_of_depreciations": 3, - "frequency_of_depreciation": 3, - "accounts": [ - { - "company_name": "_Test Company", - "fixed_asset_account": "_Test Fixed Asset - _TC", - "accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC", - "depreciation_expense_account": "_Test Depreciations - _TC" - } - ] - }, - { - "doctype": "Location", - "location_name": "Test Location" - }, - { - "doctype": "Role", - "role_name": "Technician" - }, - { - "doctype": "User", - "email": "marcus@abc.com", - "first_name": "marcus@abc.com", - "new_password": "password", - "roles": [{"doctype": "Has Role", "role": "Technician"}] - }, - { - "doctype": "User", - "email": "thalia@abc.com", - "first_name": "thalia@abc.com", - "new_password": "password", - "roles": [{"doctype": "Has Role", "role": "Technician"}] - }, - { - "doctype": "User", - "email": "mathias@abc.com", - "first_name": "mathias@abc.com", - "new_password": "password", - "roles": [{"doctype": "Has Role", "role": "Technician"}] - }, - { - "doctype": "Asset Maintenance Team", - "maintenance_manager": "marcus@abc.com", - "maintenance_team_name": "Team Awesome", - "company": "_Test Company", - "maintenance_team_members": [ - {"team_member": "marcus@abc.com", "full_name": "marcus@abc.com", "maintenance_role": "Technician"}, - {"team_member": "thalia@abc.com", "full_name": "thalia@abc.com", "maintenance_role": "Technician"}, - {"team_member": "mathias@abc.com", "full_name": "mathias@abc.com", "maintenance_role": "Technician"} - ] - }, - { - "doctype": "Item", - "item_code": "Photocopier", - "item_name": "Photocopier", - "item_group": "All Item Groups", - "company": "_Test Company", - "is_fixed_asset": 1, - "is_stock_item": 0, - "asset_category": "Equipment", - "auto_create_assets": 1, - "asset_naming_series": "ABC.###" - } -] diff --git a/erpnext/assets/doctype/asset_maintenance_log/test_asset_maintenance_log.py b/erpnext/assets/doctype/asset_maintenance_log/test_asset_maintenance_log.py index 6d19f5b17d9..e5f421c94ed 100644 --- a/erpnext/assets/doctype/asset_maintenance_log/test_asset_maintenance_log.py +++ b/erpnext/assets/doctype/asset_maintenance_log/test_asset_maintenance_log.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetMaintenanceLog(IntegrationTestCase): +class TestAssetMaintenanceLog(ERPNextTestSuite): pass diff --git a/erpnext/assets/doctype/asset_maintenance_team/test_asset_maintenance_team.py b/erpnext/assets/doctype/asset_maintenance_team/test_asset_maintenance_team.py index 00441a8368a..6def5ed28b9 100644 --- a/erpnext/assets/doctype/asset_maintenance_team/test_asset_maintenance_team.py +++ b/erpnext/assets/doctype/asset_maintenance_team/test_asset_maintenance_team.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetMaintenanceTeam(IntegrationTestCase): +class TestAssetMaintenanceTeam(ERPNextTestSuite): pass diff --git a/erpnext/assets/doctype/asset_movement/test_asset_movement.py b/erpnext/assets/doctype/asset_movement/test_asset_movement.py index 0cceb011a25..88dd93a93cb 100644 --- a/erpnext/assets/doctype/asset_movement/test_asset_movement.py +++ b/erpnext/assets/doctype/asset_movement/test_asset_movement.py @@ -3,20 +3,19 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, now -from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data +from erpnext.assets.doctype.asset.test_asset import create_asset from erpnext.setup.doctype.employee.test_employee import make_employee from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetMovement(IntegrationTestCase): +class TestAssetMovement(ERPNextTestSuite): def setUp(self): frappe.db.set_value( "Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC" ) - create_asset_data() make_location() def test_movement(self): diff --git a/erpnext/assets/doctype/asset_repair/test_asset_repair.py b/erpnext/assets/doctype/asset_repair/test_asset_repair.py index c56622d6665..1f158e1ea8b 100644 --- a/erpnext/assets/doctype/asset_repair/test_asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/test_asset_repair.py @@ -5,7 +5,6 @@ import unittest import frappe from frappe import qb from frappe.query_builder.functions import Sum -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_months, flt, get_first_day, nowdate, nowtime, today from erpnext.assets.doctype.asset.asset import ( @@ -15,7 +14,6 @@ from erpnext.assets.doctype.asset.asset import ( ) from erpnext.assets.doctype.asset.test_asset import ( create_asset, - create_asset_data, set_depreciation_settings_in_company, ) from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( @@ -26,16 +24,14 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle get_serial_nos_from_bundle, make_serial_batch_bundle, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetRepair(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestAssetRepair(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Stock Entry") set_depreciation_settings_in_company() - create_asset_data() create_item("_Test Stock Item") - frappe.db.sql("delete from `tabTax Rule`") def test_asset_status(self): date = nowdate() diff --git a/erpnext/assets/doctype/asset_shift_allocation/test_asset_shift_allocation.py b/erpnext/assets/doctype/asset_shift_allocation/test_asset_shift_allocation.py index 2764a2cc373..5b1cdaf0277 100644 --- a/erpnext/assets/doctype/asset_shift_allocation/test_asset_shift_allocation.py +++ b/erpnext/assets/doctype/asset_shift_allocation/test_asset_shift_allocation.py @@ -2,25 +2,19 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import cstr from erpnext.assets.doctype.asset.test_asset import create_asset from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( get_depr_schedule, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetShiftAllocation(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestAssetShiftAllocation(ERPNextTestSuite): + def setUp(self): create_asset_shift_factors() - @classmethod - def tearDownClass(cls): - frappe.db.rollback() - def test_asset_shift_allocation(self): asset = create_asset( calculate_depreciation=1, diff --git a/erpnext/assets/doctype/asset_shift_factor/test_asset_shift_factor.py b/erpnext/assets/doctype/asset_shift_factor/test_asset_shift_factor.py index 12d68b02c5f..7470e55b6fb 100644 --- a/erpnext/assets/doctype/asset_shift_factor/test_asset_shift_factor.py +++ b/erpnext/assets/doctype/asset_shift_factor/test_asset_shift_factor.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestAssetShiftFactor(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestAssetShiftFactor(ERPNextTestSuite): pass diff --git a/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py b/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py index 1425bb9aa78..4fb9b0a67f6 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py +++ b/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py @@ -3,22 +3,20 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, cstr, get_last_day, getdate, nowdate from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries -from erpnext.assets.doctype.asset.test_asset import create_asset_data from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( get_asset_depr_schedule_doc, ) from erpnext.assets.doctype.asset_repair.test_asset_repair import create_asset_repair from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetValueAdjustment(IntegrationTestCase): +class TestAssetValueAdjustment(ERPNextTestSuite): def setUp(self): - create_asset_data() frappe.db.set_value( "Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC" ) diff --git a/erpnext/assets/doctype/location/location.py b/erpnext/assets/doctype/location/location.py index 03d0980b03f..684a15860cd 100644 --- a/erpnext/assets/doctype/location/location.py +++ b/erpnext/assets/doctype/location/location.py @@ -77,7 +77,7 @@ class Location(NestedSet): location = json.loads(self.location) location["features"] = features - self.db_set("location", json.dumps(location), commit=True) + self.db_set("location", json.dumps(location)) def update_ancestor_location_features(self): self_features = set(self.add_child_property()) @@ -105,7 +105,7 @@ class Location(NestedSet): ancestor_features[index] = json.loads(feature) ancestor_doc.set_location_features(features=ancestor_features) - ancestor_doc.db_set("area", ancestor_doc.area + self.area_difference, commit=True) + ancestor_doc.db_set("area", ancestor_doc.area + self.area_difference) def remove_ancestor_location_features(self): for ancestor in self.get_ancestors(): @@ -116,7 +116,7 @@ class Location(NestedSet): ancestor_features[index] = json.loads(feature) ancestor_doc.set_location_features(features=ancestor_features) - ancestor_doc.db_set("area", ancestor_doc.area - self.area, commit=True) + ancestor_doc.db_set("area", ancestor_doc.area - self.area) def add_child_property(self): features = self.get_location_features() diff --git a/erpnext/assets/doctype/location/test_location.py b/erpnext/assets/doctype/location/test_location.py index 8de97138f7b..1222def606e 100644 --- a/erpnext/assets/doctype/location/test_location.py +++ b/erpnext/assets/doctype/location/test_location.py @@ -4,11 +4,12 @@ import json import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestLocation(IntegrationTestCase): - def runTest(self): +class TestLocation(ERPNextTestSuite): + def test_location_features(self): locations = ["Basil Farm", "Division 1", "Field 1", "Block 1"] area = 0 formatted_locations = [] diff --git a/erpnext/assets/doctype/location/test_records.json b/erpnext/assets/doctype/location/test_records.json deleted file mode 100644 index 8a89cf8bdd3..00000000000 --- a/erpnext/assets/doctype/location/test_records.json +++ /dev/null @@ -1,44 +0,0 @@ -[ - { - "doctype": "Location", - "location_name": "Test Location Area", - "is_group": 1, - "is_container": 1 - }, - { - "doctype": "Location", - "location_name": "Basil Farm", - "location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"point_type\":\"circle\",\"radius\":884.5625420736483},\"geometry\":{\"type\":\"Point\",\"coordinates\":[72.875834,19.100566]}}]}", - "parent_location": "Test Location Area", - "parent": "Test Location Area", - "is_group": 1, - "is_container": 1 - }, - { - "doctype": "Location", - "location_name": "Division 1", - "location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"point_type\":\"circle\",\"radius\":542.3424997060739},\"geometry\":{\"type\":\"Point\",\"coordinates\":[72.852359,19.11557]}}]}", - "parent_location": "Basil Farm", - "parent": "Basil Farm", - "is_group": 1, - "is_container": 1 - }, - { - "doctype": "Location", - "location_name": "Field 1", - "location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[72.846758,19.118287],[72.846758,19.121206],[72.850535,19.121206],[72.850535,19.118287],[72.846758,19.118287]]]}}]}", - "parent_location": "Division 1", - "parent": "Division 1", - "is_group": 1, - "is_container": 1 - }, - { - "doctype": "Location", - "location_name": "Block 1", - "location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[72.921495,19.073313],[72.924929,19.068121],[72.934713,19.06585],[72.929392,19.05579],[72.94158,19.056926],[72.951365,19.095213],[72.921495,19.073313]]]}}]}", - "parent_location": "Field 1", - "parent": "Field 1", - "is_group": 0, - "is_container": 1 - } -] \ No newline at end of file diff --git a/erpnext/assets/doctype/maintenance_team_member/test_maintenance_team_member.py b/erpnext/assets/doctype/maintenance_team_member/test_maintenance_team_member.py index a4795c54a56..b53649b822d 100644 --- a/erpnext/assets/doctype/maintenance_team_member/test_maintenance_team_member.py +++ b/erpnext/assets/doctype/maintenance_team_member/test_maintenance_team_member.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestMaintenanceTeamMember(IntegrationTestCase): +class TestMaintenanceTeamMember(ERPNextTestSuite): pass diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py index 66e6456d103..e3909ea619a 100644 --- a/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestBulkTransactionLog(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestBulkTransactionLog(ERPNextTestSuite): pass diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/test_bulk_transaction_log_detail.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/test_bulk_transaction_log_detail.py index 6b9b4637ab4..ae35c697c31 100644 --- a/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/test_bulk_transaction_log_detail.py +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/test_bulk_transaction_log_detail.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestBulkTransactionLogDetail(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestBulkTransactionLogDetail(ERPNextTestSuite): pass diff --git a/erpnext/buying/doctype/buying_settings/test_buying_settings.py b/erpnext/buying/doctype/buying_settings/test_buying_settings.py index 04f95dbe745..c583ad6875e 100644 --- a/erpnext/buying/doctype/buying_settings/test_buying_settings.py +++ b/erpnext/buying/doctype/buying_settings/test_buying_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBuyingSettings(IntegrationTestCase): +class TestBuyingSettings(ERPNextTestSuite): pass diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index aaace54db63..a0daeca51f2 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -889,7 +889,7 @@ def get_list_context(context=None): @frappe.whitelist() def update_status(status, name): - po = frappe.get_lazy_doc("Purchase Order", name) + po = frappe.get_lazy_doc("Purchase Order", name, check_permission="submit") po.update_status(status) po.update_delivered_qty_in_sales_order() diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index f533af61b9e..fe4bb12c3db 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -5,7 +5,7 @@ import json import frappe -from frappe.tests import IntegrationTestCase, change_settings +from frappe.tests import change_settings from frappe.utils import add_days, flt, getdate, nowdate from frappe.utils.data import today @@ -26,9 +26,11 @@ from erpnext.stock.doctype.material_request.test_material_request import make_ma from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as make_pi_from_pr, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseOrder(IntegrationTestCase): +class TestPurchaseOrder(ERPNextTestSuite): + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": 1}) def test_purchase_order_qty(self): po = create_purchase_order(qty=1, do_not_save=True) @@ -540,7 +542,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertRaises(frappe.ValidationError, pr.submit) self.assertRaises(frappe.ValidationError, pi.submit) - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) def test_make_purchase_invoice_with_terms(self): po = create_purchase_order(do_not_save=True) @@ -712,7 +714,7 @@ class TestPurchaseOrder(IntegrationTestCase): ) self.assertEqual(due_date, "2023-03-31") - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 0}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 0}) def test_terms_are_not_copied_if_automatically_fetch_payment_terms_is_unchecked(self): po = create_purchase_order(do_not_save=1) po.payment_terms_template = "_Test Payment Term Template" @@ -737,7 +739,7 @@ class TestPurchaseOrder(IntegrationTestCase): pi.insert() self.assertTrue(pi.get("payment_schedule")) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"unlink_advance_payment_on_cancelation_of_order": 1} ) def test_advance_payment_entry_unlink_against_purchase_order(self): @@ -785,6 +787,7 @@ class TestPurchaseOrder(IntegrationTestCase): Test "Advance Paid" on Purchase Order, when "Book Advance Payments in Separate Party Account" is enabled and the payment entry linked to the Order is allocated to Purchase Invoice. """ + frappe.flags.is_reverse_depr_entry = False supplier = "_Test Supplier" company = "_Test Company" @@ -810,12 +813,13 @@ class TestPurchaseOrder(IntegrationTestCase): company_doc.book_advance_payments_in_separate_party_account = False company_doc.save() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"unlink_advance_payment_on_cancelation_of_order": 1} ) def test_advance_paid_upon_payment_entry_cancellation(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry + frappe.flags.is_reverse_depr_entry = False supplier = "_Test Supplier USD" company = "_Test Company" @@ -850,6 +854,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertEqual(po_doc.advance_paid, 0) self.assertEqual(po_doc.party_account_currency, "USD") + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": 1}) def test_schedule_date(self): po = create_purchase_order(do_not_submit=True) po.schedule_date = None @@ -906,7 +911,7 @@ class TestPurchaseOrder(IntegrationTestCase): bo.load_from_db() self.assertEqual(bo.items[0].ordered_qty, 5) - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( create_payment_terms_template, @@ -1145,7 +1150,7 @@ class TestPurchaseOrder(IntegrationTestCase): # Test - 8: Since this PO is now fully subcontracted, creating a new SCO from it should throw error self.assertRaises(frappe.ValidationError, make_subcontracting_order, po.name) - @IntegrationTestCase.change_settings("Buying Settings", {"auto_create_subcontracting_order": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"auto_create_subcontracting_order": 1}) def test_auto_create_subcontracting_order(self): from erpnext.controllers.tests.test_subcontracting_controller import ( make_bom_for_subcontracted_items, @@ -1178,6 +1183,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertTrue(frappe.db.get_value("Subcontracting Order", {"purchase_order": po.name})) def test_purchase_order_advance_payment_status(self): + frappe.flags.is_reverse_depr_entry = False from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request @@ -1237,7 +1243,7 @@ class TestPurchaseOrder(IntegrationTestCase): po.reload() self.assertEqual(po.per_billed, 100) - @IntegrationTestCase.change_settings("Buying Settings", {"allow_zero_qty_in_purchase_order": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_zero_qty_in_purchase_order": 1}) def test_receive_zero_qty_purchase_order(self): """ Test the flow of a Unit Price PO and PR creation against it until completion. @@ -1286,7 +1292,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertEqual(po.per_received, 100.0) self.assertEqual(po.status, "To Bill") - @IntegrationTestCase.change_settings("Buying Settings", {"allow_zero_qty_in_purchase_order": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_zero_qty_in_purchase_order": 1}) def test_bill_zero_qty_purchase_order(self): po = create_purchase_order(qty=0) @@ -1311,7 +1317,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertFalse(po.per_billed) self.assertEqual(po.status, "To Receive and Bill") - @IntegrationTestCase.change_settings("Buying Settings", {"maintain_same_rate": 0}) + @ERPNextTestSuite.change_settings("Buying Settings", {"maintain_same_rate": 0}) def test_purchase_invoice_creation_with_partial_qty(self): po = create_purchase_order(qty=100, rate=10) @@ -1331,6 +1337,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertEqual(pi.items[0].qty, 50) def test_multiple_advances_against_purchase_order_are_allocated_across_partial_purchase_invoices(self): + frappe.flags.is_reverse_depr_entry = False # step - 1: create PO po = create_purchase_order(qty=10, rate=10) @@ -1560,6 +1567,3 @@ def get_ordered_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"): def get_requested_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"): return flt(frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse}, "indented_qty")) - - -EXTRA_TEST_RECORD_DEPENDENCIES = ["BOM", "Item Price", "Warehouse"] diff --git a/erpnext/buying/doctype/purchase_order/test_records.json b/erpnext/buying/doctype/purchase_order/test_records.json deleted file mode 100644 index 4df994a68c6..00000000000 --- a/erpnext/buying/doctype/purchase_order/test_records.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "advance_paid": 0.0, - "buying_price_list": "_Test Price List", - "company": "_Test Company", - "conversion_rate": 1.0, - "currency": "INR", - "doctype": "Purchase Order", - "base_grand_total": 5000.0, - "grand_total": 5000.0, - "is_subcontracted": 0, - "naming_series": "_T-Purchase Order-", - "base_net_total": 5000.0, - "items": [ - { - "base_amount": 5000.0, - "conversion_factor": 1.0, - "description": "_Test Item", - "doctype": "Purchase Order Item", - "item_code": "_Test Item", - "item_name": "_Test Item", - "parentfield": "items", - "qty": 10.0, - "rate": 500.0, - "schedule_date": "2013-03-01", - "stock_uom": "_Test UOM", - "uom": "_Test UOM", - "warehouse": "_Test Warehouse - _TC" - } - ], - "supplier": "_Test Supplier", - "supplier_name": "_Test Supplier", - "transaction_date": "2013-02-12", - "schedule_date": "2013-02-13" - } -] diff --git a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py index 425d172629d..9201f6c4f2d 100644 --- a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py @@ -5,7 +5,7 @@ from urllib.parse import urlparse import frappe -from frappe.tests import IntegrationTestCase, change_settings +from frappe.tests import change_settings from frappe.utils import nowdate from erpnext.buying.doctype.request_for_quotation.request_for_quotation import ( @@ -19,9 +19,10 @@ from erpnext.crm.doctype.opportunity.opportunity import make_request_for_quotati from erpnext.crm.doctype.opportunity.test_opportunity import make_opportunity from erpnext.stock.doctype.item.test_item import make_item from erpnext.templates.pages.rfq import check_supplier_has_docname_access +from erpnext.tests.utils import ERPNextTestSuite -class TestRequestforQuotation(IntegrationTestCase): +class TestRequestforQuotation(ERPNextTestSuite): def test_rfq_qty(self): rfq = make_request_for_quotation(qty=0, do_not_save=True) with self.assertRaises(InvalidQtyError): @@ -222,7 +223,7 @@ class TestRequestforQuotation(IntegrationTestCase): supplier_doc.reload() self.assertTrue(supplier_doc.portal_users[0].user) - @IntegrationTestCase.change_settings("Buying Settings", {"allow_zero_qty_in_request_for_quotation": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_zero_qty_in_request_for_quotation": 1}) def test_supplier_quotation_from_zero_qty_rfq(self): rfq = make_request_for_quotation(qty=0) sq = make_supplier_quotation_from_rfq(rfq.name, for_supplier=rfq.get("suppliers")[0].supplier) @@ -231,7 +232,7 @@ class TestRequestforQuotation(IntegrationTestCase): self.assertEqual(sq.items[0].qty, 0) self.assertEqual(sq.items[0].item_code, rfq.items[0].item_code) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Buying Settings", { "allow_zero_qty_in_request_for_quotation": 1, diff --git a/erpnext/buying/doctype/supplier/test_records.json b/erpnext/buying/doctype/supplier/test_records.json deleted file mode 100644 index 1bb9899cc85..00000000000 --- a/erpnext/buying/doctype/supplier/test_records.json +++ /dev/null @@ -1,50 +0,0 @@ -[ - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier With Template 1", - "supplier_group": "_Test Supplier Group", - "payment_terms": "_Test Payment Term Template 3" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier P", - "supplier_group": "_Test Supplier Group" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier with Country", - "supplier_group": "_Test Supplier Group", - "country": "Greece" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier", - "supplier_group": "_Test Supplier Group" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier 1", - "supplier_group": "_Test Supplier Group" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier 2", - "supplier_group": "_Test Supplier Group" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier USD", - "supplier_group": "_Test Supplier Group", - "default_currency": "USD", - "accounts": [{ - "company": "_Test Company", - "account": "_Test Payable USD - _TC" - }] - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier With Tax Category", - "supplier_group": "_Test Supplier Group", - "tax_category": "_Test Tax Category 1" - } -] diff --git a/erpnext/buying/doctype/supplier/test_supplier.py b/erpnext/buying/doctype/supplier/test_supplier.py index f3f0ede3e17..663a7b48e46 100644 --- a/erpnext/buying/doctype/supplier/test_supplier.py +++ b/erpnext/buying/doctype/supplier/test_supplier.py @@ -3,18 +3,15 @@ import frappe +from frappe.tests import UnitTestCase from erpnext.accounts.party import get_due_date from erpnext.controllers.website_list_for_contact import get_customers_suppliers from erpnext.exceptions import PartyDisabled - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Payment Term", "Payment Terms Template"] +from erpnext.tests.utils import ERPNextTestSuite -from frappe.tests import IntegrationTestCase - - -class TestSupplier(IntegrationTestCase): +class TestSupplier(ERPNextTestSuite): def test_get_supplier_group_details(self): doc = frappe.new_doc("Supplier Group") doc.supplier_group_name = "_Testing Supplier Group" @@ -175,7 +172,10 @@ def create_supplier(**args): return doc -class TestSupplierPortal(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestSupplierPortal(ERPNextTestSuite): def test_portal_user_can_access_supplier_data(self): supplier = create_supplier() diff --git a/erpnext/buying/doctype/supplier_quotation/test_records.json b/erpnext/buying/doctype/supplier_quotation/test_records.json index 8acac3210d5..1b9b922e3c9 100644 --- a/erpnext/buying/doctype/supplier_quotation/test_records.json +++ b/erpnext/buying/doctype/supplier_quotation/test_records.json @@ -1,31 +1,31 @@ [ { - "buying_price_list": "_Test Price List", - "company": "_Test Company", - "conversion_rate": 1.0, - "currency": "INR", - "doctype": "Supplier Quotation", - "base_grand_total": 5000.0, - "grand_total": 5000.0, - "is_subcontracted": 0, - "naming_series": "_T-Supplier Quotation-", - "base_net_total": 5000.0, + "buying_price_list": "_Test Price List", + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "doctype": "Supplier Quotation", + "base_grand_total": 5000.0, + "grand_total": 5000.0, + "is_subcontracted": 0, + "naming_series": "_T-Supplier Quotation-", + "base_net_total": 5000.0, "items": [ { - "base_amount": 5000.0, - "description": "_Test FG Item", - "doctype": "Supplier Quotation Item", - "item_code": "_Test FG Item", - "item_name": "_Test FG Item", - "parentfield": "items", - "qty": 10.0, - "rate": 500.0, - "uom": "_Test UOM", + "base_amount": 5000.0, + "description": "_Test FG Item", + "doctype": "Supplier Quotation Item", + "item_code": "_Test FG Item", + "item_name": "_Test FG Item", + "parentfield": "items", + "qty": 10.0, + "rate": 500.0, + "uom": "_Test UOM", "warehouse": "_Test Warehouse - _TC" } - ], - "supplier": "_Test Supplier", - "supplier_name": "_Test Supplier", + ], + "supplier": "_Test Supplier", + "supplier_name": "_Test Supplier", "transaction_date": "2013-02-12" } -] \ No newline at end of file +] diff --git a/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py b/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py index 7c2714ba671..c271d34b35d 100644 --- a/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py +++ b/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py @@ -5,14 +5,18 @@ import json import frappe -from frappe.tests import IntegrationTestCase, change_settings +from frappe.tests import change_settings from frappe.utils import add_days, today from erpnext.buying.doctype.supplier_quotation.supplier_quotation import make_purchase_order from erpnext.controllers.accounts_controller import InvalidQtyError, update_child_qty_rate +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseOrder(IntegrationTestCase): +class TestPurchaseOrder(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Supplier Quotation") + def test_update_child_supplier_quotation_add_item(self): sq = frappe.copy_doc(self.globalTestRecords["Supplier Quotation"][0]) sq.submit() @@ -166,7 +170,7 @@ class TestPurchaseOrder(IntegrationTestCase): po.insert() - @IntegrationTestCase.change_settings("Buying Settings", {"allow_zero_qty_in_supplier_quotation": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_zero_qty_in_supplier_quotation": 1}) def test_map_purchase_order_from_zero_qty_supplier_quotation(self): sq = frappe.copy_doc(self.globalTestRecords["Supplier Quotation"][0]) sq.items[0].qty = 0 diff --git a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py index a1142715e2c..b42a260d017 100644 --- a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py +++ b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py @@ -266,8 +266,8 @@ def get_scorecard_date(period, start_date): return end_date -def make_default_records(): - install_variable_docs = [ +def get_default_scorecard_variables(): + return [ { "param_name": "total_accepted_items", "variable_label": "Total Accepted Items", @@ -374,7 +374,10 @@ def make_default_records(): "path": "get_invoiced_qty", }, ] - install_standing_docs = [ + + +def get_default_scorecard_standing(): + return [ { "min_grade": 0.0, "prevent_rfqs": 1, @@ -425,12 +428,17 @@ def make_default_records(): }, ] + +def make_default_records(): + install_variable_docs = get_default_scorecard_variables() for d in install_variable_docs: try: d["doctype"] = "Supplier Scorecard Variable" frappe.get_doc(d).insert() except frappe.NameError: pass + + install_standing_docs = get_default_scorecard_standing() for d in install_standing_docs: try: d["doctype"] = "Supplier Scorecard Standing" diff --git a/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py b/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py index c65ebe2086f..a1d1dfc4709 100644 --- a/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py +++ b/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py @@ -3,10 +3,11 @@ import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecard(IntegrationTestCase): +class TestSupplierScorecard(ERPNextTestSuite): def test_create_scorecard(self): doc = make_supplier_scorecard().insert() self.assertEqual(doc.name, valid_scorecard[0].get("supplier")) diff --git a/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py b/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py index 114ff2b56b3..951d33ed901 100644 --- a/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py +++ b/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py @@ -3,10 +3,11 @@ import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecardCriteria(IntegrationTestCase): +class TestSupplierScorecardCriteria(ERPNextTestSuite): def test_variables_exist(self): delete_test_scorecards() for d in test_good_criteria: diff --git a/erpnext/buying/doctype/supplier_scorecard_period/test_supplier_scorecard_period.py b/erpnext/buying/doctype/supplier_scorecard_period/test_supplier_scorecard_period.py index 2b124dede99..6fd2bc3b0cc 100644 --- a/erpnext/buying/doctype/supplier_scorecard_period/test_supplier_scorecard_period.py +++ b/erpnext/buying/doctype/supplier_scorecard_period/test_supplier_scorecard_period.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecardPeriod(IntegrationTestCase): +class TestSupplierScorecardPeriod(ERPNextTestSuite): pass diff --git a/erpnext/buying/doctype/supplier_scorecard_standing/test_supplier_scorecard_standing.py b/erpnext/buying/doctype/supplier_scorecard_standing/test_supplier_scorecard_standing.py index 32581538b03..8cc89e941fb 100644 --- a/erpnext/buying/doctype/supplier_scorecard_standing/test_supplier_scorecard_standing.py +++ b/erpnext/buying/doctype/supplier_scorecard_standing/test_supplier_scorecard_standing.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecardStanding(IntegrationTestCase): +class TestSupplierScorecardStanding(ERPNextTestSuite): pass diff --git a/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py b/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py index 8f4b2f4ecdf..f390eefcc65 100644 --- a/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py +++ b/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py @@ -3,14 +3,14 @@ import frappe -from frappe.tests import IntegrationTestCase from erpnext.buying.doctype.supplier_scorecard_variable.supplier_scorecard_variable import ( VariablePathNotFound, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecardVariable(IntegrationTestCase): +class TestSupplierScorecardVariable(ERPNextTestSuite): def test_variable_exist(self): for d in test_existing_variables: my_doc = frappe.get_doc("Supplier Scorecard Variable", d.get("name")) diff --git a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py index f344730a7fa..1577bf2cbf6 100644 --- a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py +++ b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py @@ -2,8 +2,8 @@ # For license information, please see license.txt -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestProcurementTracker(IntegrationTestCase): +class TestProcurementTracker(ERPNextTestSuite): pass diff --git a/erpnext/buying/report/requested_items_to_order_and_receive/test_requested_items_to_order_and_receive.py b/erpnext/buying/report/requested_items_to_order_and_receive/test_requested_items_to_order_and_receive.py index ca0b1abad0c..38f2d7426ff 100644 --- a/erpnext/buying/report/requested_items_to_order_and_receive/test_requested_items_to_order_and_receive.py +++ b/erpnext/buying/report/requested_items_to_order_and_receive/test_requested_items_to_order_and_receive.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt @@ -11,11 +10,14 @@ from erpnext.buying.report.requested_items_to_order_and_receive.requested_items_ ) from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.material_request.material_request import make_purchase_order +from erpnext.tests.utils import ERPNextTestSuite -class TestRequestedItemsToOrderAndReceive(IntegrationTestCase): +class TestRequestedItemsToOrderAndReceive(ERPNextTestSuite): def setUp(self) -> None: create_item("Test MR Report Item") + self.load_test_records("Material Request") + frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1) self.setup_material_request() # to order and receive self.setup_material_request(order=True, days=1) # to receive (ordered) self.setup_material_request(order=True, receive=True, days=2) # complete (ordered & received) @@ -27,9 +29,6 @@ class TestRequestedItemsToOrderAndReceive(IntegrationTestCase): item_code="Test MR Report Item", ) - def tearDown(self) -> None: - frappe.db.rollback() - def test_date_range(self): data = get_data(self.filters) self.assertEqual(len(data), 2) # MRs today should be fetched diff --git a/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py b/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py index 5a4c8ec6ba0..1b6bf653a77 100644 --- a/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py +++ b/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py @@ -7,7 +7,6 @@ import copy import frappe -from frappe.tests import IntegrationTestCase from erpnext.buying.report.subcontracted_item_to_be_received.subcontracted_item_to_be_received import ( execute, @@ -22,9 +21,10 @@ from erpnext.controllers.tests.test_subcontracting_controller import ( from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order import ( make_subcontracting_receipt, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSubcontractedItemToBeReceived(IntegrationTestCase): +class TestSubcontractedItemToBeReceived(ERPNextTestSuite): def test_pending_and_received_qty(self): make_service_item("Subcontracted Service Item 1") service_items = [ diff --git a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/subcontracted_raw_materials_to_be_transferred.py b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/subcontracted_raw_materials_to_be_transferred.py index ef28eda62a5..4526bbf1703 100644 --- a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/subcontracted_raw_materials_to_be_transferred.py +++ b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/subcontracted_raw_materials_to_be_transferred.py @@ -41,6 +41,7 @@ def get_columns(filters): "fieldname": "transferred_qty", "width": 200, }, + {"label": _("Returned Quantity"), "fieldtype": "Float", "fieldname": "returned_qty", "width": 150}, {"label": _("Pending Quantity"), "fieldtype": "Float", "fieldname": "p_qty", "width": 150}, ] @@ -50,7 +51,7 @@ def get_data(filters): data = [] for row in order_rm_item_details: - transferred_qty = row.get("transferred_qty") or 0 + transferred_qty = (row.get("transferred_qty") or 0) - (row.get("returned_qty") or 0) if transferred_qty < row.get("reqd_qty", 0): pending_qty = frappe.utils.flt(row.get("reqd_qty", 0) - transferred_qty) row.p_qty = pending_qty if pending_qty > 0 else 0 @@ -86,6 +87,7 @@ def get_order_items_to_supply(filters): f"`tab{supplied_items_table}`.rm_item_code as rm_item_code", f"`tab{supplied_items_table}`.required_qty as reqd_qty", f"`tab{supplied_items_table}`.supplied_qty as transferred_qty", + f"`tab{supplied_items_table}`.returned_qty as returned_qty", ], filters=record_filters, ) diff --git a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py index 3553906ae63..ee76c50261d 100644 --- a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py +++ b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py @@ -4,7 +4,6 @@ # Decompiled by https://python-decompiler.com import frappe -from frappe.tests import IntegrationTestCase from erpnext.buying.report.subcontracted_raw_materials_to_be_transferred.subcontracted_raw_materials_to_be_transferred import ( execute, @@ -15,9 +14,10 @@ from erpnext.controllers.tests.test_subcontracting_controller import ( make_service_item, ) from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestSubcontractedItemToBeTransferred(IntegrationTestCase): +class TestSubcontractedItemToBeTransferred(ERPNextTestSuite): def test_pending_and_transferred_qty(self): make_service_item("Subcontracted Service Item 1") service_items = [ diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 43eaffa786b..24819c3ee19 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2289,6 +2289,16 @@ class AccountsController(TransactionBase): return stock_items + def get_asset_items(self): + asset_items = [] + item_codes = list(set(item.item_code for item in self.get("items"))) + if item_codes: + asset_items = frappe.db.get_values( + "Item", {"name": ["in", item_codes], "is_fixed_asset": 1}, pluck="name", cache=True + ) + + return asset_items + def calculate_total_advance_from_ledger(self): adv = frappe.qb.DocType("Advance Payment Ledger Entry") return ( diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index fe0f8a831aa..3ce079a62a6 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -267,8 +267,8 @@ class StatusUpdater(Document): self.global_amount_allowance = None for args in self.status_updater: - if "target_ref_field" not in args: - # if target_ref_field is not specified, the programmer does not want to validate qty / amount + if "target_ref_field" not in args or args.get("validate_qty") is False: + # if target_ref_field is not specified or validate_qty is explicitly set to False, skip validation continue items_to_validate = [] diff --git a/erpnext/controllers/subcontracting_controller.py b/erpnext/controllers/subcontracting_controller.py index 5a276d574d4..6d886bd9ecf 100644 --- a/erpnext/controllers/subcontracting_controller.py +++ b/erpnext/controllers/subcontracting_controller.py @@ -1087,6 +1087,12 @@ class SubcontractingController(StockController): if self.doctype not in ["Purchase Invoice", "Purchase Receipt", "Subcontracting Receipt"]: return + if ( + frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on") + == "BOM" + ): + return + for row in self.get(self.raw_material_table): key = (row.rm_item_code, row.main_item_code, row.get(self.subcontract_data.order_field)) if not self.__transferred_items or not self.__transferred_items.get(key): diff --git a/erpnext/controllers/tests/test_accounts_controller.py b/erpnext/controllers/tests/test_accounts_controller.py index 553a7246fea..6bb9b2f91fc 100644 --- a/erpnext/controllers/tests/test_accounts_controller.py +++ b/erpnext/controllers/tests/test_accounts_controller.py @@ -5,7 +5,6 @@ import frappe from frappe import qb from frappe.query_builder.functions import Sum -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, getdate, nowdate from frappe.utils.data import getdate as convert_to_date @@ -20,6 +19,7 @@ from erpnext.buying.doctype.purchase_order.test_purchase_order import ( ) from erpnext.projects.doctype.project.test_project import make_project from erpnext.stock.doctype.item.test_item import create_item +from erpnext.tests.utils import ERPNextTestSuite def make_customer(customer_name, currency=None): @@ -51,7 +51,7 @@ def make_supplier(supplier_name, currency=None): return supplier_name -class TestAccountsController(IntegrationTestCase): +class TestAccountsController(ERPNextTestSuite): """ Test Exchange Gain/Loss booking on various scenarios. Test Cases are numbered for better organization @@ -72,9 +72,7 @@ class TestAccountsController(IntegrationTestCase): self.create_item() self.create_parties() self.clear_old_entries() - - def tearDown(self): - frappe.db.rollback() + frappe.flags.is_reverse_depr_entry = False def create_company(self): company_name = "_Test Company" @@ -810,9 +808,7 @@ class TestAccountsController(IntegrationTestCase): self.assertEqual(exc_je_for_si, []) self.assertEqual(exc_je_for_pe, []) - @IntegrationTestCase.change_settings( - "Stock Settings", {"allow_internal_transfer_at_arms_length_price": 1} - ) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_internal_transfer_at_arms_length_price": 1}) def test_16_internal_transfer_at_arms_length_price(self): from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_inter_company_purchase_invoice from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse @@ -873,7 +869,7 @@ class TestAccountsController(IntegrationTestCase): self.assertEqual(pi.items[0].rate, arms_length_price) self.assertEqual(pi.items[0].valuation_rate, 100) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"exchange_gain_loss_posting_date": "Reconciliation Date"} ) def test_17_gain_loss_posting_date_for_normal_payment(self): @@ -936,9 +932,9 @@ class TestAccountsController(IntegrationTestCase): self.assertEqual(exc_je_for_si, []) self.assertEqual(exc_je_for_pe, []) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", - {"add_taxes_from_item_tax_template": 0, "add_taxes_from_taxes_and_charges_template": 1}, + {"add_taxes_from_taxes_and_charges_template": 1, "add_taxes_from_item_tax_template": 0}, ) def test_18_fetch_taxes_based_on_taxes_and_charges_template(self): # Create a Sales Taxes and Charges Template @@ -968,7 +964,7 @@ class TestAccountsController(IntegrationTestCase): self.assertEqual(sinv.total_taxes_and_charges, 4.5) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"add_taxes_from_item_tax_template": 1, "add_taxes_from_taxes_and_charges_template": 0}, ) @@ -2479,7 +2475,7 @@ class TestAccountsController(IntegrationTestCase): po.items[0].delivered_by_supplier = 1 po.save() - @IntegrationTestCase.change_settings("Global Defaults", {"use_posting_datetime_for_naming_documents": 1}) + @ERPNextTestSuite.change_settings("Global Defaults", {"use_posting_datetime_for_naming_documents": 1}) def test_document_naming_rule_based_on_posting_date(self): frappe.new_doc( "Document Naming Rule", document_type="Sales Invoice", prefix="SI-.MM.-.YYYY.-" diff --git a/erpnext/controllers/tests/test_distributed_discount.py b/erpnext/controllers/tests/test_distributed_discount.py index 05db1496da8..4f4911c8537 100644 --- a/erpnext/controllers/tests/test_distributed_discount.py +++ b/erpnext/controllers/tests/test_distributed_discount.py @@ -1,11 +1,11 @@ -from frappe.tests import IntegrationTestCase - from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxesAndTotals(AccountsTestMixin, IntegrationTestCase): +class TestTaxesAndTotals(AccountsTestMixin, ERPNextTestSuite): + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_distributed_discount_amount(self): so = make_sales_order(do_not_save=1) so.apply_discount_on = "Net Total" @@ -27,6 +27,7 @@ class TestTaxesAndTotals(AccountsTestMixin, IntegrationTestCase): self.assertEqual(so.net_total, 1400) self.assertEqual(so.grand_total, 1400) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_distributed_discount_amount_with_taxes(self): so = make_sales_order(do_not_save=1) so.apply_discount_on = "Grand Total" diff --git a/erpnext/controllers/tests/test_item_variant.py b/erpnext/controllers/tests/test_item_variant.py index 585a63ca798..e5c9d05d4db 100644 --- a/erpnext/controllers/tests/test_item_variant.py +++ b/erpnext/controllers/tests/test_item_variant.py @@ -2,16 +2,16 @@ import json import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.controllers.item_variant import copy_attributes_to_variant, make_variant_item_code from erpnext.stock.doctype.item.test_item import set_item_variant_settings from erpnext.stock.doctype.quality_inspection.test_quality_inspection import ( create_quality_inspection_parameter, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestItemVariant(IntegrationTestCase): +class TestItemVariant(ERPNextTestSuite): def test_tables_in_template_copied_to_variant(self): fields = [{"field_name": "quality_inspection_template"}] set_item_variant_settings(fields) diff --git a/erpnext/controllers/tests/test_item_wise_inventory_account.py b/erpnext/controllers/tests/test_item_wise_inventory_account.py index e8b2c1343e7..398a8388865 100644 --- a/erpnext/controllers/tests/test_item_wise_inventory_account.py +++ b/erpnext/controllers/tests/test_item_wise_inventory_account.py @@ -5,8 +5,7 @@ import copy from collections import defaultdict import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import add_days, cint, today +from frappe.utils import add_days, today from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record @@ -14,9 +13,10 @@ from erpnext.manufacturing.doctype.work_order.work_order import make_stock_entry from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestItemWiseInventoryAccount(IntegrationTestCase): +class TestItemWiseInventoryAccount(ERPNextTestSuite): def setUp(self): self.company = make_company() self.company_abbr = frappe.db.get_value("Company", self.company, "abbr") @@ -275,7 +275,7 @@ class TestItemWiseInventoryAccount(IntegrationTestCase): } for row in items: - self.make_item_group(items[row]["item_group"]) + self._make_item_group(items[row]["item_group"]) inventory_account_dict = frappe._dict() for item_name, item_data in items.items(): @@ -359,7 +359,7 @@ class TestItemWiseInventoryAccount(IntegrationTestCase): } for row in items: - self.make_item_group(items[row]["item_group"]) + self._make_item_group(items[row]["item_group"]) inventory_account_dict = frappe._dict() for item_name, item_data in items.items(): @@ -453,7 +453,7 @@ class TestItemWiseInventoryAccount(IntegrationTestCase): self.assertEqual(sle_value[0].value, gl_value, f"GL Entry not created for {item_code} correctly") - def make_item_group(self, item_name): + def _make_item_group(self, item_name): if not frappe.db.exists("Item Group", item_name): item_group = frappe.get_doc( { diff --git a/erpnext/controllers/tests/test_item_wise_tax_details.py b/erpnext/controllers/tests/test_item_wise_tax_details.py index 7628f77f7e3..f6d94c61eca 100644 --- a/erpnext/controllers/tests/test_item_wise_tax_details.py +++ b/erpnext/controllers/tests/test_item_wise_tax_details.py @@ -1,12 +1,12 @@ import json import frappe -from frappe.tests.utils import FrappeTestCase from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxesAndTotals(FrappeTestCase): +class TestTaxesAndTotals(ERPNextTestSuite): def setUp(self): self.doc = frappe.get_doc( { diff --git a/erpnext/controllers/tests/test_mapper.py b/erpnext/controllers/tests/test_mapper.py index 53eb75058ec..a54fff65706 100644 --- a/erpnext/controllers/tests/test_mapper.py +++ b/erpnext/controllers/tests/test_mapper.py @@ -4,13 +4,15 @@ import unittest import frappe import frappe.utils from frappe.model import mapper -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, nowdate -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestMapper(IntegrationTestCase): +class TestMapper(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Sales Order") + def test_map_docs(self): """Test mapping of multiple source docs on a single target doc""" @@ -38,6 +40,7 @@ class TestMapper(IntegrationTestCase): "order_type": "Sales", "transaction_date": nowdate(), "valid_till": add_months(nowdate(), 1), + "company": "_Test Company", } ) for item in item_list: @@ -64,6 +67,6 @@ class TestMapper(IntegrationTestCase): "uom": "_Test UOM", } ) - so = frappe.get_doc(frappe.get_test_records("Sales Order")[0]) + so = frappe.get_doc(self.globalTestRecords["Sales Order"][0]) so.insert(ignore_permissions=True) return so, [item.item_code] diff --git a/erpnext/controllers/tests/test_qty_based_taxes.py b/erpnext/controllers/tests/test_qty_based_taxes.py index d2fefa5b3b6..e3ddb0d1e1b 100644 --- a/erpnext/controllers/tests/test_qty_based_taxes.py +++ b/erpnext/controllers/tests/test_qty_based_taxes.py @@ -2,14 +2,15 @@ import unittest from uuid import uuid4 as _uuid4 import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite def uuid4(): return str(_uuid4()) -class TestTaxes(IntegrationTestCase): +class TestTaxes(ERPNextTestSuite): def setUp(self): self.company = frappe.get_doc( { @@ -125,12 +126,3 @@ class TestTaxes(IntegrationTestCase): doc.insert() self.assertEqual(doc.taxes[0].tax_amount, 600) self.created_docs.append(doc) - - def tearDown(self): - for doc in self.created_docs: - doc.delete() - self.item.delete() - self.item_group.delete() - self.item_tax_template.delete() - self.account.delete() - self.company.delete() diff --git a/erpnext/controllers/tests/test_queries.py b/erpnext/controllers/tests/test_queries.py index f7129a240b6..29f7ea1ea9f 100644 --- a/erpnext/controllers/tests/test_queries.py +++ b/erpnext/controllers/tests/test_queries.py @@ -14,19 +14,7 @@ def add_default_params(func, doctype): return partial(func, doctype=doctype, txt="", searchfield="name", start=0, page_len=20, filters=None) -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "BOM", "Account"] - - class TestQueries(ERPNextTestSuite): - # All tests are based on self.globalTestRecords[doctype] - - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_employees() - cls.make_leads() - cls.make_projects() - def assert_nested_in(self, item, container): self.assertIn(item, [vals for tuples in container for vals in tuples]) @@ -97,6 +85,8 @@ class TestQueries(ERPNextTestSuite): self.assertGreaterEqual(frappe.db.count("UOM", {"enabled": 1}), 10) def test_employee_query_with_user_permissions(self): + employee = frappe.db.get_all("Employee", {"first_name": "_Test Employee"})[0].name + # party field is a dynamic link field in Payment Entry doctype with ignore_user_permissions=0 ps = make_property_setter( doctype="Payment Entry", @@ -111,7 +101,7 @@ class TestQueries(ERPNextTestSuite): { "user": user.name, "doctype": "Employee", - "docname": self.employees[0].name, + "docname": employee, "is_default": 1, "apply_to_all_doctypes": 1, "applicable_doctypes": [], @@ -119,7 +109,7 @@ class TestQueries(ERPNextTestSuite): } ) - with self.set_user(user.name): + with ERPNextTestSuite.set_user(self, user.name): params = { "doctype": "Employee", "txt": "", diff --git a/erpnext/controllers/tests/test_reactivity.py b/erpnext/controllers/tests/test_reactivity.py index b6baad2fab2..fa3007087e1 100644 --- a/erpnext/controllers/tests/test_reactivity.py +++ b/erpnext/controllers/tests/test_reactivity.py @@ -1,13 +1,13 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase -from frappe.utils import getdate, today +from frappe.utils import today from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import disable_dimension from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestReactivity(AccountsTestMixin, IntegrationTestCase): +class TestReactivity(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -16,9 +16,6 @@ class TestReactivity(AccountsTestMixin, IntegrationTestCase): self.create_price_list() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def disable_dimensions(self): res = frappe.db.get_all("Accounting Dimension", filters={"disabled": False}) for x in res: diff --git a/erpnext/controllers/tests/test_subcontracting_controller.py b/erpnext/controllers/tests/test_subcontracting_controller.py index b6c21fa0b45..465b318d09b 100644 --- a/erpnext/controllers/tests/test_subcontracting_controller.py +++ b/erpnext/controllers/tests/test_subcontracting_controller.py @@ -5,8 +5,7 @@ import copy from collections import defaultdict import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import cint +from frappe.utils import cint, flt from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.controllers.subcontracting_controller import ( @@ -23,9 +22,10 @@ from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order import ( make_subcontracting_receipt, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSubcontractingController(IntegrationTestCase): +class TestSubcontractingController(ERPNextTestSuite): def setUp(self): make_subcontracted_items() make_raw_materials() @@ -75,6 +75,7 @@ class TestSubcontractingController(IntegrationTestCase): sco.create_raw_materials_supplied_or_received() self.assertIsNotNone(sco.supplied_items) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": 1}) def test_sco_with_bom(self): """ - Set backflush based on BOM. @@ -741,6 +742,7 @@ class TestSubcontractingController(IntegrationTestCase): "doctype": "Serial No", "item_code": "Subcontracted SRM Item 2", "serial_no": serial_no, + "company": "_Test Company", } ).insert() @@ -1512,7 +1514,7 @@ def make_subcontracted_item(**args): }, ) - args.raw_materials = ["_Test FG Item", "Test Extra Item 1"] + args.raw_materials = ["_Test Extra Item 1", "Test Extra Item 2"] if not frappe.db.get_value("BOM", {"item": args.item_code}, "name"): make_bom(item=args.item_code, raw_materials=args.get("raw_materials")) diff --git a/erpnext/controllers/tests/test_transaction_base.py b/erpnext/controllers/tests/test_transaction_base.py index cfb2dffabb6..4d0542053f7 100644 --- a/erpnext/controllers/tests/test_transaction_base.py +++ b/erpnext/controllers/tests/test_transaction_base.py @@ -1,10 +1,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestUtils(IntegrationTestCase): +class TestUtils(ERPNextTestSuite): def test_reset_default_field_value(self): doc = frappe.get_doc( { diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py index 476bde248cc..bc4e2b346d4 100644 --- a/erpnext/controllers/trends.py +++ b/erpnext/controllers/trends.py @@ -55,6 +55,14 @@ def validate_filters(filters): if filters.get("based_on") == filters.get("group_by"): frappe.throw(_("'Based On' and 'Group By' can not be same")) + if filters.get("period_based_on") and filters.period_based_on not in ["bill_date", "posting_date"]: + frappe.throw( + msg=_("{0} can be either {1} or {2}.").format( + frappe.bold("Period based On"), frappe.bold("Posting Date"), frappe.bold("Billing Date") + ), + title=_("Invalid Filter"), + ) + def get_data(filters, conditions): data = [] diff --git a/erpnext/crm/doctype/appointment/test_appointment.py b/erpnext/crm/doctype/appointment/test_appointment.py index e88a3dc67e5..24974ecf472 100644 --- a/erpnext/crm/doctype/appointment/test_appointment.py +++ b/erpnext/crm/doctype/appointment/test_appointment.py @@ -4,7 +4,8 @@ import datetime import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite LEAD_EMAIL = "test_appointment_lead@example.com" @@ -26,13 +27,9 @@ def create_test_appointment(): return test_appointment -class TestAppointment(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - frappe.db.delete("Lead", {"email_id": LEAD_EMAIL}) - +class TestAppointment(ERPNextTestSuite): def setUp(self): + frappe.db.delete("Lead", {"email_id": LEAD_EMAIL}) self.test_appointment = create_test_appointment() self.test_appointment.set_verified(self.test_appointment.customer_email) diff --git a/erpnext/crm/doctype/appointment_booking_settings/test_appointment_booking_settings.py b/erpnext/crm/doctype/appointment_booking_settings/test_appointment_booking_settings.py index 0fca8a59da3..96d86a224ed 100644 --- a/erpnext/crm/doctype/appointment_booking_settings/test_appointment_booking_settings.py +++ b/erpnext/crm/doctype/appointment_booking_settings/test_appointment_booking_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestAppointmentBookingSettings(IntegrationTestCase): +class TestAppointmentBookingSettings(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/campaign/test_campaign.py b/erpnext/crm/doctype/campaign/test_campaign.py index 878c18664ad..b84fc2815ca 100644 --- a/erpnext/crm/doctype/campaign/test_campaign.py +++ b/erpnext/crm/doctype/campaign/test_campaign.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCampaign(IntegrationTestCase): +class TestCampaign(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/competitor/test_competitor.py b/erpnext/crm/doctype/competitor/test_competitor.py index 2fbe068e8a7..664af74f3f6 100644 --- a/erpnext/crm/doctype/competitor/test_competitor.py +++ b/erpnext/crm/doctype/competitor/test_competitor.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCompetitor(IntegrationTestCase): +class TestCompetitor(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/contract/test_contract.py b/erpnext/crm/doctype/contract/test_contract.py index 2ea083834ce..f6aa0ef0979 100644 --- a/erpnext/crm/doctype/contract/test_contract.py +++ b/erpnext/crm/doctype/contract/test_contract.py @@ -3,11 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, nowdate +from erpnext.tests.utils import ERPNextTestSuite -class TestContract(IntegrationTestCase): + +class TestContract(ERPNextTestSuite): def setUp(self): frappe.db.sql("delete from `tabContract`") self.contract_doc = get_contract() diff --git a/erpnext/crm/doctype/contract_fulfilment_checklist/test_contract_fulfilment_checklist.py b/erpnext/crm/doctype/contract_fulfilment_checklist/test_contract_fulfilment_checklist.py index becb1674190..33f74f3e543 100644 --- a/erpnext/crm/doctype/contract_fulfilment_checklist/test_contract_fulfilment_checklist.py +++ b/erpnext/crm/doctype/contract_fulfilment_checklist/test_contract_fulfilment_checklist.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestContractFulfilmentChecklist(IntegrationTestCase): +class TestContractFulfilmentChecklist(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/contract_template/test_contract_template.py b/erpnext/crm/doctype/contract_template/test_contract_template.py index 4b2911945d0..aff3c8a9171 100644 --- a/erpnext/crm/doctype/contract_template/test_contract_template.py +++ b/erpnext/crm/doctype/contract_template/test_contract_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestContractTemplate(IntegrationTestCase): +class TestContractTemplate(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/crm_settings/test_crm_settings.py b/erpnext/crm/doctype/crm_settings/test_crm_settings.py index 22109d960dd..12fa43f8e1d 100644 --- a/erpnext/crm/doctype/crm_settings/test_crm_settings.py +++ b/erpnext/crm/doctype/crm_settings/test_crm_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCRMSettings(IntegrationTestCase): +class TestCRMSettings(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/email_campaign/test_email_campaign.py b/erpnext/crm/doctype/email_campaign/test_email_campaign.py index b94a41e7820..7d7d445b4be 100644 --- a/erpnext/crm/doctype/email_campaign/test_email_campaign.py +++ b/erpnext/crm/doctype/email_campaign/test_email_campaign.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestEmailCampaign(IntegrationTestCase): +class TestEmailCampaign(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/lead/test_lead.py b/erpnext/crm/doctype/lead/test_lead.py index b1b4e162b32..5da10ff9ea2 100644 --- a/erpnext/crm/doctype/lead/test_lead.py +++ b/erpnext/crm/doctype/lead/test_lead.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import random_string, today from erpnext.crm.doctype.lead.lead import make_opportunity @@ -12,19 +11,16 @@ from erpnext.tests.utils import ERPNextTestSuite class TestLead(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_leads() - def test_make_customer(self): from erpnext.crm.doctype.lead.lead import make_customer + lead = frappe.db.get_all("Lead", {"lead_name": "_Test Lead"})[0].name + frappe.delete_doc_if_exists("Customer", "_Test Lead") - customer = make_customer(self.leads[0].name) + customer = make_customer(lead) self.assertEqual(customer.doctype, "Customer") - self.assertEqual(customer.lead_name, self.leads[0].name) + self.assertEqual(customer.lead_name, lead) customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" @@ -48,9 +44,10 @@ class TestLead(ERPNextTestSuite): def test_make_customer_from_organization(self): from erpnext.crm.doctype.lead.lead import make_customer - customer = make_customer(self.leads[1].name) + lead = frappe.db.get_all("Lead", {"lead_name": "_Test Lead 1"})[0].name + customer = make_customer(lead) self.assertEqual(customer.doctype, "Customer") - self.assertEqual(customer.lead_name, self.leads[1].name) + self.assertEqual(customer.lead_name, lead) customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" @@ -127,6 +124,7 @@ class TestLead(ERPNextTestSuite): create_todo("followup", "Lead", lead.name) opportunity = make_opportunity(lead.name) + opportunity.company = "_Test Company" opportunity.save() self.assertEqual(opportunity.get("party_name"), lead.name) diff --git a/erpnext/crm/doctype/market_segment/test_market_segment.py b/erpnext/crm/doctype/market_segment/test_market_segment.py index 4f42f704309..5821bae063a 100644 --- a/erpnext/crm/doctype/market_segment/test_market_segment.py +++ b/erpnext/crm/doctype/market_segment/test_market_segment.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestMarketSegment(IntegrationTestCase): +class TestMarketSegment(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index db9866d9b89..caf94a044cb 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import now_datetime, random_string, today from erpnext.crm.doctype.lead.lead import make_customer @@ -14,14 +13,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestOpportunity(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - # Only first lead is required - # TODO: dynamically generate limited test records - cls.make_leads() - cls.make_opportunities() - @classmethod def make_opportunities(cls): records = [ @@ -31,6 +22,7 @@ class TestOpportunity(ERPNextTestSuite): "opportunity_from": "Lead", "enquiry_type": "Sales", "party_name": cls.leads[0].name, + "company": cls.companies[0].name, "transaction_date": "2013-12-12", "items": [ {"item_name": "Test Item", "description": "Some description", "qty": 5, "rate": 100} @@ -57,7 +49,7 @@ class TestOpportunity(ERPNextTestSuite): self.assertEqual(doc.status, "Quotation") def test_make_new_lead_if_required(self): - opp_doc = make_opportunity_from_lead() + opp_doc = make_opportunity_from_lead("_Test Company") self.assertTrue(opp_doc.party_name) self.assertEqual(opp_doc.opportunity_from, "Lead") @@ -101,7 +93,7 @@ class TestOpportunity(ERPNextTestSuite): create_communication(opp_doc.doctype, opp_doc.name, opp_doc.contact_email) -def make_opportunity_from_lead(): +def make_opportunity_from_lead(company): new_lead_email_id = f"new{random_string(5)}@example.com" args = { "doctype": "Opportunity", @@ -109,6 +101,7 @@ def make_opportunity_from_lead(): "opportunity_type": "Sales", "with_items": 0, "transaction_date": today(), + "company": company, } # new lead should be created against the new.opportunity@example.com opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) diff --git a/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py b/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py index 91bbd0d7095..1015ac8effa 100644 --- a/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py +++ b/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestOpportunityType(IntegrationTestCase): +class TestOpportunityType(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/prospect/test_prospect.py b/erpnext/crm/doctype/prospect/test_prospect.py index d66f3d5a494..594269dd084 100644 --- a/erpnext/crm/doctype/prospect/test_prospect.py +++ b/erpnext/crm/doctype/prospect/test_prospect.py @@ -3,20 +3,21 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import random_string from erpnext.crm.doctype.lead.lead import add_lead_to_prospect from erpnext.crm.doctype.lead.test_lead import make_lead +from erpnext.tests.utils import ERPNextTestSuite -class TestProspect(IntegrationTestCase): +class TestProspect(ERPNextTestSuite): def test_add_lead_to_prospect_and_address_linking(self): + company = "_Test Company" lead_doc = make_lead() address_doc = make_address(address_title=lead_doc.name) address_doc.append("links", {"link_doctype": lead_doc.doctype, "link_name": lead_doc.name}) address_doc.save() - prospect_doc = make_prospect() + prospect_doc = make_prospect(company=company, company_name=company) add_lead_to_prospect(lead_doc.name, prospect_doc.name) prospect_doc.reload() lead_exists_in_prosoect = False @@ -37,6 +38,7 @@ class TestProspect(IntegrationTestCase): "doctype": "Prospect", "company_name": "_Test Prospect", "customer_group": "_Test Customer Group", + "company": "_Test Company", } ) prospect.insert() @@ -58,6 +60,7 @@ def make_prospect(**args): { "doctype": "Prospect", "company_name": args.company_name or f"_Test Company {random_string(3)}", + "company": args.company, } ).insert() diff --git a/erpnext/crm/doctype/sales_stage/test_sales_stage.py b/erpnext/crm/doctype/sales_stage/test_sales_stage.py index 24da6ce48f6..9633ca17c14 100644 --- a/erpnext/crm/doctype/sales_stage/test_sales_stage.py +++ b/erpnext/crm/doctype/sales_stage/test_sales_stage.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesStage(IntegrationTestCase): +class TestSalesStage(ERPNextTestSuite): pass diff --git a/erpnext/crm/report/opportunity_summary_by_sales_stage/test_opportunity_summary_by_sales_stage.py b/erpnext/crm/report/opportunity_summary_by_sales_stage/test_opportunity_summary_by_sales_stage.py index 63d6cae3b00..4d5ba1dc9a2 100644 --- a/erpnext/crm/report/opportunity_summary_by_sales_stage/test_opportunity_summary_by_sales_stage.py +++ b/erpnext/crm/report/opportunity_summary_by_sales_stage/test_opportunity_summary_by_sales_stage.py @@ -1,24 +1,14 @@ -import unittest - -import frappe -from frappe.tests import IntegrationTestCase - from erpnext.crm.report.opportunity_summary_by_sales_stage.opportunity_summary_by_sales_stage import ( execute, ) from erpnext.crm.report.sales_pipeline_analytics.test_sales_pipeline_analytics import ( - create_company, - create_customer, create_opportunity, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestOpportunitySummaryBySalesStage(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - create_company() - create_customer() +class TestOpportunitySummaryBySalesStage(ERPNextTestSuite): + def setUp(self): create_opportunity() def test_opportunity_summary_by_sales_stage(self): diff --git a/erpnext/crm/report/sales_pipeline_analytics/test_sales_pipeline_analytics.py b/erpnext/crm/report/sales_pipeline_analytics/test_sales_pipeline_analytics.py index b29668fa030..893218c37ea 100644 --- a/erpnext/crm/report/sales_pipeline_analytics/test_sales_pipeline_analytics.py +++ b/erpnext/crm/report/sales_pipeline_analytics/test_sales_pipeline_analytics.py @@ -1,15 +1,13 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.crm.report.sales_pipeline_analytics.sales_pipeline_analytics import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesPipelineAnalytics(IntegrationTestCase): +class TestSalesPipelineAnalytics(ERPNextTestSuite): def setUp(self): - create_company() - create_customer() create_opportunity() def test_sales_pipeline_analytics(self): @@ -181,23 +179,6 @@ class TestSalesPipelineAnalytics(IntegrationTestCase): self.assertEqual(expected_data, report[1]) -def create_company(): - doc = frappe.db.exists("Company", "Best Test") - if not doc: - doc = frappe.new_doc("Company") - doc.company_name = "Best Test" - doc.default_currency = "INR" - doc.insert() - - -def create_customer(): - doc = frappe.db.exists("Customer", "_Test NC") - if not doc: - doc = frappe.new_doc("Customer") - doc.customer_name = "_Test NC" - doc.insert() - - def create_opportunity(): doc = frappe.db.exists({"doctype": "Opportunity", "party_name": "_Test NC"}) if not doc: diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py b/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py index 891a6bd10df..6cc09e6d2a7 100644 --- a/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py +++ b/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py @@ -4,7 +4,6 @@ import json import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils.response import json_handler from erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings import ( @@ -14,22 +13,10 @@ from erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings import ( get_plaid_configuration, new_bank_transaction, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestPlaidSettings(IntegrationTestCase): - def setUp(self): - pass - - def tearDown(self): - for bt in frappe.get_all("Bank Transaction"): - doc = frappe.get_doc("Bank Transaction", bt.name) - doc.cancel() - doc.delete() - - for doctype in ("Bank Account", "Bank Account Type", "Bank Account Subtype"): - for d in frappe.get_all(doctype): - frappe.delete_doc(doctype, d.name, force=True) - +class TestPlaidSettings(ERPNextTestSuite): def test_plaid_disabled(self): frappe.db.set_single_value("Plaid Settings", "enabled", 0) self.assertTrue(get_plaid_configuration() == "disabled") @@ -69,7 +56,7 @@ class TestPlaidSettings(IntegrationTestCase): } bank = json.dumps(frappe.get_doc("Bank", "Citi").as_dict(), default=json_handler) - company = frappe.db.get_single_value("Global Defaults", "default_company") + company = "_Test Company" add_bank_accounts(bank_accounts, bank, company) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 962fe3e98aa..c997443b41d 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -63,7 +63,6 @@ welcome_email = "erpnext.setup.utils.welcome_email" setup_wizard_requires = "assets/erpnext/js/setup_wizard.js" setup_wizard_stages = "erpnext.setup.setup_wizard.setup_wizard.get_setup_stages" setup_wizard_complete = "erpnext.setup.setup_wizard.setup_wizard.setup_demo" -setup_wizard_test = "erpnext.setup.setup_wizard.test_setup_wizard.run_setup_wizard_test" after_install = "erpnext.setup.install.after_install" @@ -320,8 +319,6 @@ has_website_permission = { "Project": "erpnext.controllers.website_list_for_contact.has_website_permission", } -before_tests = "erpnext.setup.utils.before_tests" - period_closing_doctypes = [ "Sales Invoice", diff --git a/erpnext/locale/main.pot b/erpnext/locale/main.pot index 1361fc78c39..f627ccf1b41 100644 --- a/erpnext/locale/main.pot +++ b/erpnext/locale/main.pot @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: ERPNext VERSION\n" "Report-Msgid-Bugs-To: hello@frappe.io\n" -"POT-Creation-Date: 2026-03-15 09:45+0000\n" -"PO-Revision-Date: 2026-03-15 09:45+0000\n" +"POT-Creation-Date: 2026-03-22 09:44+0000\n" +"PO-Revision-Date: 2026-03-22 09:44+0000\n" "Last-Translator: hello@frappe.io\n" "Language-Team: hello@frappe.io\n" "MIME-Version: 1.0\n" @@ -16,7 +16,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.16.0\n" -#: erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py:1515 +#: erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py:1520 msgid "" "\n" "\t\t\tThe Batch {0} of an item {1} has negative stock in the warehouse {2}{3}.\n" @@ -35,7 +35,7 @@ msgstr "" msgid " Address" msgstr "" -#: erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py:604 +#: erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py:611 msgid " Amount" msgstr "" @@ -72,7 +72,7 @@ msgstr "" msgid " Phantom Item" msgstr "" -#: erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py:595 +#: erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py:602 msgid " Rate" msgstr "" @@ -157,7 +157,7 @@ msgstr "" msgid "% Delivered" msgstr "" -#: erpnext/manufacturing/doctype/bom/bom.js:999 +#: erpnext/manufacturing/doctype/bom/bom.js:1000 #, python-format msgid "% Finished Item Quantity" msgstr "" @@ -172,8 +172,8 @@ msgstr "" msgid "% Occupied" msgstr "" -#: erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py:278 -#: erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py:330 +#: erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py:283 +#: erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py:337 msgid "% Of Grand Total" msgstr "" @@ -309,8 +309,8 @@ msgid "'Inspection Required before Purchase' has disabled for the item {0}, no n msgstr "" #: erpnext/stock/report/stock_ledger/stock_ledger.py:665 -#: erpnext/stock/report/stock_ledger/stock_ledger.py:705 -#: erpnext/stock/report/stock_ledger/stock_ledger.py:810 +#: erpnext/stock/report/stock_ledger/stock_ledger.py:706 +#: erpnext/stock/report/stock_ledger/stock_ledger.py:811 msgid "'Opening'" msgstr "" @@ -759,7 +759,7 @@ msgstr "" msgid "" msgstr "" -#: erpnext/accounts/doctype/bank_clearance/bank_clearance.py:123 +#: erpnext/accounts/doctype/bank_clearance/bank_clearance.py:125 msgid "
Apart from these, you can access all values in this RFQ, like {{ message_for_supplier }} or {{ terms }}.
Please correct the following row(s):