Merge pull request #53657 from ruthra-kumar/move_commits_inside_test_guard_clause

refactor(test): move remaining commits inside test guard
This commit is contained in:
ruthra kumar
2026-03-24 17:43:17 +05:30
committed by GitHub
29 changed files with 255 additions and 331 deletions

View File

@@ -9,9 +9,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestAccountingDimension(ERPNextTestSuite): class TestAccountingDimension(ERPNextTestSuite):
def setUp(self):
create_dimension()
def test_dimension_against_sales_invoice(self): def test_dimension_against_sales_invoice(self):
si = create_sales_invoice(do_not_save=1) si = create_sales_invoice(do_not_save=1)
@@ -76,63 +73,3 @@ class TestAccountingDimension(ERPNextTestSuite):
si.save() si.save()
self.assertRaises(frappe.ValidationError, si.submit) self.assertRaises(frappe.ValidationError, si.submit)
def create_dimension():
frappe.set_user("Administrator")
if not frappe.db.exists("Accounting Dimension", {"document_type": "Department"}):
dimension = frappe.get_doc(
{
"doctype": "Accounting Dimension",
"document_type": "Department",
}
)
dimension.append(
"dimension_defaults",
{
"company": "_Test Company",
"reference_document": "Department",
"default_dimension": "_Test Department - _TC",
},
)
dimension.insert()
dimension.save()
else:
dimension = frappe.get_doc("Accounting Dimension", "Department")
dimension.disabled = 0
dimension.save()
if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}):
dimension1 = frappe.get_doc(
{
"doctype": "Accounting Dimension",
"document_type": "Location",
}
)
dimension1.append(
"dimension_defaults",
{
"company": "_Test Company",
"reference_document": "Location",
"default_dimension": "Block 1",
},
)
dimension1.insert()
dimension1.save()
else:
dimension1 = frappe.get_doc("Accounting Dimension", "Location")
dimension1.disabled = 0
dimension1.save()
def disable_dimension():
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
dimension1.disabled = 1
dimension1.save()
dimension2 = frappe.get_doc("Accounting Dimension", "Location")
dimension2.disabled = 1
dimension2.save()

View File

@@ -3,9 +3,6 @@
import frappe import frappe
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension,
)
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 from erpnext.tests.utils import ERPNextTestSuite
@@ -13,7 +10,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestAccountingDimensionFilter(ERPNextTestSuite): class TestAccountingDimensionFilter(ERPNextTestSuite):
def setUp(self): def setUp(self):
create_dimension()
create_accounting_dimension_filter() create_accounting_dimension_filter()
self.invoice_list = [] self.invoice_list = []

View File

@@ -489,4 +489,5 @@ def rename_temporarily_named_docs(doctype):
for hook in frappe.get_hooks(hook_type): for hook in frappe.get_hooks(hook_type):
frappe.call(hook, newname=newname, oldname=oldname) frappe.call(hook, newname=newname, oldname=oldname)
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()

View File

@@ -71,14 +71,16 @@ def start_merge(docname):
ledger_merge.account, ledger_merge.account,
) )
row.db_set("merged", 1) row.db_set("merged", 1)
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
successful_merges += 1 successful_merges += 1
frappe.publish_realtime( frappe.publish_realtime(
"ledger_merge_progress", "ledger_merge_progress",
{"ledger_merge": ledger_merge.name, "current": successful_merges, "total": total}, {"ledger_merge": ledger_merge.name, "current": successful_merges, "total": total},
) )
except Exception: except Exception:
frappe.db.rollback() if not frappe.in_test:
frappe.db.rollback()
ledger_merge.log_error("Ledger merge failed") ledger_merge.log_error("Ledger merge failed")
finally: finally:
if successful_merges == total: if successful_merges == total:

View File

@@ -274,7 +274,8 @@ def start_import(invoices):
doc.flags.ignore_mandatory = True doc.flags.ignore_mandatory = True
doc.insert(set_name=invoice_number) doc.insert(set_name=invoice_number)
doc.submit() doc.submit()
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
names.append(doc.name) names.append(doc.name)
except Exception: except Exception:
errors += 1 errors += 1

View File

