Merge pull request #53701 from frappe/version-16-hotfix

This commit is contained in:
diptanilsaha
2026-03-23 22:03:34 +05:30
committed by GitHub
439 changed files with 6049 additions and 5451 deletions

View File

@@ -4,8 +4,8 @@ on:
workflow_dispatch: workflow_dispatch:
concurrency: concurrency:
group: server-individual-tests-develop-${{ github.event_name }}-${{ github.event.number || github.event_name == 'workflow_dispatch' && github.run_id || '' }} group: server-individual-tests-lightmode-develop
cancel-in-progress: false cancel-in-progress: true
permissions: permissions:
contents: read contents: read
@@ -21,7 +21,7 @@ jobs:
- id: set-matrix - id: set-matrix
run: | run: |
# Use grep and find to get the list of test files # 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 . # Remove ./ prefix, file extension, and replace / with .
gsub(/^\.\//, "", $0) gsub(/^\.\//, "", $0)
gsub(/\.py$/, "", $0) gsub(/\.py$/, "", $0)
@@ -58,6 +58,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: ${{fromJson(needs.discover.outputs.matrix)}} matrix: ${{fromJson(needs.discover.outputs.matrix)}}
max-parallel: 14
name: Test name: Test
@@ -130,4 +131,13 @@ jobs:
FRAPPE_BRANCH: ${{ github.event.inputs.branch }} FRAPPE_BRANCH: ${{ github.event.inputs.branch }}
- name: Run Tests - 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

View File

@@ -129,7 +129,7 @@ jobs:
FRAPPE_BRANCH: ${{ github.event.client_payload.sha || github.event.inputs.branch }} FRAPPE_BRANCH: ${{ github.event.client_payload.sha || github.event.inputs.branch }}
- name: Run Tests - 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: env:
TYPE: server TYPE: server

View File

@@ -524,7 +524,8 @@ def make_gl_entries(
if gl_entries: if gl_entries:
try: try:
make_gl_entries(gl_entries, cancel=(doc.docstatus == 2), merge_entries=True) 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: except Exception as e:
if frappe.in_test: if frappe.in_test:
doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}") 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: if submit:
journal_entry.submit() journal_entry.submit()
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
except Exception: except Exception:
frappe.db.rollback() frappe.db.rollback()
doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}") doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}")

View File

@@ -3,7 +3,6 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import nowdate from frappe.utils import nowdate
from erpnext.accounts.doctype.account.account import ( from erpnext.accounts.doctype.account.account import (
@@ -12,11 +11,10 @@ from erpnext.accounts.doctype.account.account import (
update_account_number, update_account_number,
) )
from erpnext.stock import get_company_default_inventory_account, get_warehouse_account from erpnext.stock import get_company_default_inventory_account, get_warehouse_account
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Company"]
class TestAccount(IntegrationTestCase): class TestAccount(ERPNextTestSuite):
def test_rename_account(self): def test_rename_account(self):
if not frappe.db.exists("Account", "1210 - Debtors - _TC"): if not frappe.db.exists("Account", "1210 - Debtors - _TC"):
acc = frappe.new_doc("Account") acc = frappe.new_doc("Account")

View File

@@ -1,6 +0,0 @@
[
{
"doctype": "Account",
"name": "_Test Account 1"
}
]

View File

@@ -2,19 +2,3 @@
# See license.txt # See license.txt
# import frappe # 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

View File

@@ -2,8 +2,9 @@
# See license.txt # See license.txt
# import frappe # import frappe
from frappe.tests import IntegrationTestCase
from erpnext.tests.utils import ERPNextTestSuite
class TestAccountClosingBalance(IntegrationTestCase): class TestAccountClosingBalance(ERPNextTestSuite):
pass pass

View File

@@ -103,10 +103,6 @@ class AccountingDimension(Document):
if not self.fieldname: if not self.fieldname:
self.fieldname = scrub(self.label) 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): def make_dimension_in_accounting_doctypes(doc, doclist=None):
if not doclist: if not doclist:
@@ -241,34 +237,26 @@ def get_doctypes_with_dimensions():
return frappe.get_hooks("accounting_dimension_doctypes") return frappe.get_hooks("accounting_dimension_doctypes")
def get_accounting_dimensions(as_list=True, filters=None): def get_accounting_dimensions(as_list=True):
if not filters: accounting_dimensions = frappe.get_all(
filters = {"disabled": 0} "Accounting Dimension",
fields=["label", "fieldname", "disabled", "document_type"],
if frappe.flags.accounting_dimensions is None: filters={"disabled": 0},
frappe.flags.accounting_dimensions = frappe.get_all( )
"Accounting Dimension",
fields=["label", "fieldname", "disabled", "document_type"],
filters=filters,
)
if as_list: if as_list:
return [d.fieldname for d in frappe.flags.accounting_dimensions] return [d.fieldname for d in accounting_dimensions]
else: else:
return frappe.flags.accounting_dimensions return accounting_dimensions
def get_checks_for_pl_and_bs_accounts(): def get_checks_for_pl_and_bs_accounts():
if frappe.flags.accounting_dimensions_details is None: return frappe.db.sql(
# nosemgrep """SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs
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
FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c
WHERE p.name = c.parent AND p.disabled = 0""", WHERE p.name = c.parent AND p.disabled = 0""",
as_dict=1, as_dict=1,
) )
return frappe.flags.accounting_dimensions_details
def get_dimension_with_children(doctype, dimensions): def get_dimension_with_children(doctype, dimensions):

View File

@@ -3,15 +3,13 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry 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.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Cost Center", "Location", "Warehouse", "Department"]
class TestAccountingDimension(IntegrationTestCase): class TestAccountingDimension(ERPNextTestSuite):
def setUp(self): def setUp(self):
create_dimension() create_dimension()
@@ -80,11 +78,6 @@ class TestAccountingDimension(IntegrationTestCase):
si.save() si.save()
self.assertRaises(frappe.ValidationError, si.submit) 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(): def create_dimension():
frappe.set_user("Administrator") frappe.set_user("Administrator")

View File

@@ -69,37 +69,34 @@ class AccountingDimensionFilter(Document):
def get_dimension_filter_map(): def get_dimension_filter_map():
if not frappe.flags.get("dimension_filter_map"): filters = frappe.db.sql(
filters = frappe.db.sql( """
""" SELECT
SELECT a.applicable_on_account, d.dimension_value, p.accounting_dimension,
a.applicable_on_account, d.dimension_value, p.accounting_dimension, p.allow_or_restrict, p.fieldname, a.is_mandatory
p.allow_or_restrict, p.fieldname, a.is_mandatory FROM
FROM `tabApplicable On Account` a,
`tabApplicable On Account` a, `tabAccounting Dimension Filter` p
`tabAccounting Dimension Filter` p LEFT JOIN `tabAllowed Dimension` d ON d.parent = p.name
LEFT JOIN `tabAllowed Dimension` d ON d.parent = p.name WHERE
WHERE p.name = a.parent
p.name = a.parent AND p.disabled = 0
AND p.disabled = 0 """,
""", as_dict=1,
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,
) )
return dimension_filter_map
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
def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory): def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory):

View File

@@ -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.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Location", "Cost Center", "Department"]
class TestAccountingDimensionFilter(unittest.TestCase): class TestAccountingDimensionFilter(ERPNextTestSuite):
def setUp(self): def setUp(self):
create_dimension() create_dimension()
create_accounting_dimension_filter() create_accounting_dimension_filter()
@@ -44,17 +43,6 @@ class TestAccountingDimensionFilter(unittest.TestCase):
self.assertRaises(MandatoryAccountDimensionError, si.submit) self.assertRaises(MandatoryAccountDimensionError, si.submit)
self.invoice_list.append(si) 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(): def create_accounting_dimension_filter():
if not frappe.db.get_value("Accounting Dimension Filter", {"accounting_dimension": "Cost Center"}): if not frappe.db.get_value("Accounting Dimension Filter", {"accounting_dimension": "Cost Center"}):

View File

@@ -3,7 +3,6 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import add_months, nowdate from frappe.utils import add_months, nowdate
from erpnext.accounts.doctype.accounting_period.accounting_period import ( from erpnext.accounts.doctype.accounting_period.accounting_period import (
@@ -11,11 +10,10 @@ from erpnext.accounts.doctype.accounting_period.accounting_period import (
OverlapError, OverlapError,
) )
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"]
class TestAccountingPeriod(IntegrationTestCase): class TestAccountingPeriod(ERPNextTestSuite):
def test_overlap(self): def test_overlap(self):
ap1 = create_accounting_period( ap1 = create_accounting_period(
start_date="2018-04-01", end_date="2018-06-30", company="Wind Power LLC" 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 doc.submit() # Should not raise
self.assertEqual(doc.docstatus, 1) 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): def create_accounting_period(**args):
args = frappe._dict(args) args = frappe._dict(args)

View File

@@ -1,17 +1,11 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.tests.utils import ERPNextTestSuite
class TestAccountsSettings(IntegrationTestCase): class TestAccountsSettings(ERPNextTestSuite):
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()
def test_stale_days(self): def test_stale_days(self):
cur_settings = frappe.get_doc("Accounts Settings", "Accounts Settings") cur_settings = frappe.get_doc("Accounts Settings", "Accounts Settings")
cur_settings.allow_stale = 0 cur_settings.allow_stale = 0

View File

@@ -2,7 +2,6 @@
# See license.txt # See license.txt
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import nowdate, today from frappe.utils import nowdate, today
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry 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.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.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 # link-field test record depdendencies are recursively loaded
# Use these module variables to add/remove to/from that list # Use these module variables to add/remove to/from that list
EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] from erpnext.tests.utils import ERPNextTestSuite
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
class TestAdvancePaymentLedgerEntry(AccountsTestMixin, IntegrationTestCase): class TestAdvancePaymentLedgerEntry(AccountsTestMixin, ERPNextTestSuite):
""" """
Integration tests for AdvancePaymentLedgerEntry. Integration tests for AdvancePaymentLedgerEntry.
Use this class for testing interactions between multiple components. Use this class for testing interactions between multiple components.
@@ -30,9 +28,6 @@ class TestAdvancePaymentLedgerEntry(AccountsTestMixin, IntegrationTestCase):
self.create_item() self.create_item()
self.clear_old_entries() 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): def create_sales_order(self, qty=1, rate=100, currency="INR", do_not_submit=False):
""" """
Helper method Helper method

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestBank(IntegrationTestCase): class TestBank(ERPNextTestSuite):
pass pass

View File

@@ -2,10 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
import frappe from erpnext.tests.utils import ERPNextTestSuite
from frappe import ValidationError
from frappe.tests import IntegrationTestCase
class TestBankAccount(IntegrationTestCase): class TestBankAccount(ERPNextTestSuite):
pass pass

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestBankAccountSubtype(IntegrationTestCase): class TestBankAccountSubtype(ERPNextTestSuite):
pass pass

View File

@@ -3,8 +3,8 @@
# import frappe # import frappe
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestBankAccountType(IntegrationTestCase): class TestBankAccountType(ERPNextTestSuite):
pass pass

View File