@@ -3,9 +3,6 @@
import frappe import frappe
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension,
)
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,
) )
@@ -13,11 +10,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestOpeningInvoiceCreationTool(ERPNextTestSuite): class TestOpeningInvoiceCreationTool(ERPNextTestSuite):
def setUp(self):
if not frappe.db.exists("Company", "_Test Opening Invoice Company"):
make_company()
create_dimension()
def make_invoices( def make_invoices(
self, self,
invoice_type="Sales", invoice_type="Sales",
@@ -182,19 +174,6 @@ def get_opening_invoice_creation_dict(**args):
return invoice_dict return invoice_dict
def make_company():
if frappe.db.exists("Company", "_Test Opening Invoice Company"):
return frappe.get_doc("Company", "_Test Opening Invoice Company")
company = frappe.new_doc("Company")
company.company_name = "_Test Opening Invoice Company"
company.abbr = "_TOIC"
company.default_currency = "INR"
company.country = "Pakistan"
company.insert()
return company
def make_customer(customer=None): def make_customer(customer=None):
customer_name = customer or "Opening Customer" customer_name = customer or "Opening Customer"
customer = frappe.get_doc( customer = frappe.get_doc(

View File

@@ -750,7 +750,8 @@ def make_payment_request(**args):
pr.submit() pr.submit()
if args.order_type == "Shopping Cart": if args.order_type == "Shopping Cart":
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
frappe.local.response["type"] = "redirect" frappe.local.response["type"] = "redirect"
frappe.local.response["location"] = pr.get_payment_url() frappe.local.response["location"] = pr.get_payment_url()

View File

@@ -3,10 +3,6 @@
import frappe import frappe
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension,
disable_dimension,
)
from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import ( from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import (
make_closing_entry_from_opening, make_closing_entry_from_opening,
) )
@@ -161,7 +157,6 @@ class TestPOSClosingEntry(ERPNextTestSuite):
test case to check whether we can create POS Closing Entry without mandatory accounting dimension test case to check whether we can create POS Closing Entry without mandatory accounting dimension
""" """
create_dimension()
location = frappe.get_doc("Accounting Dimension", "Location") location = frappe.get_doc("Accounting Dimension", "Location")
location.dimension_defaults[0].mandatory_for_bs = True location.dimension_defaults[0].mandatory_for_bs = True
location.save() location.save()
@@ -197,7 +192,6 @@ class TestPOSClosingEntry(ERPNextTestSuite):
) )
accounting_dimension_department.mandatory_for_bs = 0 accounting_dimension_department.mandatory_for_bs = 0
accounting_dimension_department.save() accounting_dimension_department.save()
disable_dimension()
def test_merging_into_sales_invoice_for_batched_item(self): def test_merging_into_sales_invoice_for_batched_item(self):
frappe.flags.print_message = False frappe.flags.print_message = False

View File

@@ -566,10 +566,10 @@ def send_emails(document_name: str, from_scheduler: bool = False, posting_date:
new_from_date = add_months(new_to_date, -1 * doc.filter_duration) new_from_date = add_months(new_to_date, -1 * doc.filter_duration)
doc.add_comment("Comment", "Emails sent on: " + frappe.utils.format_datetime(frappe.utils.now())) doc.add_comment("Comment", "Emails sent on: " + frappe.utils.format_datetime(frappe.utils.now()))
if doc.report == "General Ledger": if doc.report == "General Ledger":
doc.db_set("to_date", new_to_date, commit=True) frappe.db.set_value(doc.doctype, doc.name, "to_date", new_to_date)
doc.db_set("from_date", new_from_date, commit=True) frappe.db.set_value(doc.doctype, doc.name, "from_date", new_from_date)
else: else:
doc.db_set("posting_date", new_to_date, commit=True) frappe.db.set_value(doc.doctype, doc.name, "posting_date", new_to_date)
return True return True
else: else:
return False return False

View File

@@ -2189,11 +2189,6 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
def test_offsetting_entries_for_accounting_dimensions(self): def test_offsetting_entries_for_accounting_dimensions(self):
from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.report.trial_balance.test_trial_balance import (
clear_dimension_defaults,
create_accounting_dimension,
disable_dimension,
)
create_account( create_account(
account_name="Offsetting", account_name="Offsetting",
@@ -2201,7 +2196,16 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
parent_account="Temporary Accounts - _TC", parent_account="Temporary Accounts - _TC",
) )
create_accounting_dimension(company="_Test Company", offsetting_account="Offsetting - _TC") dim = frappe.get_doc("Accounting Dimension", "Branch")
dim.append(
"dimension_defaults",
{
"company": "_Test Company",
"reference_document": "Branch",
"offsetting_account": "Offsetting - _TC",
},
)
dim.save()
branch1 = frappe.new_doc("Branch") branch1 = frappe.new_doc("Branch")
branch1.branch = "Location 1" branch1.branch = "Location 1"
@@ -2238,8 +2242,6 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin):
voucher_type="Purchase Invoice", voucher_type="Purchase Invoice",
additional_columns=["branch"], additional_columns=["branch"],
) )
clear_dimension_defaults("Branch")
disable_dimension()
def test_repost_accounting_entries(self): def test_repost_accounting_entries(self):
# update repost settings # update repost settings

View File

@@ -2246,13 +2246,6 @@ class TestSalesInvoice(ERPNextTestSuite):
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) @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
# Dimension creates custom field, which does an implicit DB commit as it is a DDL command
# Ensure dimension don't have any mandatory fields
create_dimension()
# rollback from tearDown() happens till here
si = create_sales_invoice(do_not_save=True) si = create_sales_invoice(do_not_save=True)
si.items = [] si.items = []
for d in [(1122, 2), (1122.01, 1), (1122.01, 1)]: for d in [(1122, 2), (1122.01, 1), (1122.01, 1)]:

View File

@@ -772,7 +772,8 @@ def process_all(subscription: list, posting_date: DateTimeLikeObject | None = No
try: try:
subscription = frappe.get_doc("Subscription", subscription_name) subscription = frappe.get_doc("Subscription", subscription_name)
subscription.process(posting_date) subscription.process(posting_date)
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
except frappe.ValidationError: except frappe.ValidationError:
frappe.db.rollback() frappe.db.rollback()
subscription.log_error("Subscription failed") subscription.log_error("Subscription failed")

View File

@@ -18,7 +18,6 @@ class TestTaxWithholdingCategory(ERPNextTestSuite):
# create relevant supplier, etc # create relevant supplier, etc
create_records() create_records()
create_tax_withholding_category_records() create_tax_withholding_category_records()
make_pan_no_field()
def validate_tax_withholding_entries(self, doctype, docname, expected_entries): def validate_tax_withholding_entries(self, doctype, docname, expected_entries):
"""Validate tax withholding entries for a document""" """Validate tax withholding entries for a document"""
@@ -3998,18 +3997,3 @@ def create_lower_deduction_certificate(
"certificate_limit": limit, "certificate_limit": limit,
} }
).insert() ).insert()
def make_pan_no_field():
pan_field = {
"Supplier": [
{
"fieldname": "pan",
"label": "PAN",
"fieldtype": "Data",
"translatable": 0,
}
]
}
create_custom_fields(pan_field, update=1)

View File

@@ -14,7 +14,6 @@ class TestTrialBalance(ERPNextTestSuite):
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
from erpnext.accounts.utils import get_fiscal_year from erpnext.accounts.utils import get_fiscal_year
self.company = create_company()
create_cost_center( create_cost_center(
cost_center_name="Test Cost Center", cost_center_name="Test Cost Center",
company="Trial Balance Company", company="Trial Balance Company",
@@ -26,7 +25,16 @@ class TestTrialBalance(ERPNextTestSuite):
parent_account="Temporary Accounts - TBC", parent_account="Temporary Accounts - TBC",
) )
self.fiscal_year = get_fiscal_year(today(), company="Trial Balance Company")[0] self.fiscal_year = get_fiscal_year(today(), company="Trial Balance Company")[0]
create_accounting_dimension() dim = frappe.get_doc("Accounting Dimension", "Branch")
dim.append(
"dimension_defaults",
{
"company": "Trial Balance Company",
"automatically_post_balancing_accounting_entry": 1,
"offsetting_account": "Offsetting - TBC",
},
)
dim.save()
def test_offsetting_entries_for_accounting_dimensions(self): def test_offsetting_entries_for_accounting_dimensions(self):
""" """
@@ -45,7 +53,7 @@ class TestTrialBalance(ERPNextTestSuite):
branch2.insert(ignore_if_duplicate=True) branch2.insert(ignore_if_duplicate=True)
si = create_sales_invoice( si = create_sales_invoice(
company=self.company, company="Trial Balance Company",
debit_to="Debtors - TBC", debit_to="Debtors - TBC",
cost_center="Test Cost Center - TBC", cost_center="Test Cost Center - TBC",
income_account="Sales - TBC", income_account="Sales - TBC",
@@ -57,60 +65,7 @@ class TestTrialBalance(ERPNextTestSuite):
si.submit() si.submit()
filters = frappe._dict( filters = frappe._dict(
{"company": self.company, "fiscal_year": self.fiscal_year, "branch": ["Location 1"]} {"company": "Trial Balance Company", "fiscal_year": self.fiscal_year, "branch": ["Location 1"]}
) )
total_row = execute(filters)[1][-1] total_row = execute(filters)[1][-1]
self.assertEqual(total_row["debit"], total_row["credit"]) self.assertEqual(total_row["debit"], total_row["credit"])
def create_company(**args):
args = frappe._dict(args)
company = frappe.get_doc(
{
"doctype": "Company",
"company_name": args.company_name or "Trial Balance Company",
"country": args.country or "India",
"default_currency": args.currency or "INR",
"parent_company": args.get("parent_company"),
"is_group": args.get("is_group"),
}
)
company.insert(ignore_if_duplicate=True)
return company.name
def create_accounting_dimension(**args):
args = frappe._dict(args)
document_type = args.document_type or "Branch"
if frappe.db.exists("Accounting Dimension", document_type):
accounting_dimension = frappe.get_doc("Accounting Dimension", document_type)
accounting_dimension.disabled = 0
else:
accounting_dimension = frappe.new_doc("Accounting Dimension")
accounting_dimension.document_type = document_type
accounting_dimension.insert()
accounting_dimension.set("dimension_defaults", [])
accounting_dimension.append(
"dimension_defaults",
{
"company": args.company or "Trial Balance Company",
"automatically_post_balancing_accounting_entry": 1,
"offsetting_account": args.offsetting_account or "Offsetting - TBC",
},
)
accounting_dimension.save()
def disable_dimension(**args):
args = frappe._dict(args)
document_type = args.document_type or "Branch"
dimension = frappe.get_doc("Accounting Dimension", document_type)
dimension.disabled = 1
dimension.save()
def clear_dimension_defaults(dimension_name):
accounting_dimension = frappe.get_doc("Accounting Dimension", dimension_name)
accounting_dimension.dimension_defaults = []
accounting_dimension.save()

View File

@@ -62,7 +62,9 @@ def book_depreciation_entries(date):
accounting_dimensions, accounting_dimensions,
) )
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
except Exception as e: except Exception as e:
frappe.db.rollback() frappe.db.rollback()
failed_assets.append(asset_name) failed_assets.append(asset_name)
@@ -72,7 +74,8 @@ def book_depreciation_entries(date):
if failed_assets: if failed_assets:
set_depr_entry_posting_status_for_failed_assets(failed_assets) set_depr_entry_posting_status_for_failed_assets(failed_assets)
notify_depr_entry_posting_error(failed_assets, error_logs) notify_depr_entry_posting_error(failed_assets, error_logs)
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
def get_depreciable_assets_data(date): def get_depreciable_assets_data(date):