@@ -3,7 +3,6 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import add_months, getdate from frappe.utils import add_months, getdate
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center 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.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.item.test_item import create_item
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse 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): class TestBankClearance(ERPNextTestSuite):
@classmethod def setUp(self):
def setUpClass(cls): frappe.clear_cache()
super().setUpClass()
create_warehouse( create_warehouse(
warehouse_name="_Test Warehouse", warehouse_name="_Test Warehouse",
properties={"parent_warehouse": "All Warehouses - _TC"}, properties={"parent_warehouse": "All Warehouses - _TC"},

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestBankGuarantee(IntegrationTestCase): class TestBankGuarantee(ERPNextTestSuite):
pass pass

View File

@@ -4,7 +4,6 @@
import frappe import frappe
from frappe import qb from frappe import qb
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, today from frappe.utils import add_days, today
from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import ( 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.doctype.payment_entry.test_payment_entry import create_payment_entry
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin 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): def setUp(self):
self.create_company() self.create_company()
self.create_customer() self.create_customer()
@@ -24,9 +24,6 @@ class TestBankReconciliationTool(AccountsTestMixin, IntegrationTestCase):
qb.from_(bank_dt).delete().where(bank_dt.name == "HDFC").run() qb.from_(bank_dt).delete().where(bank_dt.name == "HDFC").run()
self.create_bank_account() self.create_bank_account()
def tearDown(self):
frappe.db.rollback()
def create_bank_account(self): def create_bank_account(self):
bank = frappe.get_doc( bank = frappe.get_doc(
{ {
@@ -43,6 +40,7 @@ class TestBankReconciliationTool(AccountsTestMixin, IntegrationTestCase):
"bank": bank.name, "bank": bank.name,
"is_company_account": True, "is_company_account": True,
"account": self.bank, # account from Chart of Accounts "account": self.bank, # account from Chart of Accounts
"company": self.company,
} }
) )
.insert() .insert()

View File

@@ -1,15 +1,14 @@
# Copyright (c) 2020, Frappe Technologies and Contributors # Copyright (c) 2020, Frappe Technologies and Contributors
# See license.txt # See license.txt
import unittest
from erpnext.accounts.doctype.bank_statement_import.bank_statement_import import ( from erpnext.accounts.doctype.bank_statement_import.bank_statement_import import (
is_mt940_format, is_mt940_format,
preprocess_mt940_content, preprocess_mt940_content,
) )
from erpnext.tests.utils import ERPNextTestSuite
class TestBankStatementImport(unittest.TestCase): class TestBankStatementImport(ERPNextTestSuite):
"""Unit tests for Bank Statement Import functions""" """Unit tests for Bank Statement Import functions"""
def test_preprocess_mt940_content_with_long_statement_number(self): def test_preprocess_mt940_content_with_long_statement_number(self):

View File

@@ -2,27 +2,20 @@
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import nowdate from frappe.utils import nowdate
from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import create_bank_account from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import create_bank_account
from erpnext.tests.utils import ERPNextTestSuite
IBAN_1 = "DE02000000003716541159" IBAN_1 = "DE02000000003716541159"
IBAN_2 = "DE02500105170137075030" IBAN_2 = "DE02500105170137075030"
class TestAutoMatchParty(IntegrationTestCase): class TestAutoMatchParty(ERPNextTestSuite):
@classmethod def setUp(self):
def setUpClass(cls):
create_bank_account() create_bank_account()
frappe.db.set_single_value("Accounts Settings", "enable_party_matching", 1) frappe.db.set_single_value("Accounts Settings", "enable_party_matching", 1)
frappe.db.set_single_value("Accounts Settings", "enable_fuzzy_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): def test_match_by_account_number(self):
create_supplier_for_match(account_no=IBAN_1[11:]) create_supplier_for_match(account_no=IBAN_1[11:])

View File

@@ -6,7 +6,6 @@ import json
import frappe import frappe
from frappe import utils from frappe import utils
from frappe.model.docstatus import DocStatus from frappe.model.docstatus import DocStatus
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import ( from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import (
get_linked_payments, 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.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.purchase_invoice.test_purchase_invoice import make_purchase_invoice
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.tests.utils import if_lending_app_installed from erpnext.tests.utils import ERPNextTestSuite, if_lending_app_installed
EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Cost Center"]
class TestBankTransaction(IntegrationTestCase): class TestBankTransaction(ERPNextTestSuite):
def setUp(self): def setUp(self):
make_pos_profile() make_pos_profile()

View File

@@ -2,8 +2,10 @@
# See license.txt # See license.txt
# import frappe # import frappe
from frappe.tests import IntegrationTestCase
class TestBisectAccountingStatements(IntegrationTestCase): from erpnext.tests.utils import ERPNextTestSuite
class TestBisectAccountingStatements(ERPNextTestSuite):
pass pass

View File

@@ -2,8 +2,10 @@
# See license.txt # See license.txt
# import frappe # import frappe
from frappe.tests import IntegrationTestCase
class TestBisectNodes(IntegrationTestCase): from erpnext.tests.utils import ERPNextTestSuite
class TestBisectNodes(ERPNextTestSuite):
pass pass

View File

@@ -19,12 +19,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestBudget(ERPNextTestSuite): class TestBudget(ERPNextTestSuite):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.make_monthly_distribution()
cls.make_projects()
def setUp(self): def setUp(self):
frappe.db.set_single_value("Accounts Settings", "use_legacy_budget_controller", False) frappe.db.set_single_value("Accounts Settings", "use_legacy_budget_controller", False)
self.company = "_Test Company" self.company = "_Test Company"

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestCashierClosing(IntegrationTestCase): class TestCashierClosing(ERPNextTestSuite):
pass pass

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestChartofAccountsImporter(IntegrationTestCase): class TestChartofAccountsImporter(ERPNextTestSuite):
pass pass

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestChequePrintTemplate(IntegrationTestCase): class TestChequePrintTemplate(ERPNextTestSuite):
pass pass

View File

@@ -3,10 +3,11 @@
import unittest import unittest
import frappe 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): def test_cost_center_creation_against_child_node(self):
cost_center = frappe.get_doc( cost_center = frappe.get_doc(
{ {

View File

@@ -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"
}
]

View File

@@ -4,7 +4,6 @@ import unittest
import frappe import frappe
from frappe.query_builder.functions import Sum from frappe.query_builder.functions import Sum
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, today from frappe.utils import add_days, today
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center 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, WrongPercentageAllocation,
) )
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry 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): def setUp(self):
cost_centers = [ cost_centers = [
"Main Cost Center 1", "Main Cost Center 1",
@@ -191,7 +191,7 @@ class TestCostCenterAllocation(IntegrationTestCase):
coa2.cancel() coa2.cancel()
jv.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): 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 from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice

View File

@@ -3,11 +3,9 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"]
def test_create_test_data(): def test_create_test_data():
@@ -88,6 +86,7 @@ def test_create_test_data():
"partner_name": "_Test Coupon Partner", "partner_name": "_Test Coupon Partner",
"commission_rate": 2, "commission_rate": 2,
"referral_code": "COPART", "referral_code": "COPART",
"territory": "All Territories",
} }
) )
sales_partner.insert() sales_partner.insert()
@@ -110,13 +109,10 @@ def test_create_test_data():
coupon_code.insert() coupon_code.insert()
class TestCouponCode(IntegrationTestCase): class TestCouponCode(ERPNextTestSuite):
def setUp(self): def setUp(self):
test_create_test_data() test_create_test_data()
def tearDown(self):
frappe.set_user("Administrator")
def test_sales_order_with_coupon_code(self): def test_sales_order_with_coupon_code(self):
frappe.db.set_value("Coupon Code", "SAVE30", "used", 0) frappe.db.set_value("Coupon Code", "SAVE30", "used", 0)

View File

@@ -3,8 +3,8 @@
# import frappe # import frappe
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestCurrencyExchangeSettings(IntegrationTestCase): class TestCurrencyExchangeSettings(ERPNextTestSuite):
pass pass

View File

@@ -4,37 +4,20 @@ import json
import frappe import frappe
from frappe.model import mapper from frappe.model import mapper
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, nowdate, today from frappe.utils import add_days, nowdate, today
from erpnext import get_default_cost_center from erpnext import get_default_cost_center
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry 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 ( from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
create_dunning as create_dunning_from_sales_invoice, create_dunning as create_dunning_from_sales_invoice,
) )
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import (
create_sales_invoice_against_cost_center, create_sales_invoice_against_cost_center,
) )
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Company", "Cost Center"]
class TestDunning(IntegrationTestCase): class TestDunning(ERPNextTestSuite):
@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()
def test_dunning_without_fees(self): def test_dunning_without_fees(self):
dunning = create_dunning(overdue_days=20) dunning = create_dunning(overdue_days=20)

View File

@@ -3,8 +3,8 @@
# import frappe # import frappe
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestDunningType(IntegrationTestCase): class TestDunningType(ERPNextTestSuite):
pass pass

View File

@@ -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"
}
]

View File

@@ -5,15 +5,15 @@
import frappe import frappe
from frappe.query_builder import functions from frappe.query_builder import functions
from frappe.query_builder.utils import DocType from frappe.query_builder.utils import DocType
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, flt, today from frappe.utils import add_days, flt, today
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry 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.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin 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): def setUp(self):
self.create_company() self.create_company()
self.create_usd_receivable_account() self.create_usd_receivable_account()
@@ -22,14 +22,13 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase):
self.clear_old_entries() self.clear_old_entries()
self.set_system_and_company_settings() self.set_system_and_company_settings()
def tearDown(self):
frappe.db.rollback()
def set_system_and_company_settings(self): def set_system_and_company_settings(self):
# set number and currency precision # set number and currency precision
system_settings = frappe.get_doc("System Settings") system_settings = frappe.get_doc("System Settings")
system_settings.float_precision = 2 system_settings.float_precision = 2
system_settings.currency_precision = 2 system_settings.currency_precision = 2
system_settings.language = "en"
system_settings.time_zone = "Asia/Kolkata"
system_settings.save() system_settings.save()
# Using Exchange Gain/Loss account for unrealized as well. # 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.unrealized_exchange_gain_loss_account = company_doc.exchange_gain_loss_account
company_doc.save() company_doc.save()
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0},
) )
@@ -91,7 +90,7 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase):
)[0] )[0]
self.assertEqual(acc_balance.balance, 8500.0) self.assertEqual(acc_balance.balance, 8500.0)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, {"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, 0.0)
self.assertEqual(acc_balance.balance_in_account_currency, 0.0) self.assertEqual(acc_balance.balance_in_account_currency, 0.0)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, {"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, precision), 0.0)
self.assertEqual(flt(acc_balance.balance_in_account_currency, precision), 0.0) self.assertEqual(flt(acc_balance.balance_in_account_currency, precision), 0.0)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0},
) )

View File

@@ -3,12 +3,12 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry 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): def test_finance_book(self):
finance_book = create_finance_book() finance_book = create_finance_book()

View File

@@ -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.doctype.journal_entry.test_journal_entry import make_journal_entry
from erpnext.accounts.utils import get_currency_precision, get_fiscal_year 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): class TestDependencyResolver(FinancialReportTemplateTestCase):
"""Test cases for DependencyResolver class""" """Test cases for DependencyResolver class"""

View File

@@ -2,29 +2,16 @@
# For license information, please see license.txt # For license information, please see license.txt
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.tests.utils import make_test_records
# On IntegrationTestCase, the doctype test records and all from erpnext.tests.utils import ERPNextTestSuite
# 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 TestFinancialReportTemplate(IntegrationTestCase): class FinancialReportTemplateTestCase(ERPNextTestSuite):
pass
class FinancialReportTemplateTestCase(IntegrationTestCase):
"""Utility class with common setup and helper methods for all test classes""" """Utility class with common setup and helper methods for all test classes"""
@classmethod def setUp(self):
def setUpClass(cls):
"""Set up test data""" """Set up test data"""
make_test_records("Company") self.create_test_template()
make_test_records("Fiscal Year")
cls.create_test_template()
@classmethod @classmethod
def create_test_template(cls): def create_test_template(cls):

View File

@@ -3,13 +3,12 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import now_datetime 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): def test_extra_year(self):
if frappe.db.exists("Fiscal Year", "_Test Fiscal Year 2000"): if frappe.db.exists("Fiscal Year", "_Test Fiscal Year 2000"):
frappe.delete_doc("Fiscal Year", "_Test Fiscal Year 2000") frappe.delete_doc("Fiscal Year", "_Test Fiscal Year 2000")

View File

@@ -4,13 +4,13 @@ import unittest
import frappe import frappe
from frappe.model.naming import parse_naming_series 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.gl_entry.gl_entry import rename_gle_sle_docs
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry 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): 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_account", "_Test Write Off - _TC")
frappe.db.set_value("Company", "_Test Company", "round_off_cost_center", "_Test Cost Center - _TC") frappe.db.set_value("Company", "_Test Company", "round_off_cost_center", "_Test Cost Center - _TC")

View File

@@ -3,16 +3,16 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, flt, nowdate from frappe.utils import add_days, flt, nowdate
from erpnext.accounts.doctype.account.test_account import create_account 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.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.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.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): def setUp(self):
self.ar_credit = create_account( self.ar_credit = create_account(
account_name="_Test Accounts Receivable Credit", account_name="_Test Accounts Receivable Credit",

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestItemTaxTemplate(IntegrationTestCase): class TestItemTaxTemplate(ERPNextTestSuite):
pass pass

View File

@@ -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"
}
]
}
]

View File

@@ -2,19 +2,20 @@
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import flt, nowdate from frappe.utils import flt, nowdate
from erpnext.accounts.doctype.account.test_account import get_inventory_account from erpnext.accounts.doctype.account.test_account import get_inventory_account
from erpnext.accounts.doctype.journal_entry.journal_entry import StockAccountInvalidTransaction from erpnext.accounts.doctype.journal_entry.journal_entry import StockAccountInvalidTransaction
from erpnext.exceptions import InvalidAccountCurrency from erpnext.exceptions import InvalidAccountCurrency
from erpnext.selling.doctype.customer.test_customer import make_customer, set_credit_limit from erpnext.selling.doctype.customer.test_customer import make_customer, set_credit_limit
from erpnext.tests.utils import ERPNextTestSuite
class TestJournalEntry(IntegrationTestCase): class TestJournalEntry(ERPNextTestSuite):
@IntegrationTestCase.change_settings( def setUp(self):
"Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} 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): def test_journal_entry_with_against_jv(self):
jv_invoice = frappe.copy_doc(self.globalTestRecords["Journal Entry"][2]) jv_invoice = frappe.copy_doc(self.globalTestRecords["Journal Entry"][2])
base_jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][0]) base_jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][0])
@@ -149,7 +150,6 @@ class TestJournalEntry(IntegrationTestCase):
if account_bal == stock_bal: if account_bal == stock_bal:
self.assertRaises(StockAccountInvalidTransaction, jv.save) self.assertRaises(StockAccountInvalidTransaction, jv.save)
frappe.db.rollback()
else: else:
jv.submit() jv.submit()
jv.cancel() jv.cancel()

View File

@@ -3,8 +3,8 @@
# import frappe # import frappe
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestJournalEntryTemplate(IntegrationTestCase): class TestJournalEntryTemplate(ERPNextTestSuite):
pass pass

View File

@@ -3,23 +3,20 @@
import frappe import frappe
from frappe import qb from frappe import qb
from frappe.tests import IntegrationTestCase
from frappe.utils import nowdate from frappe.utils import nowdate
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.test.accounts_mixin import AccountsTestMixin
from erpnext.accounts.utils import run_ledger_health_checks 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): def setUp(self):
self.create_company() self.create_company()
self.create_customer() self.create_customer()
self.configure_monitoring_tool() self.configure_monitoring_tool()
self.clear_old_entries() self.clear_old_entries()
def tearDown(self):
frappe.db.rollback()
def configure_monitoring_tool(self): def configure_monitoring_tool(self):
monitor_settings = frappe.get_doc("Ledger Health Monitor") monitor_settings = frappe.get_doc("Ledger Health Monitor")
monitor_settings.enable_health_monitor = True monitor_settings.enable_health_monitor = True

View File

@@ -2,8 +2,10 @@
# See license.txt # See license.txt
# import frappe # import frappe
from frappe.tests import IntegrationTestCase
class TestLedgerHealthMonitor(IntegrationTestCase): from erpnext.tests.utils import ERPNextTestSuite
class TestLedgerHealthMonitor(ERPNextTestSuite):
pass pass

View File

@@ -3,12 +3,12 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.ledger_merge.ledger_merge import start_merge 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): def test_merge_success(self):
if not frappe.db.exists("Account", "Indirect Expenses - _TC"): if not frappe.db.exists("Account", "Indirect Expenses - _TC"):
acc = frappe.new_doc("Account") acc = frappe.new_doc("Account")
@@ -101,16 +101,3 @@ class TestLedgerMerge(IntegrationTestCase):
self.assertFalse(frappe.db.exists("Account", "Indirect Test Income - _TC")) self.assertFalse(frappe.db.exists("Account", "Indirect Test Income - _TC"))
self.assertTrue(frappe.db.exists("Account", "Administrative 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)

View File

@@ -3,31 +3,20 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import today 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.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.tests.utils import ERPNextTestSuite
class TestLoyaltyPointEntry(IntegrationTestCase): class TestLoyaltyPointEntry(ERPNextTestSuite):
@classmethod def setUp(self):
def setUpClass(cls):
super().setUpClass()
# Create test records # Create test records
create_records() self.loyalty_program_name = "Test Single Loyalty"
cls.loyalty_program_name = "Test Single Loyalty" self.customer_name = "Test Loyalty Customer"
cls.customer_name = "Test Loyalty Customer" customer = frappe.get_doc("Customer", self.customer_name)
customer = frappe.get_doc("Customer", cls.customer_name) customer.loyalty_program = self.loyalty_program_name
customer.db_set("loyalty_program", cls.loyalty_program_name) customer.save()
@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()
def create_test_invoice(self, redeem=None): def create_test_invoice(self, redeem=None):
if redeem: if redeem:
@@ -69,9 +58,10 @@ class TestLoyaltyPointEntry(IntegrationTestCase):
self.assertEqual(entry.discretionary_reason, "Customer Appreciation") self.assertEqual(entry.discretionary_reason, "Customer Appreciation")
def test_redeem_loyalty_points(self): 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") doc = frappe.get_last_doc("Loyalty Point Entry")
self.assertEqual(doc.loyalty_points, -10) self.assertEqual(doc.loyalty_points, -7)
# Check balance # Check balance
balance = frappe.db.sql( balance = frappe.db.sql(
@@ -83,4 +73,4 @@ class TestLoyaltyPointEntry(IntegrationTestCase):
(self.customer_name,), (self.customer_name,),
)[0][0] )[0][0]
self.assertEqual(balance, 75) # 85 added, 10 redeemed self.assertEqual(balance, 3) # 10 added, 7 redeemed

View File

@@ -3,7 +3,6 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import cint, flt, getdate, today from frappe.utils import cint, flt, getdate, today
from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( 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, get_loyalty_program_details_with_points,
) )
from erpnext.accounts.party import get_dashboard_info from erpnext.accounts.party import get_dashboard_info
from erpnext.tests.utils import ERPNextTestSuite
class TestLoyaltyProgram(IntegrationTestCase): class TestLoyaltyProgram(ERPNextTestSuite):
@classmethod
def setUpClass(cls):
super().setUpClass()
# create relevant item, customer, loyalty program, etc
create_records()
def test_loyalty_points_earned_single_tier(self): def test_loyalty_points_earned_single_tier(self):
frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty")
# create a new sales invoice # 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()

View File

@@ -3,10 +3,11 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.tests.utils import ERPNextTestSuite
class TestModeofPayment(IntegrationTestCase): class TestModeofPayment(ERPNextTestSuite):
pass pass

View File

@@ -2,9 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
import frappe from erpnext.tests.utils import ERPNextTestSuite
from frappe.tests import IntegrationTestCase
class TestMonthlyDistribution(IntegrationTestCase): class TestMonthlyDistribution(ERPNextTestSuite):
pass pass

View File

@@ -2,7 +2,6 @@
# See license.txt # See license.txt
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension, 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 ( from erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool import (
get_temporary_opening_account, get_temporary_opening_account,
) )
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Customer", "Supplier", "Accounting Dimension"]
class TestOpeningInvoiceCreationTool(IntegrationTestCase): class TestOpeningInvoiceCreationTool(ERPNextTestSuite):
@classmethod def setUp(self):
def setUpClass(cls):
if not frappe.db.exists("Company", "_Test Opening Invoice Company"): if not frappe.db.exists("Company", "_Test Opening Invoice Company"):
make_company() make_company()
create_dimension() create_dimension()
return super().setUpClass()
def make_invoices( def make_invoices(
self, self,
@@ -149,9 +145,6 @@ class TestOpeningInvoiceCreationTool(IntegrationTestCase):
} }
self.check_expected_values(invoices, expected_value, invoice_type="Sales") self.check_expected_values(invoices, expected_value, invoice_type="Sales")
def tearDown(self):
disable_dimension()
def get_opening_invoice_creation_dict(**args): def get_opening_invoice_creation_dict(**args):
party = "Customer" if args.get("invoice_type", "Sales") == "Sales" else "Supplier" party = "Customer" if args.get("invoice_type", "Sales") == "Sales" else "Supplier"

View File

@@ -3,8 +3,8 @@
# import frappe # import frappe
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestPartyLink(IntegrationTestCase): class TestPartyLink(ERPNextTestSuite):
pass pass

View File

@@ -4,7 +4,6 @@
import frappe import frappe
from frappe import qb from frappe import qb
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, flt, nowdate from frappe.utils import add_days, flt, nowdate
from erpnext.accounts.doctype.account.test_account import create_account 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.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.setup.doctype.employee.test_employee import make_employee from erpnext.setup.doctype.employee.test_employee import make_employee
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Currency Exchange"]
class TestPaymentEntry(IntegrationTestCase): class TestPaymentEntry(ERPNextTestSuite):
def tearDown(self):
frappe.db.rollback()
def get_journals_for(self, voucher_type: str, voucher_no: str) -> list: def get_journals_for(self, voucher_type: str, voucher_no: str) -> list:
journals = [] journals = []
if voucher_type and voucher_no: 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].outstanding, 0)
self.assertEqual(si.payment_schedule[0].discounted_amount, 50) self.assertEqual(si.payment_schedule[0].discounted_amount, 50)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{ {
"allow_multi_currency_invoices_against_single_party_account": 1, "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): def test_payment_entry_retrieves_last_exchange_rate(self):
from erpnext.setup.doctype.currency_exchange.test_currency_exchange import save_new_records 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"]) save_new_records(self.globalTestRecords["Currency Exchange"])
pe = frappe.new_doc("Payment Entry") pe = frappe.new_doc("Payment Entry")
@@ -982,6 +978,7 @@ class TestPaymentEntry(IntegrationTestCase):
def test_gl_of_multi_currency_payment_transaction(self): def test_gl_of_multi_currency_payment_transaction(self):
from erpnext.setup.doctype.currency_exchange.test_currency_exchange import save_new_records 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"]) save_new_records(self.globalTestRecords["Currency Exchange"])
paid_from = create_account( paid_from = create_account(
parent_account="Current Liabilities - _TC", parent_account="Current Liabilities - _TC",
@@ -1158,7 +1155,7 @@ class TestPaymentEntry(IntegrationTestCase):
} }
self.assertDictEqual(ref_details, expected_response) self.assertDictEqual(ref_details, expected_response)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{ {
"unlink_payment_on_cancellation_of_invoice": 1, "unlink_payment_on_cancellation_of_invoice": 1,
@@ -1253,7 +1250,7 @@ class TestPaymentEntry(IntegrationTestCase):
si3.cancel() si3.cancel()
si3.delete() si3.delete()
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{ {
"unlink_payment_on_cancellation_of_invoice": 1, "unlink_payment_on_cancellation_of_invoice": 1,
@@ -1949,7 +1946,7 @@ class TestPaymentEntry(IntegrationTestCase):
# 'Is Opening' should always be 'No' for normal advance payments # 'Is Opening' should always be 'No' for normal advance payments
self.assertEqual(gl_with_opening_set, []) 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): def test_delete_linked_exchange_gain_loss_journal(self):
from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import (

View File

@@ -2,10 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
IGNORE_TEST_RECORD_DEPENDENCIES = ["Payment Gateway"]
class TestPaymentGatewayAccount(IntegrationTestCase): class TestPaymentGatewayAccount(ERPNextTestSuite):
pass pass

View File

@@ -3,7 +3,6 @@
import frappe import frappe
from frappe import qb from frappe import qb
from frappe.tests import IntegrationTestCase
from frappe.utils import nowdate from frappe.utils import nowdate
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry 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.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.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.stock.doctype.item.test_item import create_item 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): def setUp(self):
self.ple = qb.DocType("Payment Ledger Entry") self.ple = qb.DocType("Payment Ledger Entry")
self.create_company() self.create_company()
@@ -21,9 +21,6 @@ class TestPaymentLedgerEntry(IntegrationTestCase):
self.create_customer() self.create_customer()
self.clear_old_entries() self.clear_old_entries()
def tearDown(self):
frappe.db.rollback()
def create_company(self): def create_company(self):
company_name = "_Test Payment Ledger" company_name = "_Test Payment Ledger"
company = None 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[0], expected_values[0])
self.assertEqual(pl_entries_for_crnote[1], expected_values[1]) self.assertEqual(pl_entries_for_crnote[1], expected_values[1])
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{"unlink_payment_on_cancellation_of_invoice": 1, "delete_linked_ledger_entries": 1}, {"unlink_payment_on_cancellation_of_invoice": 1, "delete_linked_ledger_entries": 1},
) )
@@ -474,7 +471,7 @@ class TestPaymentLedgerEntry(IntegrationTestCase):
si.delete() si.delete()
self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, si.doctype, si.name) self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, si.doctype, si.name)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{"unlink_payment_on_cancellation_of_invoice": 1, "delete_linked_ledger_entries": 1}, {"unlink_payment_on_cancellation_of_invoice": 1, "delete_linked_ledger_entries": 1},
) )
@@ -507,7 +504,7 @@ class TestPaymentLedgerEntry(IntegrationTestCase):
si.delete() si.delete()
self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, si.doctype, si.name) self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, si.doctype, si.name)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{ {
"unlink_payment_on_cancellation_of_invoice": 1, "unlink_payment_on_cancellation_of_invoice": 1,

View File

@@ -3,7 +3,6 @@
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import getdate from frappe.utils import getdate
from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import ( 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, make_payment_order,
) )
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice 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): def setUp(self):
# generate and use a uniq hash identifier for 'Bank Account' and it's linked GL 'Account' to avoid validation error # 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) 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 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): def test_payment_order_creation_against_payment_entry(self):
purchase_invoice = make_purchase_invoice() purchase_invoice = make_purchase_invoice()
payment_entry = get_payment_entry( payment_entry = get_payment_entry(

View File

@@ -4,7 +4,6 @@
import frappe import frappe
from frappe import qb from frappe import qb
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, add_years, flt, getdate, nowdate, today from frappe.utils import add_days, add_years, flt, getdate, nowdate, today
from frappe.utils.data import getdate as convert_to_date 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.accounts.utils import get_fiscal_year
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.item.test_item import create_item
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"]
class TestPaymentReconciliation(IntegrationTestCase): class TestPaymentReconciliation(ERPNextTestSuite):
def setUp(self): def setUp(self):
self.create_company() self.create_company()
self.create_item() self.create_item()
@@ -30,9 +28,6 @@ class TestPaymentReconciliation(IntegrationTestCase):
self.create_cost_center() self.create_cost_center()
self.clear_old_entries() self.clear_old_entries()
def tearDown(self):
frappe.db.rollback()
def create_company(self): def create_company(self):
company = None company = None
if frappe.db.exists("Company", "_Test Payment Reconciliation"): 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")] payment_vouchers = [x.get("reference_name") for x in pr.get("payments")]
self.assertCountEqual(payment_vouchers, [je2.name, pe2.name]) self.assertCountEqual(payment_vouchers, [je2.name, pe2.name])
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{ {
"allow_multi_currency_invoices_against_single_party_account": 1, "allow_multi_currency_invoices_against_single_party_account": 1,

View File

@@ -7,7 +7,6 @@ import unittest
from unittest.mock import patch from unittest.mock import patch
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, nowdate from frappe.utils import add_days, nowdate
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry 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.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.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.setup.utils import get_exchange_rate from erpnext.setup.utils import get_exchange_rate
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Currency Exchange", "Journal Entry", "Contact", "Address"]
PAYMENT_URL = "https://example.com/payment" PAYMENT_URL = "https://example.com/payment"
@@ -64,7 +62,7 @@ payment_method = [
] ]
class TestPaymentRequest(IntegrationTestCase): class TestPaymentRequest(ERPNextTestSuite):
def setUp(self): def setUp(self):
for payment_gateway in payment_gateways: for payment_gateway in payment_gateways:
if not frappe.db.get_value("Payment Gateway", payment_gateway["gateway"], "name"): 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._get_payment_gateway_controller = _get_payment_gateway_controller.start()
self.addCleanup(_get_payment_gateway_controller.stop) self.addCleanup(_get_payment_gateway_controller.stop)
def tearDown(self):
frappe.db.rollback()
def test_payment_request_linkings(self): def test_payment_request_linkings(self):
so_inr = make_sales_order(currency="INR", do_not_save=True) so_inr = make_sales_order(currency="INR", do_not_save=True)
so_inr.disable_rounded_total = 1 so_inr.disable_rounded_total = 1
@@ -504,7 +499,7 @@ class TestPaymentRequest(IntegrationTestCase):
return_doc=1, return_doc=1,
) )
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}
) )
def test_multiple_payment_if_partially_paid_for_multi_currency(self): 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.outstanding_amount, 0)
self.assertEqual(pr.grand_total, 20000) self.assertEqual(pr.grand_total, 20000)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}
) )
def test_single_payment_with_payment_term_for_multi_currency(self): def test_single_payment_with_payment_term_for_multi_currency(self):

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestPaymentTerm(IntegrationTestCase): class TestPaymentTerm(ERPNextTestSuite):
pass pass