View File

@@ -376,6 +376,7 @@ class TestAssetCapitalization(ERPNextTestSuite):
"asset_type": "Composite Component", "asset_type": "Composite Component",
"purchase_date": pr.posting_date, "purchase_date": pr.posting_date,
"available_for_use_date": pr.posting_date, "available_for_use_date": pr.posting_date,
"location": "Test Location",
} }
) )
consumed_asset_doc.save() consumed_asset_doc.save()

View File

@@ -15,7 +15,6 @@ class TestAssetMovement(ERPNextTestSuite):
frappe.db.set_value( frappe.db.set_value(
"Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC" "Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC"
) )
make_location()
def test_movement(self): def test_movement(self):
pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location")
@@ -39,10 +38,6 @@ class TestAssetMovement(ERPNextTestSuite):
if asset.docstatus == 0: if asset.docstatus == 0:
asset.submit() asset.submit()
# check asset movement is created
if not frappe.db.exists("Location", "Test Location 2"):
frappe.get_doc({"doctype": "Location", "location_name": "Test Location 2"}).insert()
create_asset_movement( create_asset_movement(
purpose="Transfer", purpose="Transfer",
company=asset.company, company=asset.company,
@@ -121,9 +116,6 @@ class TestAssetMovement(ERPNextTestSuite):
if asset.docstatus == 0: if asset.docstatus == 0:
asset.submit() asset.submit()
if not frappe.db.exists("Location", "Test Location 2"):
frappe.get_doc({"doctype": "Location", "location_name": "Test Location 2"}).insert()
movement = frappe.get_doc({"doctype": "Asset Movement", "reference_name": pr.name}) movement = frappe.get_doc({"doctype": "Asset Movement", "reference_name": pr.name})
self.assertRaises(frappe.ValidationError, movement.cancel) self.assertRaises(frappe.ValidationError, movement.cancel)
@@ -149,9 +141,6 @@ class TestAssetMovement(ERPNextTestSuite):
asset = create_asset(item_code="Macbook Pro", do_not_save=1) asset = create_asset(item_code="Macbook Pro", do_not_save=1)
asset.save().submit() asset.save().submit()
if not frappe.db.exists("Location", "Test Location 2"):
frappe.get_doc({"doctype": "Location", "location_name": "Test Location 2"}).insert()
asset_creation_date = frappe.db.get_value( asset_creation_date = frappe.db.get_value(
"Asset Movement", "Asset Movement",
[["Asset Movement Item", "asset", "=", asset.name], ["docstatus", "=", 1]], [["Asset Movement Item", "asset", "=", asset.name], ["docstatus", "=", 1]],
@@ -196,9 +185,3 @@ def create_asset_movement(**args):
movement.submit() movement.submit()
return movement return movement
def make_location():
for location in ["Pune", "Mumbai", "Nagpur"]:
if not frappe.db.exists("Location", location):
frappe.get_doc({"doctype": "Location", "location_name": location}).insert(ignore_permissions=True)

View File

@@ -785,7 +785,8 @@ def make_purchase_invoice_from_portal(purchase_order_name: str):
if frappe.session.user not in frappe.get_all("Portal User", {"parent": doc.supplier}, pluck="user"): if frappe.session.user not in frappe.get_all("Portal User", {"parent": doc.supplier}, pluck="user"):
frappe.throw(_("Not Permitted"), frappe.PermissionError) frappe.throw(_("Not Permitted"), frappe.PermissionError)
doc.save() doc.save()
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
frappe.response["type"] = "redirect" frappe.response["type"] = "redirect"
frappe.response.location = "/purchase-invoices/" + doc.name frappe.response.location = "/purchase-invoices/" + doc.name

View File

@@ -1567,25 +1567,10 @@ class TestAccountsController(ERPNextTestSuite):
frappe.db.set_value("Company", self.company, "cost_center", cc) frappe.db.set_value("Company", self.company, "cost_center", cc)
def setup_dimensions(self):
# create dimension
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension,
)
create_dimension()
# make it non-mandatory
loc = frappe.get_doc("Accounting Dimension", "Location")
for x in loc.dimension_defaults:
x.mandatory_for_bs = False
x.mandatory_for_pl = False
loc.save()
def test_90_dimensions_filter(self): def test_90_dimensions_filter(self):
""" """
Test workings of dimension filters Test workings of dimension filters
""" """
self.setup_dimensions()
rate_in_account_currency = 1 rate_in_account_currency = 1
# Invoices # Invoices
@@ -1653,7 +1638,6 @@ class TestAccountsController(ERPNextTestSuite):
self.assertEqual(len(pr.payments), 1) self.assertEqual(len(pr.payments), 1)
def test_91_cr_note_should_inherit_dimension(self): def test_91_cr_note_should_inherit_dimension(self):
self.setup_dimensions()
rate_in_account_currency = 1 rate_in_account_currency = 1
# Invoice # Invoice
@@ -1698,7 +1682,6 @@ class TestAccountsController(ERPNextTestSuite):
def test_92_dimension_inhertiance_exc_gain_loss(self): def test_92_dimension_inhertiance_exc_gain_loss(self):
# Sales Invoice in Foreign Currency # Sales Invoice in Foreign Currency
self.setup_dimensions()
rate_in_account_currency = 1 rate_in_account_currency = 1
dpt = "Research & Development - _TC" dpt = "Research & Development - _TC"
@@ -1734,7 +1717,6 @@ class TestAccountsController(ERPNextTestSuite):
) )
def test_93_dimension_inheritance_on_advance(self): def test_93_dimension_inheritance_on_advance(self):
self.setup_dimensions()
dpt = "Research & Development - _TC" dpt = "Research & Development - _TC"
adv = self.create_payment_entry(amount=1, source_exc_rate=85) adv = self.create_payment_entry(amount=1, source_exc_rate=85)

View File

@@ -120,7 +120,8 @@ class Appointment(Document):
self.auto_assign() self.auto_assign()
self.create_calendar_event() self.create_calendar_event()
self.save(ignore_permissions=True) self.save(ignore_permissions=True)
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
def create_lead_and_link(self): def create_lead_and_link(self):
# Return if already linked # Return if already linked

View File

@@ -926,7 +926,7 @@ def update_transactions_annual_history(company, commit=False):
transactions_history = get_all_transactions_annual_history(company) transactions_history = get_all_transactions_annual_history(company)
frappe.db.set_value("Company", company, "transactions_annual_history", json.dumps(transactions_history)) frappe.db.set_value("Company", company, "transactions_annual_history", json.dumps(transactions_history))
if commit: if commit and not frappe.in_test:
frappe.db.commit() frappe.db.commit()
@@ -935,7 +935,9 @@ def cache_companies_monthly_sales_history():
for company in companies: for company in companies:
update_company_monthly_sales(company) update_company_monthly_sales(company)
update_transactions_annual_history(company) update_transactions_annual_history(company)
frappe.db.commit()
if not frappe.in_test:
frappe.db.commit()
@frappe.whitelist() @frappe.whitelist()

View File

@@ -180,5 +180,39 @@
"default_currency": "ZAR", "default_currency": "ZAR",
"doctype": "Company", "doctype": "Company",
"create_chart_of_accounts_based_on": "Standard Template" "create_chart_of_accounts_based_on": "Standard Template"
},
{
"abbr": "_TOIC",
"company_name": "_Test Opening Invoice Company",
"country": "Pakistan",
"default_currency": "INR",
"doctype": "Company",
"create_chart_of_accounts_based_on": "Standard Template"
},
{
"abbr": "TBC",
"company_name": "Trial Balance Company",
"country": "India",
"default_currency": "INR",
"doctype": "Company",
"create_chart_of_accounts_based_on": "Standard Template"
},
{
"abbr": "_TSS",
"company_name": "_Test Support SLA",
"country": "India",
"default_currency": "INR",
"doctype": "Company",
"chart_of_accounts": "Standard",
"create_chart_of_accounts_based_on": "Standard Template"
},
{
"abbr": "TQC",
"company_name": "Test Quality Company",
"country": "India",
"default_currency": "INR",
"doctype": "Company",
"chart_of_accounts": "Standard",
"create_chart_of_accounts_based_on": "Standard Template"
} }
] ]