View File

@@ -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
}
]

View File

@@ -3,13 +3,11 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.tests.utils import ERPNextTestSuite
class TestPaymentTermsTemplate(IntegrationTestCase): class TestPaymentTermsTemplate(ERPNextTestSuite):
def tearDown(self):
frappe.delete_doc("Payment Terms Template", "_Test Payment Terms Template For Test", force=1)
def test_create_template(self): def test_create_template(self):
template = frappe.get_doc( template = frappe.get_doc(
{ {

View File

@@ -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"
}
]

View File

@@ -2,28 +2,3 @@
# See license.txt # See license.txt
# import frappe # 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

View File

@@ -3,16 +3,16 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import today from frappe.utils import today
from erpnext.accounts.doctype.finance_book.test_finance_book import create_finance_book 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.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.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.utils import get_fiscal_year from erpnext.accounts.utils import get_fiscal_year
from erpnext.tests.utils import ERPNextTestSuite
class TestPeriodClosingVoucher(IntegrationTestCase): class TestPeriodClosingVoucher(ERPNextTestSuite):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
frappe.db.set_single_value("Accounts Settings", "use_legacy_controller_for_pcv", 1) 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) costcenter.insert(ignore_if_duplicate=True)
return costcenter.name return costcenter.name
EXTRA_TEST_RECORD_DEPENDENCIES = ["Customer", "Cost Center"]

View File

@@ -3,7 +3,6 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension, create_dimension,
@@ -22,26 +21,14 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle
get_batch_from_bundle, get_batch_from_bundle,
) )
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
from erpnext.tests.utils import ERPNextTestSuite
class TestPOSClosingEntry(IntegrationTestCase): class TestPOSClosingEntry(ERPNextTestSuite):
@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`")
def setUp(self): def setUp(self):
# Make stock available for POS Sales init_user_and_profile()
frappe.db.sql("delete from `tabPOS Opening Entry`")
make_stock_entry(target="_Test Warehouse - _TC", qty=2, basic_rate=100) make_stock_entry(target="_Test Warehouse - _TC", qty=2, basic_rate=100)
frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice")
def tearDown(self):
frappe.set_user("Administrator")
frappe.db.sql("delete from `tabPOS Profile`")
def test_pos_closing_entry(self): def test_pos_closing_entry(self):
test_user, pos_profile = init_user_and_profile() test_user, pos_profile = init_user_and_profile()
@@ -58,6 +45,7 @@ class TestPOSClosingEntry(IntegrationTestCase):
pos_inv2.submit() pos_inv2.submit()
pcv_doc = make_closing_entry_from_opening(opening_entry) pcv_doc = make_closing_entry_from_opening(opening_entry)
pcv_doc.flags.in_test = True
payment = pcv_doc.payment_reconciliation[0] payment = pcv_doc.payment_reconciliation[0]
self.assertEqual(payment.mode_of_payment, "Cash") self.assertEqual(payment.mode_of_payment, "Cash")
@@ -66,6 +54,7 @@ class TestPOSClosingEntry(IntegrationTestCase):
if d.mode_of_payment == "Cash": if d.mode_of_payment == "Cash":
d.closing_amount = 6700 d.closing_amount = 6700
pcv_doc.flags.in_test = True
pcv_doc.submit() pcv_doc.submit()
self.assertEqual(pcv_doc.total_quantity, 2) self.assertEqual(pcv_doc.total_quantity, 2)
@@ -84,6 +73,7 @@ class TestPOSClosingEntry(IntegrationTestCase):
pos_inv.submit() pos_inv.submit()
pcv_doc = make_closing_entry_from_opening(opening_entry) pcv_doc = make_closing_entry_from_opening(opening_entry)
pcv_doc.flags.in_test = True
pcv_doc.submit() pcv_doc.submit()
self.assertTrue(pcv_doc.name) self.assertTrue(pcv_doc.name)
@@ -116,6 +106,7 @@ class TestPOSClosingEntry(IntegrationTestCase):
pos_return.submit() pos_return.submit()
pcv_doc = make_closing_entry_from_opening(opening_entry) pcv_doc = make_closing_entry_from_opening(opening_entry)
pcv_doc.flags.in_test = True
pcv_doc.submit() pcv_doc.submit()
opening_entry = create_opening_entry(pos_profile, test_user.name) opening_entry = create_opening_entry(pos_profile, test_user.name)
@@ -145,6 +136,7 @@ class TestPOSClosingEntry(IntegrationTestCase):
if d.mode_of_payment == "Cash": if d.mode_of_payment == "Cash":
d.closing_amount = 6700 d.closing_amount = 6700
pcv_doc.flags.in_test = True
pcv_doc.submit() pcv_doc.submit()
pos_inv1.load_from_db() pos_inv1.load_from_db()
@@ -198,6 +190,7 @@ class TestPOSClosingEntry(IntegrationTestCase):
pcv_doc = make_closing_entry_from_opening(opening_entry) pcv_doc = make_closing_entry_from_opening(opening_entry)
# will assert coz the new mandatory accounting dimension bank is not set in POS Profile # 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) self.assertRaises(frappe.ValidationError, pcv_doc.submit)
accounting_dimension_department = frappe.get_doc( accounting_dimension_department = frappe.get_doc(
@@ -265,6 +258,7 @@ class TestPOSClosingEntry(IntegrationTestCase):
self.assertEqual(batch_qty_with_pos, 0.0) self.assertEqual(batch_qty_with_pos, 0.0)
pcv_doc = make_closing_entry_from_opening(opening_entry) pcv_doc = make_closing_entry_from_opening(opening_entry)
pcv_doc.flags.in_test = True
pcv_doc.submit() pcv_doc.submit()
piv_merge = frappe.db.get_value("POS Invoice Merge Log", {"pos_closing_entry": pcv_doc.name}, "name") 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 frappe.flags.print_message = True
pcv_doc.reload() pcv_doc.reload()
pcv_doc.flags.in_test = True
pcv_doc.cancel() pcv_doc.cancel()
batch_qty_with_pos = get_batch_qty(batch_no, "_Test Warehouse - _TC", item_code) 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) batch_qty_with_pos = get_batch_qty(batch_no, "_Test Warehouse - _TC", item_code)
self.assertEqual(batch_qty_with_pos, 10.0) 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): def test_closing_entries_with_sales_invoice(self):
test_user, pos_profile = init_user_and_profile() test_user, pos_profile = init_user_and_profile()
opening_entry = create_opening_entry(pos_profile, test_user.name) opening_entry = create_opening_entry(pos_profile, test_user.name)
@@ -330,6 +325,7 @@ class TestPOSClosingEntry(IntegrationTestCase):
if d.mode_of_payment == "Cash": if d.mode_of_payment == "Cash":
d.closing_amount = 1500 d.closing_amount = 1500
pcv_doc.flags.in_test = True
pcv_doc.submit() pcv_doc.submit()
self.assertEqual(pcv_doc.total_quantity, 15) self.assertEqual(pcv_doc.total_quantity, 15)
@@ -473,7 +469,7 @@ def init_user_and_profile(**args):
user = "test@example.com" user = "test@example.com"
test_user = frappe.get_doc("User", user) 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) test_user.add_roles(*roles)
frappe.set_user(user) frappe.set_user(user)

View File

@@ -5,7 +5,6 @@ import unittest
import frappe import frappe
from frappe import _ from frappe import _
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.mode_of_payment.test_mode_of_payment import ( from erpnext.accounts.doctype.mode_of_payment.test_mode_of_payment import (
set_default_account_for_mode_of_payment, 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, make_serial_batch_bundle,
) )
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from erpnext.tests.utils import ERPNextTestSuite
class TestPOSInvoice(IntegrationTestCase): class POSInvoiceTestMixin(ERPNextTestSuite):
@classmethod def setUp(self):
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`")
from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile 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() self.load_test_records("Stock Entry")
cls.opening_entry = create_opening_entry(cls.pos_profile, cls.test_user.name) self.test_user, self.pos_profile = init_user_and_profile()
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")
@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": if frappe.session.user != "Administrator":
frappe.set_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): def test_timestamp_change(self):
w = create_pos_invoice(do_not_save=1) w = create_pos_invoice(do_not_save=1)
@@ -642,9 +638,7 @@ class TestPOSInvoice(IntegrationTestCase):
from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( from erpnext.accounts.doctype.loyalty_program.loyalty_program import (
get_loyalty_program_details_with_points, 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") frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty")
before_lp_details = get_loyalty_program_details_with_points( before_lp_details = get_loyalty_program_details_with_points(
"Test Loyalty Customer", company="_Test Company", loyalty_program="Test Single Loyalty" "Test Loyalty Customer", company="_Test Company", loyalty_program="Test Single Loyalty"
@@ -681,6 +675,7 @@ class TestPOSInvoice(IntegrationTestCase):
get_loyalty_program_details_with_points, get_loyalty_program_details_with_points,
) )
frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty")
# add 10 loyalty points # add 10 loyalty points
pos_inv = create_pos_invoice(customer="Test Loyalty Customer", rate=10000, do_not_save=1) pos_inv = create_pos_invoice(customer="Test Loyalty Customer", rate=10000, do_not_save=1)
pos_inv.append( pos_inv.append(
@@ -710,134 +705,6 @@ class TestPOSInvoice(IntegrationTestCase):
) )
self.assertEqual(after_redeem_lp_details.loyalty_points, 9) 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): def test_pos_batch_reservation(self):
from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import ( from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import (
get_auto_batch_nos, get_auto_batch_nos,
@@ -1004,40 +871,39 @@ class TestPOSInvoice(IntegrationTestCase):
def test_ignore_pricing_rule(self): def test_ignore_pricing_rule(self):
from erpnext.accounts.doctype.pricing_rule.test_pricing_rule import make_pricing_rule from erpnext.accounts.doctype.pricing_rule.test_pricing_rule import make_pricing_rule
item_price = frappe.get_doc( if not frappe.db.exists(
{ "Item Price",
"doctype": "Item Price", {"item_code": "_Test Item", "price_list": "_Test Price List", "price_list_rate": "450"},
"item_code": "_Test Item", ):
"price_list": "_Test Price List", item_price = frappe.get_doc(
"price_list_rate": "450", {
} "doctype": "Item Price",
) "item_code": "_Test Item",
item_price.insert() "price_list": "_Test Price List",
"price_list_rate": "450",
}
)
item_price.insert()
pr = make_pricing_rule(selling=1, priority=5, discount_percentage=10) pr = make_pricing_rule(selling=1, priority=5, discount_percentage=10)
pr.save() pr.save()
try: pos_inv = create_pos_invoice(qty=1, do_not_submit=1)
pos_inv = create_pos_invoice(qty=1, do_not_submit=1) pos_inv.items[0].rate = 300
pos_inv.items[0].rate = 300 pos_inv.save()
pos_inv.save() self.assertEqual(pos_inv.items[0].discount_percentage, 10)
self.assertEqual(pos_inv.items[0].discount_percentage, 10) # rate shouldn't change
# rate shouldn't change self.assertEqual(pos_inv.items[0].rate, 405)
self.assertEqual(pos_inv.items[0].rate, 405)
pos_inv.ignore_pricing_rule = 1 pos_inv.ignore_pricing_rule = 1
pos_inv.save() pos_inv.save()
self.assertEqual(pos_inv.ignore_pricing_rule, 1) self.assertEqual(pos_inv.ignore_pricing_rule, 1)
# rate should reset since pricing rules are ignored # rate should reset since pricing rules are ignored
self.assertEqual(pos_inv.items[0].rate, 450) self.assertEqual(pos_inv.items[0].rate, 450)
pos_inv.items[0].rate = 300 pos_inv.items[0].rate = 300
pos_inv.save() pos_inv.save()
self.assertEqual(pos_inv.items[0].rate, 300) self.assertEqual(pos_inv.items[0].rate, 300)
finally:
item_price.delete()
pos_inv.delete()
pr.delete()
def test_delivered_serial_no_case(self): def test_delivered_serial_no_case(self):
from erpnext.accounts.doctype.pos_invoice_merge_log.test_pos_invoice_merge_log import ( 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.delivery_note.test_delivery_note import create_delivery_note
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item
frappe.db.savepoint("before_test_delivered_serial_no_case") se = make_serialized_item(self)
try: 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]) 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] 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( pos_inv = create_pos_invoice(
item_code="_Test Serialized Item With Series", item_code="_Test Serialized Item With Series",
serial_no=[serial_no], serial_no=[serial_no],
qty=1, qty=1,
rate=100, rate=100,
do_not_submit=True, do_not_submit=True,
ignore_sabb_validation=True, ignore_sabb_validation=True,
) )
self.assertRaises(frappe.ValidationError, pos_inv.submit) self.assertRaises(frappe.ValidationError, pos_inv.submit)
finally:
frappe.db.rollback(save_point="before_test_delivered_serial_no_case")
frappe.set_user("Administrator")
def test_bundle_stock_availability_validation(self): def test_bundle_stock_availability_validation(self):
from erpnext.accounts.doctype.pos_invoice.pos_invoice import ProductBundleStockValidationError from erpnext.accounts.doctype.pos_invoice.pos_invoice import ProductBundleStockValidationError

View File

@@ -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)

View File

@@ -283,7 +283,7 @@ class POSInvoiceMergeLog(Document):
base_rounding_adjustment += doc.base_rounding_adjustment base_rounding_adjustment += doc.base_rounding_adjustment
base_rounded_total += doc.base_rounded_total 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( row = frappe._dict(
item=old_new_item_map[d.item_row], item=old_new_item_map[d.item_row],
tax=old_new_tax_map[d.tax_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): 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 customer, invoices_acc_dim in invoice_by_customer.items():
for invoices in invoices_acc_dim.values(): for invoices in invoices_acc_dim.values():
for _invoices in split_invoices(invoices): 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.db_set("error_message", "")
closing_entry.update_opening_entry() closing_entry.update_opening_entry()
except Exception as e: if frappe.in_test:
frappe.db.rollback() merge_and_close()
message_log = frappe.message_log.pop() if frappe.message_log else str(e) else:
error_message = get_error_message(message_log) 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: if closing_entry:
closing_entry.set_status(update=True, status="Failed") closing_entry.set_status(update=True, status="Failed")
if isinstance(error_message, list): if isinstance(error_message, list):
error_message = json.dumps(error_message) error_message = json.dumps(error_message)
closing_entry.db_set("error_message", error_message) closing_entry.db_set("error_message", error_message)
raise raise
finally: finally:
frappe.db.commit() frappe.db.commit()
frappe.publish_realtime("closing_process_complete", user=frappe.session.user) frappe.publish_realtime("closing_process_complete", user=frappe.session.user)
def cancel_merge_logs(merge_logs, closing_entry=None): def cancel_merge_logs(merge_logs, closing_entry=None):
try: def merge_cancel_and_close():
for log in merge_logs: for log in merge_logs:
merge_log = frappe.get_doc("POS Invoice Merge Log", log) merge_log = frappe.get_doc("POS Invoice Merge Log", log)
if merge_log.docstatus == 2: 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.db_set("error_message", "")
closing_entry.update_opening_entry(for_cancel=True) closing_entry.update_opening_entry(for_cancel=True)
except Exception as e: if frappe.flags.in_test:
frappe.db.rollback() merge_cancel_and_close()
message_log = frappe.message_log.pop() if frappe.message_log else str(e) else:
error_message = get_error_message(message_log) 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: if closing_entry:
closing_entry.set_status(update=True, status="Submitted") closing_entry.set_status(update=True, status="Submitted")
closing_entry.db_set("error_message", error_message) closing_entry.db_set("error_message", error_message)
raise raise
finally: finally:
frappe.db.commit() frappe.db.commit()
frappe.publish_realtime("closing_process_complete", user=frappe.session.user) frappe.publish_realtime("closing_process_complete", user=frappe.session.user)
def enqueue_job(job, **kwargs): def enqueue_job(job, **kwargs):

View File

@@ -3,7 +3,6 @@
import json import json
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.mode_of_payment.test_mode_of_payment import ( from erpnext.accounts.doctype.mode_of_payment.test_mode_of_payment import (
set_default_account_for_mode_of_payment, 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, get_serial_nos_from_bundle,
) )
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from erpnext.tests.utils import ERPNextTestSuite
class TestPOSInvoiceMergeLog(IntegrationTestCase): class TestPOSInvoiceMergeLog(ERPNextTestSuite):
@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")
def setUp(self): 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): set_default_account_for_mode_of_payment(mode_of_payment, "_Test Company", "_Test Bank - _TC")
frappe.set_user("Administrator") frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice")
frappe.db.sql("delete from `tabPOS Profile`") frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0)
frappe.db.sql("delete from `tabPOS Invoice`")
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): 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 = create_pos_invoice(rate=300, do_not_submit=1)
pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300})
pos_inv.save() pos_inv.save()
@@ -58,9 +52,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
pos_inv3.save() pos_inv3.save()
pos_inv3.submit() pos_inv3.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
pos_inv.load_from_db() pos_inv.load_from_db()
self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) 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) self.assertFalse(pos_inv.consolidated_invoice == pos_inv3.consolidated_invoice)
def test_consolidated_credit_note_creation(self): 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 = create_pos_invoice(rate=300, do_not_submit=1)
pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300})
pos_inv.save() pos_inv.save()
@@ -98,9 +87,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
pos_inv_cn.paid_amount = -300 pos_inv_cn.paid_amount = -300
pos_inv_cn.submit() pos_inv_cn.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
pos_inv.load_from_db() pos_inv.load_from_db()
self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) 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) self.assertEqual(consolidated_credit_note.payments[1].amount, -200)
def test_consolidated_invoice_item_taxes(self): 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 = create_pos_invoice(qty=1, rate=100, do_not_save=True)
inv.append( inv.append(
@@ -157,9 +141,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
inv2.save() inv2.save()
inv2.submit() inv2.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
inv.load_from_db() inv.load_from_db()
@@ -207,9 +189,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
qty=10, 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 = create_pos_invoice(qty=3, rate=10000, do_not_save=True)
inv.append( inv.append(
"taxes", "taxes",
@@ -244,9 +223,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
inv2.insert() inv2.insert()
inv2.submit() inv2.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
inv.load_from_db() inv.load_from_db()
consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice)
@@ -264,9 +241,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
qty=10, 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 = create_pos_invoice(qty=6, rate=10000, do_not_save=True)
inv.append( inv.append(
"taxes", "taxes",
@@ -306,16 +280,14 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
inv3.insert() inv3.insert()
inv3.submit() inv3.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
inv.load_from_db() inv.load_from_db()
consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice)
self.assertNotEqual(consolidated_invoice.outstanding_amount, 800) self.assertNotEqual(consolidated_invoice.outstanding_amount, 800)
self.assertEqual(consolidated_invoice.status, "Paid") self.assertEqual(consolidated_invoice.status, "Paid")
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"System Settings", {"number_format": "#,###.###", "currency_precision": 3, "float_precision": 3} "System Settings", {"number_format": "#,###.###", "currency_precision": 3, "float_precision": 3}
) )
def test_consolidation_round_off_error_3(self): def test_consolidation_round_off_error_3(self):
@@ -325,8 +297,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
rate=8000, rate=8000,
qty=10, 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] item_rates = [69, 59, 29]
for _i in [1, 2]: for _i in [1, 2]:
@@ -363,9 +333,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
inv.save() inv.save()
inv.submit() inv.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
inv.load_from_db() inv.load_from_db()
consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice)
@@ -383,9 +351,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
qty=10, 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 = 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.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 70})
inv.insert() inv.insert()
@@ -396,9 +361,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
inv2.insert() inv2.insert()
inv2.submit() inv2.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
inv.load_from_db() inv.load_from_db()
consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) 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 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 from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item
se = make_serialized_item(self) se = make_serialized_item(self)
serial_no = get_serial_nos_from_bundle(se.get("items")[0].serial_and_batch_bundle)[0] 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( pos_inv = create_pos_invoice(
item_code="_Test Serialized Item With Series", item_code="_Test Serialized Item With Series",
serial_no=[serial_no], serial_no=[serial_no],
@@ -449,9 +410,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
pos_inv2.save() pos_inv2.save()
pos_inv2.submit() pos_inv2.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
pos_inv.load_from_db() pos_inv.load_from_db()
pos_inv2.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 1", is_group=0)
create_cost_center(cost_center_name="_Test POS Cost Center 2", 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 = create_pos_invoice(rate=300, do_not_submit=1)
pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300})
pos_inv.cost_center = "_Test POS Cost Center 1 - _TC" pos_inv.cost_center = "_Test POS Cost Center 1 - _TC"
@@ -491,9 +447,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
pos_inv3.save() pos_inv3.save()
pos_inv3.submit() pos_inv3.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
pos_inv.load_from_db() pos_inv.load_from_db()
self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) 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 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 = create_pos_invoice(rate=300, do_not_submit=1)
pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300})
pos_inv.save() pos_inv.save()
pos_inv.submit() pos_inv.submit()
closing_entry = make_closing_entry_from_opening(opening_entry) closing_entry = self.make_closing_entry()
closing_entry.insert()
closing_entry.submit()
self.assertTrue(frappe.db.exists("POS Invoice Merge Log", {"pos_closing_entry": closing_entry.name})) self.assertTrue(frappe.db.exists("POS Invoice Merge Log", {"pos_closing_entry": closing_entry.name}))