View File

@@ -21,9 +21,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestInventoryDimension(ERPNextTestSuite): class TestInventoryDimension(ERPNextTestSuite):
def setUp(self):
prepare_test_data()
def test_validate_inventory_dimension(self): def test_validate_inventory_dimension(self):
# Can not be child doc # Can not be child doc
inv_dim1 = create_inventory_dimension( inv_dim1 = create_inventory_dimension(
@@ -76,6 +73,7 @@ class TestInventoryDimension(ERPNextTestSuite):
self.assertFalse(custom_field) self.assertFalse(custom_field)
def test_inventory_dimension(self): def test_inventory_dimension(self):
create_warehouse("Shelf Warehouse")
warehouse = "Shelf Warehouse - _TC" warehouse = "Shelf Warehouse - _TC"
item_code = "_Test Item" item_code = "_Test Item"
@@ -555,28 +553,6 @@ def get_voucher_sl_entries(voucher_no, fields):
) )
def prepare_test_data():
for shelf in ["Shelf 1", "Shelf 2"]:
if not frappe.db.exists("Shelf", shelf):
frappe.get_doc({"doctype": "Shelf", "shelf_name": shelf}).insert(ignore_permissions=True)
create_warehouse("Shelf Warehouse")
for rack in ["Rack 1", "Rack 2"]:
if not frappe.db.exists("Rack", rack):
frappe.get_doc({"doctype": "Rack", "rack_name": rack}).insert(ignore_permissions=True)
create_warehouse("Rack Warehouse")
for site in ["Site 1", "Site 2"]:
if not frappe.db.exists("Inv Site", site):
frappe.get_doc({"doctype": "Inv Site", "site_name": site}).insert(ignore_permissions=True)
for store in ["Store 1", "Store 2"]:
if not frappe.db.exists("Store", store):
frappe.get_doc({"doctype": "Store", "store_name": store}).insert(ignore_permissions=True)
def create_inventory_dimension(**args): def create_inventory_dimension(**args):
args = frappe._dict(args) args = frappe._dict(args)