View File

@@ -4,35 +4,21 @@ import unittest
import frappe import frappe
from frappe.core.doctype.user_permission.test_user_permission import create_user 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_invoice.test_pos_invoice import create_pos_invoice
from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile 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.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
from erpnext.tests.utils import ERPNextTestSuite
class TestPOSOpeningEntry(IntegrationTestCase): class TestPOSOpeningEntry(ERPNextTestSuite):
@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`")
def setUp(self): def setUp(self):
# Make stock available for POS Sales frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice")
frappe.db.sql("delete from `tabPOS Opening Entry`")
make_stock_entry(target="_Test Warehouse - _TC", qty=2, basic_rate=100) 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 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 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): def test_pos_opening_entry(self):
test_user, pos_profile = self.init_user_and_profile() test_user, pos_profile = self.init_user_and_profile()
opening_entry = create_opening_entry(pos_profile, test_user.name) 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.status, "Open")
self.assertEqual(opening_entry_1.user, test_user.name) 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) frappe.set_user(cashier_user.name)
pos_profile2 = make_pos_profile(name="_Test POS Profile 2") pos_profile2 = make_pos_profile(name="_Test POS Profile 2")

View File

@@ -3,19 +3,18 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import cint from frappe.utils import cint
from erpnext.accounts.doctype.pos_profile.pos_profile import ( from erpnext.accounts.doctype.pos_profile.pos_profile import (
get_child_nodes, get_child_nodes,
) )
from erpnext.stock.get_item_details import get_pos_profile from erpnext.stock.get_item_details import get_pos_profile
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"]
class TestPOSProfile(IntegrationTestCase): class TestPOSProfile(ERPNextTestSuite):
def test_pos_profile(self): def test_pos_profile(self):
frappe.set_user("Administrator")
make_pos_profile() make_pos_profile()
pos_profile = get_pos_profile("_Test Company") or {} 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(items), products_count[0][0])
self.assertEqual(len(customers), customers_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): def test_disabled_pos_profile_creation(self):
make_pos_profile(name="_Test POS Profile 001", disabled=1) make_pos_profile(name="_Test POS Profile 001", disabled=1)

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestPOSProfileUser(IntegrationTestCase): class TestPOSProfileUser(ERPNextTestSuite):
pass pass

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestPOSSettings(IntegrationTestCase): class TestPOSSettings(ERPNextTestSuite):
pass pass

View File

@@ -5,7 +5,6 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice 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.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.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.item.test_item import make_item
from erpnext.stock.get_item_details import get_item_details 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): def setUp(self):
delete_existing_pricing_rules() delete_existing_pricing_rules()
setup_pricing_rule_data() setup_pricing_rule_data()
self.enterClassContext(self.change_settings("Selling Settings", validate_selling_price=0)) 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): def test_pricing_rule_for_discount(self):
from frappe import MandatoryError from frappe import MandatoryError
@@ -416,6 +413,7 @@ class TestPricingRule(IntegrationTestCase):
self.assertEqual(item.discount_amount, 110) self.assertEqual(item.discount_amount, 110)
self.assertEqual(item.rate, 990) 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): def test_pricing_rule_for_product_discount_on_same_item(self):
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule")
test_record = { test_record = {
@@ -1191,6 +1189,7 @@ class TestPricingRule(IntegrationTestCase):
si.delete() si.delete()
rule.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): def test_pricing_rule_for_product_free_item_rounded_qty_and_recursion(self):
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule")
test_record = { test_record = {
@@ -1236,6 +1235,7 @@ class TestPricingRule(IntegrationTestCase):
so.save() so.save()
self.assertEqual(len(so.items), 1) 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): def test_pricing_rule_for_product_free_item_round_free_qty(self):
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule")
test_record = { test_record = {
@@ -1522,9 +1522,6 @@ class TestPricingRule(IntegrationTestCase):
pi.cancel() pi.cancel()
EXTRA_TEST_RECORD_DEPENDENCIES = ["UTM Campaign"]
def make_pricing_rule(**args): def make_pricing_rule(**args):
args = frappe._dict(args) args = frappe._dict(args)

View File

@@ -243,8 +243,10 @@ def get_other_conditions(conditions, values, args):
if group_condition: if group_condition:
conditions += " and " + group_condition conditions += " and " + group_condition
date = args.get("transaction_date") or frappe.get_value( date = (
args.get("doctype"), args.get("name"), "posting_date", ignore=True 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: if date:
conditions += """ and %(transaction_date)s between ifnull(`tabPricing Rule`.valid_from, '2000-01-01') conditions += """ and %(transaction_date)s between ifnull(`tabPricing Rule`.valid_from, '2000-01-01')

View File

@@ -3,7 +3,6 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( 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, create_sales_invoice,
) )
from erpnext.stock.doctype.item.test_item import create_item 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): def test_creation_of_ledger_entry_on_submit(self):
"""test creation of gl entries on submission of document""" """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") 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", start_date="2023-05-01",
end_date="2023-06-30", end_date="2023-06-30",
type="Income", type="Income",
company="_Test Company",
) )
process_deferred_accounting.insert() process_deferred_accounting.insert()
@@ -83,6 +84,7 @@ class TestProcessDeferredAccounting(IntegrationTestCase):
start_date="2019-01-01", start_date="2019-01-01",
end_date="2019-01-31", end_date="2019-01-31",
type="Income", type="Income",
company="_Test Company",
) )
pda.submit() pda.submit()
pda.cancel() pda.cancel()

View File

@@ -2,8 +2,10 @@
# See license.txt # See license.txt
# import frappe # import frappe
from frappe.tests import IntegrationTestCase
class TestProcessPaymentReconciliation(IntegrationTestCase): from erpnext.tests.utils import ERPNextTestSuite
class TestProcessPaymentReconciliation(ERPNextTestSuite):
pass pass

View File

@@ -2,8 +2,10 @@
# See license.txt # See license.txt
# import frappe # import frappe
from frappe.tests import IntegrationTestCase
class TestProcessPaymentReconciliationLog(IntegrationTestCase): from erpnext.tests.utils import ERPNextTestSuite
class TestProcessPaymentReconciliationLog(ERPNextTestSuite):
pass pass

View File

@@ -2,19 +2,3 @@
# See license.txt # See license.txt
# import frappe # 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

View File

@@ -3,7 +3,6 @@
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, getdate, today from frappe.utils import add_days, getdate, today
from erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts import ( 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.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.test.accounts_mixin import AccountsTestMixin
from erpnext.tests.utils import ERPNextTestSuite
class TestProcessStatementOfAccounts(AccountsTestMixin, IntegrationTestCase): class TestProcessStatementOfAccounts(AccountsTestMixin, ERPNextTestSuite):
@classmethod def setUp(self):
def setUpClass(cls): frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0)
super().setUpClass()
letterhead = frappe.get_doc("Letter Head", "Company Letterhead - Grey") letterhead = frappe.get_doc("Letter Head", "Company Letterhead - Grey")
letterhead.is_default = 0 letterhead.is_default = 0
letterhead.save() 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_company()
self.create_customer() self.create_customer()
self.create_customer(customer_name="Other Customer") self.create_customer(customer_name="Other Customer")
@@ -101,9 +90,6 @@ class TestProcessStatementOfAccounts(AccountsTestMixin, IntegrationTestCase):
for age_range in expected_ageing: for age_range in expected_ageing:
self.assertEqual(expected_ageing[age_range], ageing.get(age_range)) self.assertEqual(expected_ageing[age_range], ageing.get(age_range))
def tearDown(self):
frappe.db.rollback()
def create_process_soa(**args): def create_process_soa(**args):
args = frappe._dict(args) args = frappe._dict(args)

View File

@@ -2,8 +2,10 @@
# See license.txt # See license.txt
# import frappe # import frappe
from frappe.tests import IntegrationTestCase
class TestProcessSubscription(IntegrationTestCase): from erpnext.tests.utils import ERPNextTestSuite
class TestProcessSubscription(ERPNextTestSuite):
pass pass

View File

@@ -3,13 +3,13 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.promotional_scheme.promotional_scheme import TransactionExists 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.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): def setUp(self):
if frappe.db.exists("Promotional Scheme", "_Test Scheme"): if frappe.db.exists("Promotional Scheme", "_Test Scheme"):
frappe.delete_doc("Promotional Scheme", "_Test Scheme") frappe.delete_doc("Promotional Scheme", "_Test Scheme")

View File

@@ -3,7 +3,6 @@
import frappe import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, cint, flt, getdate, nowdate, today from frappe.utils import add_days, cint, flt, getdate, nowdate, today
import erpnext 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.doctype.stock_entry.test_stock_entry import get_qty_after_transaction
from erpnext.stock.tests.test_utils import StockTestMixin from erpnext.stock.tests.test_utils import StockTestMixin
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Cost Center", "Payment Term", "Payment Terms Template"]
IGNORE_TEST_RECORD_DEPENDENCIES = ["Serial No"]
class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
@classmethod def setUp(self):
def setUpClass(cls):
super().setUpClass()
unlink_payment_on_cancel_of_invoice() unlink_payment_on_cancel_of_invoice()
frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1) frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
self.load_test_records("Purchase Invoice")
@classmethod self.load_test_records("Journal Entry")
def tearDownClass(cls):
unlink_payment_on_cancel_of_invoice(0)
def tearDown(self):
frappe.db.rollback()
def test_purchase_invoice_qty(self): def test_purchase_invoice_qty(self):
pi = make_purchase_invoice(qty=0, do_not_save=True) 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][1], gle.debit)
self.assertEqual(expected_values[gle.account][2], gle.credit) 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): def test_purchase_invoice_with_exchange_rate_difference(self):
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
make_purchase_invoice as create_purchase_invoice, 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 # fetching the latest GL Entry with exchange gain and loss account account
amount = frappe.db.get_value( 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( discrepancy_caused_by_exchange_rate_diff = abs(
pi.items[0].base_net_amount - pr.items[0].base_net_amount 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 # fetching the latest GL Entry with exchange gain and loss account account
amount = frappe.db.get_value( 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( discrepancy_caused_by_exchange_rate_diff = abs(
pi.items[1].base_net_amount - pr.items[1].base_net_amount 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): def test_purchase_invoice_change_naming_series(self):
pi = frappe.copy_doc(self.globalTestRecords["Purchase Invoice"][1]) 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.tax_amount, expected_values[i][1])
self.assertEqual(tax.total, expected_values[i][2]) self.assertEqual(tax.total, expected_values[i][2])
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
"Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}
)
def test_purchase_invoice_with_advance(self): def test_purchase_invoice_with_advance(self):
jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][1]) jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][1])
jv.insert() jv.insert()
@@ -562,9 +553,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin):
) )
) )
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
"Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}
)
def test_invoice_with_advance_and_multi_payment_terms(self): def test_invoice_with_advance_and_multi_payment_terms(self):
jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][1]) jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][1])
jv.insert() jv.insert()
@@ -1289,9 +1278,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin):
acc_settings.submit_journal_entriessubmit_journal_entries = 0 acc_settings.submit_journal_entriessubmit_journal_entries = 0
acc_settings.save() acc_settings.save()
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
"Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}
)
def test_gain_loss_with_advance_entry(self): def test_gain_loss_with_advance_entry(self):
unlink_enabled = frappe.db.get_single_value( unlink_enabled = frappe.db.get_single_value(
"Accounts Settings", "unlink_payment_on_cancellation_of_invoice" "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) frappe.db.set_value("Company", "_Test Company", "exchange_gain_loss_account", original_account)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
"Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}
)
def test_purchase_invoice_advance_taxes(self): def test_purchase_invoice_advance_taxes(self):
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry 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) rate = flt(sle.stock_value_difference) / flt(sle.actual_qty)
self.assertAlmostEqual(rate, 500) 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): def test_payment_allocation_for_payment_terms(self):
from erpnext.buying.doctype.purchase_order.test_purchase_order import ( from erpnext.buying.doctype.purchase_order.test_purchase_order import (
create_pr_against_po, create_pr_against_po,
@@ -2287,6 +2272,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin):
def test_create_purchase_invoice_without_mandatory(self): def test_create_purchase_invoice_without_mandatory(self):
pi = frappe.new_doc("Purchase Invoice") pi = frappe.new_doc("Purchase Invoice")
pi.company = "_Test Company"
pi.flags.ignore_mandatory = True pi.flags.ignore_mandatory = True
pi.insert(ignore_permissions=True) pi.insert(ignore_permissions=True)
@@ -2295,7 +2281,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin):
pi.delete() 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): def test_purchase_invoice_without_supplier_group(self):
# Create a Supplier # Create a Supplier
test_supplier_name = "_Test Supplier Without Supplier Group" test_supplier_name = "_Test Supplier Without Supplier Group"
@@ -2415,6 +2401,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin):
"doctype": "Serial No", "doctype": "Serial No",
"item_code": serial_item, "item_code": serial_item,
"serial_no": serial_no, "serial_no": serial_no,
"company": "_Test Company",
} }
).insert() ).insert()
@@ -2467,11 +2454,6 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin):
self.assertEqual(row.rejected_serial_no, serial_nos[2]) self.assertEqual(row.rejected_serial_no, serial_nos[2])
def test_make_pr_and_pi_from_po(self): 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 = create_item(
item_code="_Test_Item", is_stock_item=0, is_fixed_asset=1, asset_category="Computers" 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) 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} "Buying Settings", {"maintain_same_rate": 0, "set_landed_cost_based_on_purchase_invoice_rate": 1}
) )
def test_pr_status_rate_adjusted_from_pi(self): def test_pr_status_rate_adjusted_from_pi(self):

View File

@@ -2,8 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
from frappe.tests import IntegrationTestCase from erpnext.tests.utils import ERPNextTestSuite
class TestPurchaseTaxesandChargesTemplate(IntegrationTestCase): class TestPurchaseTaxesandChargesTemplate(ERPNextTestSuite):
pass pass

View File

@@ -4,7 +4,6 @@
import frappe import frappe
from frappe import qb from frappe import qb
from frappe.query_builder.functions import Sum from frappe.query_builder.functions import Sum
from frappe.tests import IntegrationTestCase
from frappe.utils import add_days, nowdate, today from frappe.utils import add_days, nowdate, today
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry 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.accounts.utils import get_fiscal_year
from erpnext.stock.doctype.item.test_item import make_item 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.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries, make_purchase_receipt
from erpnext.tests.utils import ERPNextTestSuite
class TestRepostAccountingLedger(AccountsTestMixin, IntegrationTestCase): class TestRepostAccountingLedger(AccountsTestMixin, ERPNextTestSuite):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0))
def setUp(self): def setUp(self):
self.create_company() self.create_company()
self.create_customer() self.create_customer()
self.create_item() self.create_item()
frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0)
update_repost_settings() update_repost_settings()
def tearDown(self):
frappe.db.rollback()
def test_01_basic_functions(self): def test_01_basic_functions(self):
si = create_sales_invoice( si = create_sales_invoice(
item=self.item, item=self.item,
@@ -121,7 +114,7 @@ class TestRepostAccountingLedger(AccountsTestMixin, IntegrationTestCase):
ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name}) ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name})
self.assertRaises(frappe.ValidationError, ral.save) 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): def test_04_pcv_validation(self):
# Clear old GL entries so PCV can be submitted. # Clear old GL entries so PCV can be submitted.
gl = frappe.qb.DocType("GL Entry") gl = frappe.qb.DocType("GL Entry")

View File

@@ -2,8 +2,10 @@
# See license.txt # See license.txt
# import frappe # import frappe
from frappe.tests import IntegrationTestCase
class TestRepostAccountingLedgerSettings(IntegrationTestCase): from erpnext.tests.utils import ERPNextTestSuite
class TestRepostAccountingLedgerSettings(ERPNextTestSuite):
pass pass

View File

@@ -2,8 +2,10 @@
# See license.txt # See license.txt
# import frappe # import frappe
from frappe.tests import IntegrationTestCase
class TestRepostPaymentLedger(IntegrationTestCase): from erpnext.tests.utils import ERPNextTestSuite
class TestRepostPaymentLedger(ERPNextTestSuite):
pass pass

View File

@@ -2777,7 +2777,7 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None):
"doctype": target_doctype, "doctype": target_doctype,
"postprocess": update_details, "postprocess": update_details,
"set_target_warehouse": "set_from_warehouse", "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, doctype + " Item": item_field_map,
}, },

View File

@@ -383,5 +383,390 @@
"price_list_currency": "INR", "price_list_currency": "INR",
"selling_price_list": "_Test Price List", "selling_price_list": "_Test Price List",
"territory": "_Test Territory" "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"
} }
] ]

View File

@@ -7,7 +7,6 @@ import json
import frappe import frappe
from frappe import qb from frappe import qb
from frappe.model.dynamic_links import get_dynamic_link_map 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 from frappe.utils import add_days, cint, flt, format_date, getdate, nowdate, today
import erpnext 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.doctype.sales_invoice.sales_invoice import make_inter_company_transaction
from erpnext.accounts.utils import PaymentEntryUnlinkError from erpnext.accounts.utils import PaymentEntryUnlinkError
from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries 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 ( from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
get_depr_schedule, get_depr_schedule,
) )
@@ -53,6 +52,11 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestSalesInvoice(ERPNextTestSuite): class TestSalesInvoice(ERPNextTestSuite):
def setUp(self): 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 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}]) 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"): for company in frappe.get_all("Company", pluck="name"):
frappe.db.set_value("Company", company, "accounts_frozen_till_date", None) 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", "Accounts Settings",
{"maintain_same_internal_transaction_rate": 1, "maintain_same_rate_action": "Stop"}, {"maintain_same_internal_transaction_rate": 1, "maintain_same_rate_action": "Stop"},
) )
@@ -86,9 +91,6 @@ class TestSalesInvoice(ERPNextTestSuite):
pi.submit() pi.submit()
self.assertIn("Rate must be same", str(e.exception)) self.assertIn("Rate must be same", str(e.exception))
def tearDown(self):
frappe.db.rollback()
def make(self): def make(self):
w = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][0]) w = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][0])
w.is_pos = 0 w.is_pos = 0
@@ -96,18 +98,6 @@ class TestSalesInvoice(ERPNextTestSuite):
w.submit() w.submit()
return w 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): def test_sales_invoice_qty(self):
si = create_sales_invoice(qty=0, do_not_save=True) si = create_sales_invoice(qty=0, do_not_save=True)
with self.assertRaises(InvalidQtyError): with self.assertRaises(InvalidQtyError):
@@ -229,9 +219,7 @@ class TestSalesInvoice(ERPNextTestSuite):
self.assertRaises(frappe.LinkExistsError, si.cancel) self.assertRaises(frappe.LinkExistsError, si.cancel)
unlink_payment_on_cancel_of_invoice() unlink_payment_on_cancel_of_invoice()
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
"Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}
)
def test_payment_entry_unlink_against_standalone_credit_note(self): def test_payment_entry_unlink_against_standalone_credit_note(self):
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
@@ -273,6 +261,9 @@ class TestSalesInvoice(ERPNextTestSuite):
si1.load_from_db() si1.load_from_db()
self.assertRaises(PaymentEntryUnlinkError, si1.cancel) 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): def test_sales_invoice_calculation_export_currency(self):
si = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][2]) si = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][2])
si.currency = "USD" si.currency = "USD"
@@ -536,6 +527,7 @@ class TestSalesInvoice(ERPNextTestSuite):
self.assertTrue(gle) self.assertTrue(gle)
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True})
def test_tax_calculation_with_multiple_items(self): def test_tax_calculation_with_multiple_items(self):
si = create_sales_invoice(qty=84, rate=4.6, do_not_save=True) si = create_sales_invoice(qty=84, rate=4.6, do_not_save=True)
item_row = si.get("items")[0] item_row = si.get("items")[0]
@@ -564,6 +556,7 @@ class TestSalesInvoice(ERPNextTestSuite):
self.assertEqual(si.grand_total, 5474.0) 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): def test_tax_calculation_with_item_tax_template(self):
si = create_sales_invoice(qty=84, rate=4.6, do_not_save=True) si = create_sales_invoice(qty=84, rate=4.6, do_not_save=True)
item_row = si.get("items")[0] item_row = si.get("items")[0]
@@ -630,6 +623,7 @@ class TestSalesInvoice(ERPNextTestSuite):
self.assertEqual(si.rounding_adjustment, 0.43) self.assertEqual(si.rounding_adjustment, 0.43)
self.assertEqual(si.rounded_total, 5676.0) 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): def test_tax_calculation_with_multiple_items_and_discount(self):
si = create_sales_invoice(qty=1, rate=75, do_not_save=True) si = create_sales_invoice(qty=1, rate=75, do_not_save=True)
item_row = si.get("items")[0] item_row = si.get("items")[0]
@@ -754,6 +748,9 @@ class TestSalesInvoice(ERPNextTestSuite):
self.assertEqual(si.base_grand_total, 1622.97) self.assertEqual(si.base_grand_total, 1622.97)
self.assertEqual(si.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): def test_sales_invoice_calculation_export_currency_with_tax_inclusive_price(self):
# prepare # prepare
si = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][3]) si = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][3])
@@ -844,7 +841,7 @@ class TestSalesInvoice(ERPNextTestSuite):
w = self.make() w = self.make()
self.assertEqual(w.outstanding_amount, w.base_rounded_total) self.assertEqual(w.outstanding_amount, w.base_rounded_total)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{"add_taxes_from_item_tax_template": 0, "add_taxes_from_taxes_and_charges_template": 0}, {"add_taxes_from_item_tax_template": 0, "add_taxes_from_taxes_and_charges_template": 0},
) )
@@ -1401,9 +1398,7 @@ class TestSalesInvoice(ERPNextTestSuite):
dn.submit() dn.submit()
return dn return dn
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
"Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}
)
def test_sales_invoice_with_advance(self): def test_sales_invoice_with_advance(self):
jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][0]) jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][0])
jv.insert() jv.insert()
@@ -1624,7 +1619,6 @@ class TestSalesInvoice(ERPNextTestSuite):
self.assertRaises(frappe.ValidationError, cr_note.save) self.assertRaises(frappe.ValidationError, cr_note.save)
def test_gle_made_when_asset_is_returned(self): def test_gle_made_when_asset_is_returned(self):
create_asset_data()
asset = create_asset(item_code="Macbook Pro") asset = create_asset(item_code="Macbook Pro")
si = create_sales_invoice(item_code="Macbook Pro", asset=asset.name, qty=1, rate=90000) si = create_sales_invoice(item_code="Macbook Pro", asset=asset.name, qty=1, rate=90000)
@@ -2131,17 +2125,21 @@ class TestSalesInvoice(ERPNextTestSuite):
si.insert() si.insert()
return si return si
@ERPNextTestSuite.change_settings("Selling Settings", {"sales_update_frequency": "Each Transaction"})
def test_company_monthly_sales(self): def test_company_monthly_sales(self):
existing_current_month_sales = frappe.get_cached_value( from erpnext.setup.doctype.company.company import update_company_current_month_sales
"Company", "_Test Company", "total_monthly_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() 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) self.assertEqual(current_month_sales, existing_current_month_sales + si.base_grand_total)
si.cancel() 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) self.assertEqual(current_month_sales, existing_current_month_sales)
def test_rounding_adjustment(self): 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][1], gle.debit)
self.assertEqual(expected_values[gle.account][2], gle.credit) self.assertEqual(expected_values[gle.account][2], gle.credit)
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True})
def test_rounding_adjustment_2(self): def test_rounding_adjustment_2(self):
si = create_sales_invoice(rate=400, do_not_save=True) si = create_sales_invoice(rate=400, do_not_save=True)
for rate in [400.25, 600.30, 100.65]: 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[0], gle.debit)
self.assertEqual(expected_account_values[1], gle.credit) self.assertEqual(expected_account_values[1], gle.credit)
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True})
def test_rounding_adjustment_3(self): def test_rounding_adjustment_3(self):
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import create_dimension from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import create_dimension
@@ -2484,7 +2484,7 @@ class TestSalesInvoice(ERPNextTestSuite):
for gle in gl_entries: for gle in gl_entries:
self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{"book_deferred_entries_based_on": "Days", "book_deferred_entries_via_journal_entry": 0}, {"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) self.assertRaises(frappe.ValidationError, si.save)
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{"book_deferred_entries_based_on": "Months", "book_deferred_entries_via_journal_entry": 0}, {"book_deferred_entries_based_on": "Months", "book_deferred_entries_via_journal_entry": 0},
) )
@@ -3005,7 +3005,7 @@ class TestSalesInvoice(ERPNextTestSuite):
si.submit() 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): def test_sales_invoice_with_discount_accounting_enabled(self):
discount_account = create_account( discount_account = create_account(
account_name="Discount Account", account_name="Discount Account",
@@ -3022,7 +3022,7 @@ class TestSalesInvoice(ERPNextTestSuite):
check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1)) 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): def test_additional_discount_for_sales_invoice_with_discount_accounting_enabled(self):
from erpnext.accounts.doctype.repost_accounting_ledger.test_repost_accounting_ledger import ( from erpnext.accounts.doctype.repost_accounting_ledger.test_repost_accounting_ledger import (
update_repost_settings, 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. 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) asset = create_asset(item_code="Macbook Pro", calculate_depreciation=1, submit=1)
post_depreciation_entries(getdate("2021-09-30")) 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. 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( asset = create_asset(
item_code="Macbook Pro", item_code="Macbook Pro",
calculate_depreciation=1, calculate_depreciation=1,
@@ -3460,7 +3458,8 @@ class TestSalesInvoice(ERPNextTestSuite):
si.submit() si.submit()
frappe.db.set_value("Company", "_Test Company", "accounts_frozen_till_date", None) 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): def test_over_billing_case_against_delivery_note(self):
""" """
Test a case where duplicating the item with qty = 1 in the invoice 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()) self.assertTrue("cannot overbill" in str(err.exception).lower())
dn.cancel() dn.cancel()
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings(
"Accounts Settings", "Accounts Settings",
{ {
"book_deferred_entries_via_journal_entry": 1, "book_deferred_entries_via_journal_entry": 1,
@@ -3604,9 +3603,7 @@ class TestSalesInvoice(ERPNextTestSuite):
account.disabled = 0 account.disabled = 0
account.save() account.save()
@IntegrationTestCase.change_settings( @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
"Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}
)
def test_gain_loss_with_advance_entry(self): def test_gain_loss_with_advance_entry(self):
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry 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="") 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): def test_sales_invoice_without_customer_group_and_territory(self):
# create a customer # create a customer
if not frappe.db.exists("Customer", "_Test Simple 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.customer_group, None)
self.assertEqual(si.territory, 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): def test_sales_return_negative_rate(self):
si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True) si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True)
self.assertRaises(frappe.ValidationError, si.save) self.assertRaises(frappe.ValidationError, si.save)
@@ -3884,19 +3881,18 @@ class TestSalesInvoice(ERPNextTestSuite):
def test_loyalty_points_redemption_with_shopping_cart(self): def test_loyalty_points_redemption_with_shopping_cart(self):
from erpnext.accounts.doctype.loyalty_program.test_loyalty_program import ( from erpnext.accounts.doctype.loyalty_program.test_loyalty_program import (
create_records,
create_sales_invoice_record, create_sales_invoice_record,
) )
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
# Set up loyalty program # Set up loyalty program
create_records() loyalty_customer = frappe.get_doc("Customer", {"customer_name": "Test Loyalty Customer"}).name
frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") frappe.db.set_value("Customer", loyalty_customer, "loyalty_program", "Test Single Loyalty")
create_sales_invoice_record(10).insert().submit() create_sales_invoice_record(10).insert().submit()
# Create a sales order # 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.name = "_T-Sales Order LP-0001"
so.order_type = "Shopping Cart" so.order_type = "Shopping Cart"
so.loyalty_points = 50 so.loyalty_points = 50
@@ -4174,12 +4170,14 @@ class TestSalesInvoice(ERPNextTestSuite):
si.save() si.save()
return si return si
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True})
def test_rounding_validation_for_opening_with_inclusive_tax(self): def test_rounding_validation_for_opening_with_inclusive_tax(self):
si = self._create_opening_invoice_with_inclusive_tax() si = self._create_opening_invoice_with_inclusive_tax()
# 'Round Off for Opening' not set in Company master # 'Round Off for Opening' not set in Company master
# Ledger level validation must be thrown # Ledger level validation must be thrown
self.assertRaises(frappe.ValidationError, si.submit) 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): def test_ledger_entries_on_opening_invoice_with_rounding_loss_by_inclusive_tax(self):
si = self._create_opening_invoice_with_inclusive_tax() si = self._create_opening_invoice_with_inclusive_tax()
# 'Round Off for Opening' is set in Company master # 'Round Off for Opening' is set in Company master
@@ -4201,7 +4199,7 @@ class TestSalesInvoice(ERPNextTestSuite):
self.assertEqual(len(actual), 4) self.assertEqual(len(actual), 4)
self.assertEqual(expected, actual) 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): def test_common_party_with_foreign_currency_jv(self):
from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( 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.assertTrue(jv)
self.assertEqual(jv[0], si.grand_total) 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): 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.account.test_account import create_account
from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( 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])) 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): def test_total_billed_amount(self):
si = create_sales_invoice(do_not_submit=True) si = create_sales_invoice(do_not_submit=True)
@@ -4407,6 +4406,8 @@ class TestSalesInvoice(ERPNextTestSuite):
doc = frappe.get_doc("Project", project.name) doc = frappe.get_doc("Project", project.name)
self.assertEqual(doc.total_billed_amount, si.grand_total) 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): 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 # 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 from copy import copy
@@ -4745,7 +4746,7 @@ class TestSalesInvoice(ERPNextTestSuite):
doc.db_set("do_not_use_batchwise_valuation", original_value) 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): def test_zero_valuation_for_standalone_credit_note_with_expired_batch(self):
item_code = "_Test Item for Expiry Batch Zero Valuation" item_code = "_Test Item for Expiry Batch Zero Valuation"
make_item_for_si( make_item_for_si(
@@ -4805,6 +4806,33 @@ class TestSalesInvoice(ERPNextTestSuite):
self.assertEqual(stock_ledger_entry.incoming_rate, 0.0) 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): def make_item_for_si(item_code, properties=None):
from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.item.test_item import make_item
@@ -4989,9 +5017,6 @@ def create_sales_invoice_against_cost_center(**args):
return si return si
EXTRA_TEST_RECORD_DEPENDENCIES = ["Journal Entry", "Contact", "Address"]
def get_outstanding_amount(against_voucher_type, against_voucher, account, party, party_type): def get_outstanding_amount(against_voucher_type, against_voucher, account, party, party_type):
bal = flt( bal = flt(
frappe.db.sql( frappe.db.sql(

View File

@@ -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
}]
}
]

View File

@@ -2,9 +2,8 @@
# See license.txt # See license.txt
import unittest import unittest
import frappe from erpnext.tests.utils import ERPNextTestSuite
from frappe.tests import IntegrationTestCase
class TestSalesTaxesandChargesTemplate(IntegrationTestCase): class TestSalesTaxesandChargesTemplate(ERPNextTestSuite):
pass pass

View File

@@ -3,14 +3,12 @@
import unittest import unittest
import frappe import frappe
from frappe.tests import IntegrationTestCase
from erpnext.accounts.doctype.share_transfer.share_transfer import ShareDontExists from erpnext.accounts.doctype.share_transfer.share_transfer import ShareDontExists
from erpnext.tests.utils import ERPNextTestSuite
EXTRA_TEST_RECORD_DEPENDENCIES = ["Share Type", "Shareholder"]
class TestShareTransfer(IntegrationTestCase): class TestShareTransfer(ERPNextTestSuite):
def setUp(self): def setUp(self):
frappe.db.sql("delete from `tabShare Transfer`") frappe.db.sql("delete from `tabShare Transfer`")
frappe.db.sql("delete from `tabShare Balance`") frappe.db.sql("delete from `tabShare Balance`")

View File

@@ -1,10 +0,0 @@
[
{
"doctype": "Share Type",
"title": "Class A"
},
{
"doctype": "Share Type",
"title": "Class B"
}
]

Some files were not shown because too many files have changed in this diff Show More