View File

@@ -2421,12 +2421,11 @@ class TestStockEntry(ERPNextTestSuite):
Unit test case to check the document naming rule with company condition Unit test case to check the document naming rule with company condition
For Quality Inspection, when created from Stock Entry. For Quality Inspection, when created from Stock Entry.
""" """
from erpnext.accounts.report.trial_balance.test_trial_balance import create_company
from erpnext.controllers.stock_controller import make_quality_inspections from erpnext.controllers.stock_controller import make_quality_inspections
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
# create a separate company to handle document naming rule with company condition # create a separate company to handle document naming rule with company condition
qc_company = create_company(company_name="Test Quality Company") qc_company = "Test Quality Company"
# create document naming rule based on that for Quality Inspection Doctype # create document naming rule based on that for Quality Inspection Doctype
qc_naming_rule = frappe.new_doc( qc_naming_rule = frappe.new_doc(

View File

@@ -31,7 +31,8 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False,
for d in item_warehouses: for d in item_warehouses:
try: try:
repost_stock(d[0], d[1], allow_zero_rate, only_actual, only_bin, allow_negative_stock) repost_stock(d[0], d[1], allow_zero_rate, only_actual, only_bin, allow_negative_stock)
frappe.db.commit() if not frappe.in_test:
frappe.db.commit()
except Exception: except Exception:
frappe.db.rollback() frappe.db.rollback()

View File

@@ -13,32 +13,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestServiceLevelAgreement(ERPNextTestSuite): class TestServiceLevelAgreement(ERPNextTestSuite):
def setUp(self):
self.create_company()
frappe.db.set_single_value("Support Settings", "track_service_level_agreement", 1)
lead = frappe.qb.DocType("Lead")
frappe.qb.from_(lead).delete().where(lead.company == self.company).run()
def create_company(self):
name = "_Test Support SLA"
company = None
if frappe.db.exists("Company", name):
company = frappe.get_doc("Company", name)
else:
company = frappe.get_doc(
{
"doctype": "Company",
"company_name": name,
"country": "India",
"default_currency": "INR",
"create_chart_of_accounts_based_on": "Standard Template",
"chart_of_accounts": "Standard",
}
)
company = company.save()
self.company = company.name
def test_service_level_agreement(self): def test_service_level_agreement(self):
# Default Service Level Agreement # Default Service Level Agreement
create_default_service_level_agreement = create_service_level_agreement( create_default_service_level_agreement = create_service_level_agreement(
@@ -219,10 +193,9 @@ class TestServiceLevelAgreement(ERPNextTestSuite):
doctype=doctype, doctype=doctype,
sla_fulfilled_on=[{"status": "Converted"}], sla_fulfilled_on=[{"status": "Converted"}],
) )
# make lead with default SLA # make lead with default SLA
creation = datetime.datetime(2019, 3, 4, 12, 0) creation = datetime.datetime(2019, 3, 4, 12, 0)
lead = make_lead(creation=creation, index=1, company=self.company) lead = make_lead(creation=creation, index=1, company="_Test Support SLA")
self.assertEqual(lead.service_level_agreement, lead_sla.name) self.assertEqual(lead.service_level_agreement, lead_sla.name)
self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0)) self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0))
@@ -250,7 +223,7 @@ class TestServiceLevelAgreement(ERPNextTestSuite):
) )
creation = datetime.datetime(2020, 3, 4, 4, 0) creation = datetime.datetime(2020, 3, 4, 4, 0)
lead = make_lead(creation, index=2, company=self.company) lead = make_lead(creation, index=2, company="_Test Support SLA")
frappe.flags.current_time = datetime.datetime(2020, 3, 4, 4, 15) frappe.flags.current_time = datetime.datetime(2020, 3, 4, 4, 15)
lead.reload() lead.reload()
@@ -284,7 +257,7 @@ class TestServiceLevelAgreement(ERPNextTestSuite):
) )
creation = datetime.datetime(2019, 3, 4, 12, 0) creation = datetime.datetime(2019, 3, 4, 12, 0)
lead = make_lead(creation=creation, index=1, company=self.company) lead = make_lead(creation=creation, index=1, company="_Test Support SLA")
self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0)) self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0))
# failed with response time only # failed with response time only
@@ -311,7 +284,7 @@ class TestServiceLevelAgreement(ERPNextTestSuite):
# fulfilled with response time only # fulfilled with response time only
creation = datetime.datetime(2019, 3, 4, 12, 0) creation = datetime.datetime(2019, 3, 4, 12, 0)
lead = make_lead(creation=creation, index=2, company=self.company) lead = make_lead(creation=creation, index=2, company="_Test Support SLA")
self.assertEqual(lead.service_level_agreement, lead_sla.name) self.assertEqual(lead.service_level_agreement, lead_sla.name)
self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0)) self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0))
@@ -338,7 +311,7 @@ class TestServiceLevelAgreement(ERPNextTestSuite):
apply_sla_for_resolution=0, apply_sla_for_resolution=0,
) )
creation = datetime.datetime(2019, 3, 4, 12, 0) creation = datetime.datetime(2019, 3, 4, 12, 0)
lead = make_lead(creation=creation, index=4, company=self.company) lead = make_lead(creation=creation, index=4, company="_Test Support SLA")
applied_sla = frappe.db.get_value("Lead", lead.name, "service_level_agreement") applied_sla = frappe.db.get_value("Lead", lead.name, "service_level_agreement")
self.assertFalse(applied_sla) self.assertFalse(applied_sla)

View File

@@ -190,7 +190,9 @@ def link_existing_conversations(doc, state):
call_log = frappe.get_doc("Call Log", log) call_log = frappe.get_doc("Call Log", log)
call_log.add_link(link_type=doc.doctype, link_name=doc.name) call_log.add_link(link_type=doc.doctype, link_name=doc.name)
call_log.save(ignore_permissions=True) call_log.save(ignore_permissions=True)
frappe.db.commit()
if not frappe.in_test:
frappe.db.commit()
except Exception: except Exception:
frappe.log_error(title=_("Error during caller information update")) frappe.log_error(title=_("Error during caller information update"))

View File

@@ -20,7 +20,6 @@ class TestWebsite(ERPNextTestSuite):
po1 = create_purchase_order(supplier="Supplier1") po1 = create_purchase_order(supplier="Supplier1")
po2 = create_purchase_order(supplier="Supplier2") po2 = create_purchase_order(supplier="Supplier2")
create_custom_doctype()
create_webform() create_webform()
create_order_assignment(supplier="Supplier1", po=po1.name) create_order_assignment(supplier="Supplier1", po=po1.name)
create_order_assignment(supplier="Supplier2", po=po2.name) create_order_assignment(supplier="Supplier2", po=po2.name)
@@ -60,42 +59,6 @@ def create_user(name, email):
).insert(ignore_if_duplicate=True) ).insert(ignore_if_duplicate=True)
def create_custom_doctype():
frappe.get_doc(
{
"doctype": "DocType",
"name": "Order Assignment",
"module": "Buying",
"custom": 1,
"autoname": "field:po",
"fields": [
{"label": "PO", "fieldname": "po", "fieldtype": "Link", "options": "Purchase Order"},
{
"label": "Supplier",
"fieldname": "supplier",
"fieldtype": "Data",
"fetch_from": "po.supplier",
},
],
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1,
},
{"read": 1, "role": "Supplier"},
],
}
).insert(ignore_if_duplicate=True)
def create_webform(): def create_webform():
frappe.get_doc( frappe.get_doc(
{ {

View File

@@ -8,6 +8,7 @@ from typing import Any, NewType
import frappe import frappe
from frappe import _ from frappe import _
from frappe.core.doctype.report.report import get_report_module_dotted_path from frappe.core.doctype.report.report import get_report_module_dotted_path
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
from frappe.tests.utils import load_test_records_for from frappe.tests.utils import load_test_records_for
from frappe.utils import now_datetime, today from frappe.utils import now_datetime, today
@@ -240,16 +241,29 @@ class BootStrapTestData:
self.make_sales_person() self.make_sales_person()
self.make_activity_type() self.make_activity_type()
self.make_address() self.make_address()
self.update_support_settings()
self.update_selling_settings() self.update_selling_settings()
self.update_stock_settings() self.update_stock_settings()
self.update_system_settings() self.update_system_settings()
frappe.db.commit() # nosemgrep frappe.db.commit() # nosemgrep
# custom doctype
# DDL commands have implicit commit # DDL commands have implicit commit
# Dimensions
self.make_dimensions()
# custom doctype
self.make_custom_doctype() self.make_custom_doctype()
# data on custom doctype
self.make_shelf()
self.make_rack()
self.make_inv_site()
self.make_store()
# custom field
self.make_custom_field()
def update_system_settings(self): def update_system_settings(self):
system_settings = frappe.get_doc("System Settings") system_settings = frappe.get_doc("System Settings")
system_settings.time_zone = "Asia/Kolkata" system_settings.time_zone = "Asia/Kolkata"
@@ -258,6 +272,11 @@ class BootStrapTestData:
system_settings.rounding_method = "Banker's Rounding" system_settings.rounding_method = "Banker's Rounding"
system_settings.save() system_settings.save()
def update_support_settings(self):
support_settings = frappe.get_doc("Support Settings")
support_settings.track_service_level_agreement = True
support_settings.save()
def update_selling_settings(self): def update_selling_settings(self):
selling_settings = frappe.get_doc("Selling Settings") selling_settings = frappe.get_doc("Selling Settings")
selling_settings.selling_price_list = "Standard Selling" selling_settings.selling_price_list = "Standard Selling"
@@ -956,6 +975,7 @@ class BootStrapTestData:
def make_location(self): def make_location(self):
records = [ records = [
{"doctype": "Location", "location_name": "Test Location"}, {"doctype": "Location", "location_name": "Test Location"},
{"doctype": "Location", "location_name": "Test Location 2"},
{"doctype": "Location", "location_name": "Test Location Area", "is_group": 1, "is_container": 1}, {"doctype": "Location", "location_name": "Test Location Area", "is_group": 1, "is_container": 1},
{ {
"doctype": "Location", "doctype": "Location",
@@ -2743,6 +2763,46 @@ class BootStrapTestData:
} }
).insert(ignore_permissions=True) ).insert(ignore_permissions=True)
if not frappe.db.exists("DocType", "Order Assignment"):
frappe.get_doc(
{
"doctype": "DocType",
"name": "Order Assignment",
"module": "Buying",
"custom": 1,
"autoname": "field:po",
"fields": [
{
"label": "PO",
"fieldname": "po",
"fieldtype": "Link",
"options": "Purchase Order",
},
{
"label": "Supplier",
"fieldname": "supplier",
"fieldtype": "Data",
"fetch_from": "po.supplier",
},
],
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1,
},
{"read": 1, "role": "Supplier"},
],
}
).insert(ignore_if_duplicate=True)
def make_address(self): def make_address(self):
records = [ records = [
{ {
@@ -2794,6 +2854,103 @@ class BootStrapTestData:
] ]
self.make_records(["address_title", "address_type"], records) self.make_records(["address_title", "address_type"], records)
def make_dimensions(self):
records = [
{
"doctype": "Accounting Dimension",
"document_type": "Department",
"dimension_defaults": [
{
"company": "_Test Company",
"reference_document": "Department",
"default_dimension": "_Test Department - _TC",
}
],
},
{
"doctype": "Accounting Dimension",
"document_type": "Location",
"dimension_defaults": [
{
"company": "_Test Company",
"reference_document": "Location",
"default_dimension": "Block 1",
}
],
},
{
"doctype": "Accounting Dimension",
"document_type": "Branch",
},
]
self.make_records(["document_type"], records)
def make_custom_field(self):
pan_field = {
"Supplier": [
{
"fieldname": "pan",
"label": "PAN",
"fieldtype": "Data",
"translatable": 0,
}
]
}
create_custom_fields(pan_field, update=1)
def make_shelf(self):
records = [
{
"doctype": "Shelf",
"shelf_name": "Shelf 1",
},
{
"doctype": "Shelf",
"shelf_name": "Shelf 2",
},
]
self.make_records(["shelf_name"], records)
def make_rack(self):
records = [
{
"doctype": "Rack",
"rack_name": "Rack 1",
},
{
"doctype": "Rack",
"rack_name": "Rack 2",
},
]
self.make_records(["rack_name"], records)
def make_inv_site(self):
records = [
{
"doctype": "Inv Site",
"site_name": "Site 1",
},
{
"doctype": "Inv Site",
"site_name": "Site 2",
},
]
self.make_records(["site_name"], records)
def make_store(self):
records = [
{
"doctype": "Store",
"store_name": "Store 1",
},
{
"doctype": "Store",
"store_name": "Store 2",
},
]
self.make_records(["store_name"], records)
BootStrapTestData() BootStrapTestData()