refactor: Use db.set_single_value (#35668)

I just applied semgrep autofix. Untested completed, review before merging.

```yaml
- id: frappe-set-value-semantics
  patterns:
    - pattern-either:
      - pattern: frappe.db.set_value($DOCTYPE, None, $...AFTER)
      - pattern: frappe.db.set_value($DOCTYPE, $DOCTYPE, $...AFTER)
  fix: frappe.db.set_single_value($DOCTYPE, $...AFTER)
  message: |
    If $DOCTYPE is a single doctype then using `frappe.db.set_value` is discouraged for setting values in DB. Use db.set_single_value for single doctype instead.
  languages: [python]
  severity: ERROR
```
This commit is contained in:
Ankush Menat 2023-06-13 17:30:38 +05:30 committed by GitHub
parent b43e068852
commit a3ea985348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 124 additions and 142 deletions

0
.semgrepignore Normal file
View File

View File

@ -12,7 +12,7 @@ from frappe.utils import add_days, add_years, cstr, getdate
class FiscalYear(Document): class FiscalYear(Document):
@frappe.whitelist() @frappe.whitelist()
def set_as_default(self): def set_as_default(self):
frappe.db.set_value("Global Defaults", None, "current_fiscal_year", self.name) frappe.db.set_single_value("Global Defaults", "current_fiscal_year", self.name)
global_defaults = frappe.get_doc("Global Defaults") global_defaults = frappe.get_doc("Global Defaults")
global_defaults.check_permission("write") global_defaults.check_permission("write")
global_defaults.on_update() global_defaults.on_update()

View File

@ -105,8 +105,8 @@ class TestJournalEntry(unittest.TestCase):
elif test_voucher.doctype in ["Sales Order", "Purchase Order"]: elif test_voucher.doctype in ["Sales Order", "Purchase Order"]:
# if test_voucher is a Sales Order/Purchase Order, test error on cancellation of test_voucher # if test_voucher is a Sales Order/Purchase Order, test error on cancellation of test_voucher
frappe.db.set_value( frappe.db.set_single_value(
"Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0 "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0
) )
submitted_voucher = frappe.get_doc(test_voucher.doctype, test_voucher.name) submitted_voucher = frappe.get_doc(test_voucher.doctype, test_voucher.name)
self.assertRaises(frappe.LinkExistsError, submitted_voucher.cancel) self.assertRaises(frappe.LinkExistsError, submitted_voucher.cancel)

View File

@ -31,7 +31,7 @@ class TestPOSInvoice(unittest.TestCase):
frappe.set_user("Administrator") frappe.set_user("Administrator")
if frappe.db.get_single_value("Selling Settings", "validate_selling_price"): if frappe.db.get_single_value("Selling Settings", "validate_selling_price"):
frappe.db.set_value("Selling Settings", None, "validate_selling_price", 0) frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0)
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)
@ -722,7 +722,7 @@ class TestPOSInvoice(unittest.TestCase):
) )
if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"): if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"):
frappe.db.set_value("Selling Settings", "Selling Settings", "validate_selling_price", 1) frappe.db.set_single_value("Selling Settings", "validate_selling_price", 1)
item = "Test Selling Price Validation" item = "Test Selling Price Validation"
make_item(item, {"is_stock_item": 1}) make_item(item, {"is_stock_item": 1})

View File

@ -42,7 +42,7 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
@classmethod @classmethod
def setUpClass(self): def setUpClass(self):
unlink_payment_on_cancel_of_invoice() unlink_payment_on_cancel_of_invoice()
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(self):
@ -1232,9 +1232,7 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice" "Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice"
) )
frappe.db.set_value( frappe.db.set_single_value("Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1)
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1
)
original_account = frappe.db.get_value("Company", "_Test Company", "exchange_gain_loss_account") original_account = frappe.db.get_value("Company", "_Test Company", "exchange_gain_loss_account")
frappe.db.set_value( frappe.db.set_value(
@ -1369,8 +1367,8 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
pay.reload() pay.reload()
pay.cancel() pay.cancel()
frappe.db.set_value( frappe.db.set_single_value(
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", unlink_enabled "Accounts Settings", "unlink_payment_on_cancel_of_invoice", unlink_enabled
) )
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)

View File

@ -1063,7 +1063,7 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEqual(pos.write_off_amount, 10) self.assertEqual(pos.write_off_amount, 10)
def test_pos_with_no_gl_entry_for_change_amount(self): def test_pos_with_no_gl_entry_for_change_amount(self):
frappe.db.set_value("Accounts Settings", None, "post_change_gl_entries", 0) frappe.db.set_single_value("Accounts Settings", "post_change_gl_entries", 0)
make_pos_profile( make_pos_profile(
company="_Test Company with perpetual inventory", company="_Test Company with perpetual inventory",
@ -1113,7 +1113,7 @@ class TestSalesInvoice(unittest.TestCase):
self.validate_pos_gl_entry(pos, pos, 60, validate_without_change_gle=True) self.validate_pos_gl_entry(pos, pos, 60, validate_without_change_gle=True)
frappe.db.set_value("Accounts Settings", None, "post_change_gl_entries", 1) frappe.db.set_single_value("Accounts Settings", "post_change_gl_entries", 1)
def validate_pos_gl_entry(self, si, pos, cash_amount, validate_without_change_gle=False): def validate_pos_gl_entry(self, si, pos, cash_amount, validate_without_change_gle=False):
if validate_without_change_gle: if validate_without_change_gle:
@ -2452,7 +2452,7 @@ class TestSalesInvoice(unittest.TestCase):
"Check mapping (expense account) of inter company SI to PI in absence of default warehouse." "Check mapping (expense account) of inter company SI to PI in absence of default warehouse."
# setup # setup
old_negative_stock = frappe.db.get_single_value("Stock Settings", "allow_negative_stock") old_negative_stock = frappe.db.get_single_value("Stock Settings", "allow_negative_stock")
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
old_perpetual_inventory = erpnext.is_perpetual_inventory_enabled("_Test Company 1") old_perpetual_inventory = erpnext.is_perpetual_inventory_enabled("_Test Company 1")
frappe.local.enable_perpetual_inventory["_Test Company 1"] = 1 frappe.local.enable_perpetual_inventory["_Test Company 1"] = 1
@ -2506,7 +2506,7 @@ class TestSalesInvoice(unittest.TestCase):
# tear down # tear down
frappe.local.enable_perpetual_inventory["_Test Company 1"] = old_perpetual_inventory frappe.local.enable_perpetual_inventory["_Test Company 1"] = old_perpetual_inventory
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", old_negative_stock) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", old_negative_stock)
def test_sle_for_target_warehouse(self): def test_sle_for_target_warehouse(self):
se = make_stock_entry( se = make_stock_entry(
@ -2898,7 +2898,7 @@ class TestSalesInvoice(unittest.TestCase):
party_link = create_party_link("Supplier", supplier, customer) party_link = create_party_link("Supplier", supplier, customer)
# enable common party accounting # enable common party accounting
frappe.db.set_value("Accounts Settings", None, "enable_common_party_accounting", 1) frappe.db.set_single_value("Accounts Settings", "enable_common_party_accounting", 1)
# create a sales invoice # create a sales invoice
si = create_sales_invoice(customer=customer, parent_cost_center="_Test Cost Center - _TC") si = create_sales_invoice(customer=customer, parent_cost_center="_Test Cost Center - _TC")
@ -2925,7 +2925,7 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEqual(jv[0], si.grand_total) self.assertEqual(jv[0], si.grand_total)
party_link.delete() party_link.delete()
frappe.db.set_value("Accounts Settings", None, "enable_common_party_accounting", 0) frappe.db.set_single_value("Accounts Settings", "enable_common_party_accounting", 0)
def test_payment_statuses(self): def test_payment_statuses(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
@ -3045,7 +3045,7 @@ class TestSalesInvoice(unittest.TestCase):
self.assertRaises(frappe.ValidationError, si.save) self.assertRaises(frappe.ValidationError, si.save)
def test_sales_invoice_submission_post_account_freezing_date(self): def test_sales_invoice_submission_post_account_freezing_date(self):
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", add_days(getdate(), 1)) frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", add_days(getdate(), 1))
si = create_sales_invoice(do_not_save=True) si = create_sales_invoice(do_not_save=True)
si.posting_date = add_days(getdate(), 1) si.posting_date = add_days(getdate(), 1)
si.save() si.save()
@ -3054,7 +3054,7 @@ class TestSalesInvoice(unittest.TestCase):
si.posting_date = getdate() si.posting_date = getdate()
si.submit() si.submit()
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", None) frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)
def test_over_billing_case_against_delivery_note(self): def test_over_billing_case_against_delivery_note(self):
""" """
@ -3066,7 +3066,7 @@ class TestSalesInvoice(unittest.TestCase):
over_billing_allowance = frappe.db.get_single_value( over_billing_allowance = frappe.db.get_single_value(
"Accounts Settings", "over_billing_allowance" "Accounts Settings", "over_billing_allowance"
) )
frappe.db.set_value("Accounts Settings", None, "over_billing_allowance", 0) frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", 0)
dn = create_delivery_note() dn = create_delivery_note()
dn.submit() dn.submit()
@ -3082,7 +3082,7 @@ class TestSalesInvoice(unittest.TestCase):
self.assertTrue("cannot overbill" in str(err.exception).lower()) self.assertTrue("cannot overbill" in str(err.exception).lower())
frappe.db.set_value("Accounts Settings", None, "over_billing_allowance", over_billing_allowance) frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", over_billing_allowance)
def test_multi_currency_deferred_revenue_via_journal_entry(self): def test_multi_currency_deferred_revenue_via_journal_entry(self):
deferred_account = create_account( deferred_account = create_account(
@ -3121,7 +3121,7 @@ class TestSalesInvoice(unittest.TestCase):
si.save() si.save()
si.submit() si.submit()
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", getdate("2019-01-31")) frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", getdate("2019-01-31"))
pda1 = frappe.get_doc( pda1 = frappe.get_doc(
dict( dict(
@ -3166,7 +3166,7 @@ class TestSalesInvoice(unittest.TestCase):
acc_settings.submit_journal_entries = 0 acc_settings.submit_journal_entries = 0
acc_settings.save() acc_settings.save()
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", None) frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)
def test_standalone_serial_no_return(self): def test_standalone_serial_no_return(self):
si = create_sales_invoice( si = create_sales_invoice(
@ -3216,9 +3216,7 @@ class TestSalesInvoice(unittest.TestCase):
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice" "Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice"
) )
frappe.db.set_value( frappe.db.set_single_value("Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1)
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1
)
jv = make_journal_entry("_Test Receivable USD - _TC", "_Test Bank - _TC", -7000, save=False) jv = make_journal_entry("_Test Receivable USD - _TC", "_Test Bank - _TC", -7000, save=False)
@ -3261,8 +3259,8 @@ class TestSalesInvoice(unittest.TestCase):
check_gl_entries(self, si.name, expected_gle, nowdate()) check_gl_entries(self, si.name, expected_gle, nowdate())
frappe.db.set_value( frappe.db.set_single_value(
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", unlink_enabled "Accounts Settings", "unlink_payment_on_cancel_of_invoice", unlink_enabled
) )
def test_batch_expiry_for_sales_invoice_return(self): def test_batch_expiry_for_sales_invoice_return(self):

View File

@ -15,7 +15,7 @@ test_records = frappe.get_test_records("Tax Rule")
class TestTaxRule(unittest.TestCase): class TestTaxRule(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
frappe.db.set_value("Shopping Cart Settings", None, "enabled", 0) frappe.db.set_single_value("Shopping Cart Settings", "enabled", 0)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):

View File

@ -1804,7 +1804,7 @@ def set_depreciation_settings_in_company(company=None):
company.save() company.save()
# Enable booking asset depreciation entry automatically # Enable booking asset depreciation entry automatically
frappe.db.set_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically", 1) frappe.db.set_single_value("Accounts Settings", "book_asset_depreciation_entry_automatically", 1)
def enable_cwip_accounting(asset_category, enable=1): def enable_cwip_accounting(asset_category, enable=1):

View File

@ -182,4 +182,4 @@ def set_depreciation_settings_in_company():
company.save() company.save()
# Enable booking asset depreciation entry automatically # Enable booking asset depreciation entry automatically
frappe.db.set_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically", 1) frappe.db.set_single_value("Accounts Settings", "book_asset_depreciation_entry_automatically", 1)

View File

@ -92,7 +92,7 @@ class TestPurchaseOrder(FrappeTestCase):
frappe.db.set_value("Item", "_Test Item", "over_delivery_receipt_allowance", 0) frappe.db.set_value("Item", "_Test Item", "over_delivery_receipt_allowance", 0)
frappe.db.set_value("Item", "_Test Item", "over_billing_allowance", 0) frappe.db.set_value("Item", "_Test Item", "over_billing_allowance", 0)
frappe.db.set_value("Accounts Settings", None, "over_billing_allowance", 0) frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", 0)
def test_update_remove_child_linked_to_mr(self): def test_update_remove_child_linked_to_mr(self):
"""Test impact on linked PO and MR on deleting/updating row.""" """Test impact on linked PO and MR on deleting/updating row."""
@ -581,7 +581,7 @@ class TestPurchaseOrder(FrappeTestCase):
) )
def test_group_same_items(self): def test_group_same_items(self):
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
frappe.get_doc( frappe.get_doc(
{ {
"doctype": "Purchase Order", "doctype": "Purchase Order",
@ -836,8 +836,8 @@ class TestPurchaseOrder(FrappeTestCase):
) )
from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt
frappe.db.set_value("Selling Settings", None, "maintain_same_sales_rate", 1) frappe.db.set_single_value("Selling Settings", "maintain_same_sales_rate", 1)
frappe.db.set_value("Buying Settings", None, "maintain_same_rate", 1) frappe.db.set_single_value("Buying Settings", "maintain_same_rate", 1)
prepare_data_for_internal_transfer() prepare_data_for_internal_transfer()
supplier = "_Test Internal Supplier 2" supplier = "_Test Internal Supplier 2"

View File

@ -156,7 +156,7 @@ class TestSupplier(FrappeTestCase):
def test_serach_fields_for_supplier(self): def test_serach_fields_for_supplier(self):
from erpnext.controllers.queries import supplier_query from erpnext.controllers.queries import supplier_query
frappe.db.set_value("Buying Settings", None, "supp_master_name", "Naming Series") frappe.db.set_single_value("Buying Settings", "supp_master_name", "Naming Series")
supplier_name = create_supplier(supplier_name="Test Supplier 1").name supplier_name = create_supplier(supplier_name="Test Supplier 1").name
@ -189,7 +189,7 @@ class TestSupplier(FrappeTestCase):
self.assertEqual(data[0].supplier_type, "Company") self.assertEqual(data[0].supplier_type, "Company")
self.assertTrue("supplier_type" in data[0]) self.assertTrue("supplier_type" in data[0])
frappe.db.set_value("Buying Settings", None, "supp_master_name", "Supplier Name") frappe.db.set_single_value("Buying Settings", "supp_master_name", "Supplier Name")
def create_supplier(**args): def create_supplier(**args):

View File

@ -1074,8 +1074,8 @@ def make_bom_for_subcontracted_items():
def set_backflush_based_on(based_on): def set_backflush_based_on(based_on):
frappe.db.set_value( frappe.db.set_single_value(
"Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", based_on "Buying Settings", "backflush_raw_materials_of_subcontract_based_on", based_on
) )

View File

@ -53,9 +53,7 @@ class TestOpportunity(unittest.TestCase):
self.assertEqual(opportunity_doc.total, 2200) self.assertEqual(opportunity_doc.total, 2200)
def test_carry_forward_of_email_and_comments(self): def test_carry_forward_of_email_and_comments(self):
frappe.db.set_value( frappe.db.set_single_value("CRM Settings", "carry_forward_communication_and_comments", 1)
"CRM Settings", "CRM Settings", "carry_forward_communication_and_comments", 1
)
lead_doc = make_lead() lead_doc = make_lead()
lead_doc.add_comment("Comment", text="Test Comment 1") lead_doc.add_comment("Comment", text="Test Comment 1")
lead_doc.add_comment("Comment", text="Test Comment 2") lead_doc.add_comment("Comment", text="Test Comment 2")

View File

@ -205,7 +205,7 @@ class TestShoppingCart(unittest.TestCase):
self.assertEqual(quote_doctstatus, 0) self.assertEqual(quote_doctstatus, 0)
frappe.db.set_value("E Commerce Settings", None, "save_quotations_as_draft", 0) frappe.db.set_single_value("E Commerce Settings", "save_quotations_as_draft", 0)
frappe.local.shopping_cart_settings = None frappe.local.shopping_cart_settings = None
update_cart("_Test Item", 1) update_cart("_Test Item", 1)
quote_name = request_for_quotation() # Request for Quote quote_name = request_for_quotation() # Request for Quote

View File

@ -32,7 +32,7 @@ class TestPlaidSettings(unittest.TestCase):
frappe.delete_doc(doctype, d.name, force=True) frappe.delete_doc(doctype, d.name, force=True)
def test_plaid_disabled(self): def test_plaid_disabled(self):
frappe.db.set_value("Plaid Settings", None, "enabled", 0) frappe.db.set_single_value("Plaid Settings", "enabled", 0)
self.assertTrue(get_plaid_configuration() == "disabled") self.assertTrue(get_plaid_configuration() == "disabled")
def test_add_account_type(self): def test_add_account_type(self):

View File

@ -503,10 +503,8 @@ class TestWorkOrder(FrappeTestCase):
stock_entry.cancel() stock_entry.cancel()
def test_capcity_planning(self): def test_capcity_planning(self):
frappe.db.set_value( frappe.db.set_single_value(
"Manufacturing Settings", "Manufacturing Settings", {"disable_capacity_planning": 0, "capacity_planning_for_days": 1}
None,
{"disable_capacity_planning": 0, "capacity_planning_for_days": 1},
) )
data = frappe.get_cached_value( data = frappe.get_cached_value(
@ -529,7 +527,7 @@ class TestWorkOrder(FrappeTestCase):
self.assertRaises(CapacityError, work_order1.submit) self.assertRaises(CapacityError, work_order1.submit)
frappe.db.set_value("Manufacturing Settings", None, {"capacity_planning_for_days": 30}) frappe.db.set_single_value("Manufacturing Settings", {"capacity_planning_for_days": 30})
work_order1.reload() work_order1.reload()
work_order1.submit() work_order1.submit()
@ -539,7 +537,7 @@ class TestWorkOrder(FrappeTestCase):
work_order.cancel() work_order.cancel()
def test_work_order_with_non_transfer_item(self): def test_work_order_with_non_transfer_item(self):
frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM") frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM")
items = {"Finished Good Transfer Item": 1, "_Test FG Item": 1, "_Test FG Item 1": 0} items = {"Finished Good Transfer Item": 1, "_Test FG Item": 1, "_Test FG Item 1": 0}
for item, allow_transfer in items.items(): for item, allow_transfer in items.items():
@ -619,7 +617,7 @@ class TestWorkOrder(FrappeTestCase):
fg_item = "Test Batch Size Item For BOM 3" fg_item = "Test Batch Size Item For BOM 3"
rm1 = "Test Batch Size Item RM 1 For BOM 3" rm1 = "Test Batch Size Item RM 1 For BOM 3"
frappe.db.set_value("Manufacturing Settings", None, "make_serial_no_batch_from_work_order", 0) frappe.db.set_single_value("Manufacturing Settings", "make_serial_no_batch_from_work_order", 0)
for item in ["Test Batch Size Item For BOM 3", "Test Batch Size Item RM 1 For BOM 3"]: for item in ["Test Batch Size Item For BOM 3", "Test Batch Size Item RM 1 For BOM 3"]:
item_args = {"include_item_in_manufacturing": 1, "is_stock_item": 1} item_args = {"include_item_in_manufacturing": 1, "is_stock_item": 1}
@ -655,7 +653,7 @@ class TestWorkOrder(FrappeTestCase):
work_order = make_wo_order_test_record( work_order = make_wo_order_test_record(
item=fg_item, skip_transfer=True, planned_start_date=now(), qty=1 item=fg_item, skip_transfer=True, planned_start_date=now(), qty=1
) )
frappe.db.set_value("Manufacturing Settings", None, "make_serial_no_batch_from_work_order", 1) frappe.db.set_single_value("Manufacturing Settings", "make_serial_no_batch_from_work_order", 1)
ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 1)) ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 1))
for row in ste1.get("items"): for row in ste1.get("items"):
if row.is_finished_item: if row.is_finished_item:
@ -699,10 +697,10 @@ class TestWorkOrder(FrappeTestCase):
self.assertEqual(sorted(remaining_batches), sorted(batches)) self.assertEqual(sorted(remaining_batches), sorted(batches))
frappe.db.set_value("Manufacturing Settings", None, "make_serial_no_batch_from_work_order", 0) frappe.db.set_single_value("Manufacturing Settings", "make_serial_no_batch_from_work_order", 0)
def test_partial_material_consumption(self): def test_partial_material_consumption(self):
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", 1) frappe.db.set_single_value("Manufacturing Settings", "material_consumption", 1)
wo_order = make_wo_order_test_record(planned_start_date=now(), qty=4) wo_order = make_wo_order_test_record(planned_start_date=now(), qty=4)
ste_cancel_list = [] ste_cancel_list = []
@ -736,13 +734,12 @@ class TestWorkOrder(FrappeTestCase):
for ste_doc in ste_cancel_list: for ste_doc in ste_cancel_list:
ste_doc.cancel() ste_doc.cancel()
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", 0) frappe.db.set_single_value("Manufacturing Settings", "material_consumption", 0)
def test_extra_material_transfer(self): def test_extra_material_transfer(self):
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", 0) frappe.db.set_single_value("Manufacturing Settings", "material_consumption", 0)
frappe.db.set_value( frappe.db.set_single_value(
"Manufacturing Settings", "Manufacturing Settings",
None,
"backflush_raw_materials_based_on", "backflush_raw_materials_based_on",
"Material Transferred for Manufacture", "Material Transferred for Manufacture",
) )
@ -787,7 +784,7 @@ class TestWorkOrder(FrappeTestCase):
for ste_doc in ste_cancel_list: for ste_doc in ste_cancel_list:
ste_doc.cancel() ste_doc.cancel()
frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM") frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM")
def test_make_stock_entry_for_customer_provided_item(self): def test_make_stock_entry_for_customer_provided_item(self):
finished_item = "Test Item for Make Stock Entry 1" finished_item = "Test Item for Make Stock Entry 1"
@ -1087,9 +1084,8 @@ class TestWorkOrder(FrappeTestCase):
def test_partial_manufacture_entries(self): def test_partial_manufacture_entries(self):
cancel_stock_entry = [] cancel_stock_entry = []
frappe.db.set_value( frappe.db.set_single_value(
"Manufacturing Settings", "Manufacturing Settings",
None,
"backflush_raw_materials_based_on", "backflush_raw_materials_based_on",
"Material Transferred for Manufacture", "Material Transferred for Manufacture",
) )
@ -1139,7 +1135,7 @@ class TestWorkOrder(FrappeTestCase):
doc = frappe.get_doc("Stock Entry", ste) doc = frappe.get_doc("Stock Entry", ste)
doc.cancel() doc.cancel()
frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM") frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM")
@change_settings("Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1}) @change_settings("Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1})
def test_auto_batch_creation(self): def test_auto_batch_creation(self):
@ -1283,9 +1279,8 @@ class TestWorkOrder(FrappeTestCase):
self.assertEqual(work_order.required_items[1].transferred_qty, 2) self.assertEqual(work_order.required_items[1].transferred_qty, 2)
def test_backflushed_batch_raw_materials_based_on_transferred(self): def test_backflushed_batch_raw_materials_based_on_transferred(self):
frappe.db.set_value( frappe.db.set_single_value(
"Manufacturing Settings", "Manufacturing Settings",
None,
"backflush_raw_materials_based_on", "backflush_raw_materials_based_on",
"Material Transferred for Manufacture", "Material Transferred for Manufacture",
) )
@ -1356,9 +1351,8 @@ class TestWorkOrder(FrappeTestCase):
self.assertEqual(abs(d.qty), 2) self.assertEqual(abs(d.qty), 2)
def test_backflushed_serial_no_raw_materials_based_on_transferred(self): def test_backflushed_serial_no_raw_materials_based_on_transferred(self):
frappe.db.set_value( frappe.db.set_single_value(
"Manufacturing Settings", "Manufacturing Settings",
None,
"backflush_raw_materials_based_on", "backflush_raw_materials_based_on",
"Material Transferred for Manufacture", "Material Transferred for Manufacture",
) )
@ -1400,9 +1394,8 @@ class TestWorkOrder(FrappeTestCase):
self.assertEqual(manufacture_ste_doc2.items[0].qty, 2) self.assertEqual(manufacture_ste_doc2.items[0].qty, 2)
def test_backflushed_serial_no_batch_raw_materials_based_on_transferred(self): def test_backflushed_serial_no_batch_raw_materials_based_on_transferred(self):
frappe.db.set_value( frappe.db.set_single_value(
"Manufacturing Settings", "Manufacturing Settings",
None,
"backflush_raw_materials_based_on", "backflush_raw_materials_based_on",
"Material Transferred for Manufacture", "Material Transferred for Manufacture",
) )
@ -1486,9 +1479,8 @@ class TestWorkOrder(FrappeTestCase):
self.assertFalse(serial_nos) self.assertFalse(serial_nos)
def test_non_consumed_material_return_against_work_order(self): def test_non_consumed_material_return_against_work_order(self):
frappe.db.set_value( frappe.db.set_single_value(
"Manufacturing Settings", "Manufacturing Settings",
None,
"backflush_raw_materials_based_on", "backflush_raw_materials_based_on",
"Material Transferred for Manufacture", "Material Transferred for Manufacture",
) )

View File

@ -7,8 +7,8 @@ import frappe
def execute(): def execute():
frappe.reload_doc("buying", "doctype", "buying_settings") frappe.reload_doc("buying", "doctype", "buying_settings")
frappe.db.set_value( frappe.db.set_single_value(
"Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM" "Buying Settings", "backflush_raw_materials_of_subcontract_based_on", "BOM"
) )
frappe.reload_doc("stock", "doctype", "stock_entry_detail") frappe.reload_doc("stock", "doctype", "stock_entry_detail")

View File

@ -11,6 +11,6 @@ def execute():
rename_field("Item", "tolerance", "over_delivery_receipt_allowance") rename_field("Item", "tolerance", "over_delivery_receipt_allowance")
qty_allowance = frappe.db.get_single_value("Stock Settings", "over_delivery_receipt_allowance") qty_allowance = frappe.db.get_single_value("Stock Settings", "over_delivery_receipt_allowance")
frappe.db.set_value("Accounts Settings", None, "over_delivery_receipt_allowance", qty_allowance) frappe.db.set_single_value("Accounts Settings", "over_delivery_receipt_allowance", qty_allowance)
frappe.db.sql("update tabItem set over_billing_allowance=over_delivery_receipt_allowance") frappe.db.sql("update tabItem set over_billing_allowance=over_delivery_receipt_allowance")

View File

@ -4,6 +4,6 @@ import frappe
def execute(): def execute():
frappe.reload_doc("accounts", "doctype", "accounts_settings") frappe.reload_doc("accounts", "doctype", "accounts_settings")
frappe.db.set_value( frappe.db.set_single_value(
"Accounts Settings", None, "automatically_process_deferred_accounting_entry", 1 "Accounts Settings", "automatically_process_deferred_accounting_entry", 1
) )

View File

@ -2,4 +2,4 @@ import frappe
def execute(): def execute():
frappe.db.set_value("Homepage", "Homepage", "hero_section_based_on", "Default") frappe.db.set_single_value("Homepage", "hero_section_based_on", "Default")

View File

@ -46,7 +46,7 @@ def set_priorities_service_level():
frappe.reload_doc("support", "doctype", "service_level") frappe.reload_doc("support", "doctype", "service_level")
frappe.reload_doc("support", "doctype", "support_settings") frappe.reload_doc("support", "doctype", "support_settings")
frappe.db.set_value("Support Settings", None, "track_service_level_agreement", 1) frappe.db.set_single_value("Support Settings", "track_service_level_agreement", 1)
for service_level in service_level_priorities: for service_level in service_level_priorities:
if service_level: if service_level:

View File

@ -47,7 +47,7 @@ def execute():
acc_frozen_upto = frappe.db.get_value("Accounts Settings", None, "acc_frozen_upto") acc_frozen_upto = frappe.db.get_value("Accounts Settings", None, "acc_frozen_upto")
if acc_frozen_upto: if acc_frozen_upto:
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", None) frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)
for invoice in purchase_invoices + sales_invoices: for invoice in purchase_invoices + sales_invoices:
try: try:
@ -65,4 +65,4 @@ def execute():
print(f"Failed to correct gl entries of {invoice.name}") print(f"Failed to correct gl entries of {invoice.name}")
if acc_frozen_upto: if acc_frozen_upto:
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", acc_frozen_upto) frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", acc_frozen_upto)

View File

@ -8,4 +8,4 @@ def execute():
discount_account = data and int(data[0][0]) or 0 discount_account = data and int(data[0][0]) or 0
if discount_account: if discount_account:
for doctype in ["Buying Settings", "Selling Settings"]: for doctype in ["Buying Settings", "Selling Settings"]:
frappe.db.set_value(doctype, doctype, "enable_discount_accounting", 1, update_modified=False) frappe.db.set_single_value(doctype, "enable_discount_accounting", 1, update_modified=False)

View File

@ -11,8 +11,7 @@ def execute():
frappe.reload_doc("crm", "doctype", "crm_settings") frappe.reload_doc("crm", "doctype", "crm_settings")
if settings: if settings:
frappe.db.set_value( frappe.db.set_single_value(
"CRM Settings",
"CRM Settings", "CRM Settings",
{ {
"campaign_naming_by": settings.campaign_naming_by, "campaign_naming_by": settings.campaign_naming_by,

View File

@ -345,7 +345,7 @@ class TestCustomer(FrappeTestCase):
def test_serach_fields_for_customer(self): def test_serach_fields_for_customer(self):
from erpnext.controllers.queries import customer_query from erpnext.controllers.queries import customer_query
frappe.db.set_value("Selling Settings", None, "cust_master_name", "Naming Series") frappe.db.set_single_value("Selling Settings", "cust_master_name", "Naming Series")
make_property_setter( make_property_setter(
"Customer", None, "search_fields", "customer_group", "Data", for_doctype="Doctype" "Customer", None, "search_fields", "customer_group", "Data", for_doctype="Doctype"
@ -371,7 +371,7 @@ class TestCustomer(FrappeTestCase):
self.assertEqual(data[0].territory, "_Test Territory") self.assertEqual(data[0].territory, "_Test Territory")
self.assertTrue("territory" in data[0]) self.assertTrue("territory" in data[0])
frappe.db.set_value("Selling Settings", None, "cust_master_name", "Customer Name") frappe.db.set_single_value("Selling Settings", "cust_master_name", "Customer Name")
def get_customer_dict(customer_name): def get_customer_dict(customer_name):

View File

@ -43,11 +43,8 @@ class TestSalesOrder(FrappeTestCase):
@classmethod @classmethod
def tearDownClass(cls) -> None: def tearDownClass(cls) -> None:
# reset config to previous state # reset config to previous state
frappe.db.set_value( frappe.db.set_single_value(
"Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", cls.unlink_setting
"Accounts Settings",
"unlink_advance_payment_on_cancelation_of_order",
cls.unlink_setting,
) )
super().tearDownClass() super().tearDownClass()
@ -705,7 +702,7 @@ class TestSalesOrder(FrappeTestCase):
self.assertEqual(so.taxes[0].total, 110) self.assertEqual(so.taxes[0].total, 110)
old_stock_settings_value = frappe.db.get_single_value("Stock Settings", "default_warehouse") old_stock_settings_value = frappe.db.get_single_value("Stock Settings", "default_warehouse")
frappe.db.set_value("Stock Settings", None, "default_warehouse", "_Test Warehouse - _TC") frappe.db.set_single_value("Stock Settings", "default_warehouse", "_Test Warehouse - _TC")
items = json.dumps( items = json.dumps(
[ [
@ -741,7 +738,7 @@ class TestSalesOrder(FrappeTestCase):
so.delete() so.delete()
new_item_with_tax.delete() new_item_with_tax.delete()
frappe.get_doc("Item Tax Template", "Test Update Items Template - _TC").delete() frappe.get_doc("Item Tax Template", "Test Update Items Template - _TC").delete()
frappe.db.set_value("Stock Settings", None, "default_warehouse", old_stock_settings_value) frappe.db.set_single_value("Stock Settings", "default_warehouse", old_stock_settings_value)
def test_warehouse_user(self): def test_warehouse_user(self):
test_user = create_user("test_so_warehouse_user@example.com", "Sales User", "Stock User") test_user = create_user("test_so_warehouse_user@example.com", "Sales User", "Stock User")
@ -820,7 +817,7 @@ class TestSalesOrder(FrappeTestCase):
def test_auto_insert_price(self): def test_auto_insert_price(self):
make_item("_Test Item for Auto Price List", {"is_stock_item": 0}) make_item("_Test Item for Auto Price List", {"is_stock_item": 0})
make_item("_Test Item for Auto Price List with Discount Percentage", {"is_stock_item": 0}) make_item("_Test Item for Auto Price List with Discount Percentage", {"is_stock_item": 0})
frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 1) frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 1)
item_price = frappe.db.get_value( item_price = frappe.db.get_value(
"Item Price", {"price_list": "_Test Price List", "item_code": "_Test Item for Auto Price List"} "Item Price", {"price_list": "_Test Price List", "item_code": "_Test Item for Auto Price List"}
@ -861,7 +858,7 @@ class TestSalesOrder(FrappeTestCase):
) )
# do not update price list # do not update price list
frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 0) frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 0)
item_price = frappe.db.get_value( item_price = frappe.db.get_value(
"Item Price", {"price_list": "_Test Price List", "item_code": "_Test Item for Auto Price List"} "Item Price", {"price_list": "_Test Price List", "item_code": "_Test Item for Auto Price List"}
@ -882,7 +879,7 @@ class TestSalesOrder(FrappeTestCase):
None, None,
) )
frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 1) frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 1)
def test_drop_shipping(self): def test_drop_shipping(self):
from erpnext.buying.doctype.purchase_order.purchase_order import update_status from erpnext.buying.doctype.purchase_order.purchase_order import update_status
@ -1257,8 +1254,8 @@ class TestSalesOrder(FrappeTestCase):
def test_advance_payment_entry_unlink_against_sales_order(self): def test_advance_payment_entry_unlink_against_sales_order(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
frappe.db.set_value( frappe.db.set_single_value(
"Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0 "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0
) )
so = make_sales_order() so = make_sales_order()
@ -1312,8 +1309,8 @@ class TestSalesOrder(FrappeTestCase):
so = make_sales_order() so = make_sales_order()
# disable unlinking of payment entry # disable unlinking of payment entry
frappe.db.set_value( frappe.db.set_single_value(
"Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0 "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0
) )
# create a payment entry against sales order # create a payment entry against sales order
@ -2080,7 +2077,7 @@ def make_sales_order(**args):
def create_dn_against_so(so, delivered_qty=0): def create_dn_against_so(so, delivered_qty=0):
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
dn = make_delivery_note(so) dn = make_delivery_note(so)
dn.get("items")[0].qty = delivered_qty or 5 dn.get("items")[0].qty = delivered_qty or 5

View File

@ -87,13 +87,13 @@ class TestCurrencyExchange(unittest.TestCase):
cache.delete(key) cache.delete(key)
def tearDown(self): def tearDown(self):
frappe.db.set_value("Accounts Settings", None, "allow_stale", 1) frappe.db.set_single_value("Accounts Settings", "allow_stale", 1)
self.clear_cache() self.clear_cache()
def test_exchange_rate(self, mock_get): def test_exchange_rate(self, mock_get):
save_new_records(test_records) save_new_records(test_records)
frappe.db.set_value("Accounts Settings", None, "allow_stale", 1) frappe.db.set_single_value("Accounts Settings", "allow_stale", 1)
# Start with allow_stale is True # Start with allow_stale is True
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying")
@ -124,7 +124,7 @@ class TestCurrencyExchange(unittest.TestCase):
settings.save() settings.save()
# Update exchange # Update exchange
frappe.db.set_value("Accounts Settings", None, "allow_stale", 1) frappe.db.set_single_value("Accounts Settings", "allow_stale", 1)
# Start with allow_stale is True # Start with allow_stale is True
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying")
@ -152,8 +152,8 @@ class TestCurrencyExchange(unittest.TestCase):
def test_exchange_rate_strict(self, mock_get): def test_exchange_rate_strict(self, mock_get):
# strict currency settings # strict currency settings
frappe.db.set_value("Accounts Settings", None, "allow_stale", 0) frappe.db.set_single_value("Accounts Settings", "allow_stale", 0)
frappe.db.set_value("Accounts Settings", None, "stale_days", 1) frappe.db.set_single_value("Accounts Settings", "stale_days", 1)
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying")
self.assertEqual(exchange_rate, 60.0) self.assertEqual(exchange_rate, 60.0)
@ -175,8 +175,8 @@ class TestCurrencyExchange(unittest.TestCase):
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15", "for_buying") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15", "for_buying")
self.assertEqual(exchange_rate, 65.1) self.assertEqual(exchange_rate, 65.1)
frappe.db.set_value("Accounts Settings", None, "allow_stale", 0) frappe.db.set_single_value("Accounts Settings", "allow_stale", 0)
frappe.db.set_value("Accounts Settings", None, "stale_days", 1) frappe.db.set_single_value("Accounts Settings", "stale_days", 1)
self.clear_cache() self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30", "for_buying") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30", "for_buying")

View File

@ -211,7 +211,7 @@ def add_standard_navbar_items():
def add_app_name(): def add_app_name():
frappe.db.set_value("System Settings", None, "app_name", "ERPNext") frappe.db.set_single_value("System Settings", "app_name", "ERPNext")
def setup_log_settings(): def setup_log_settings():

View File

@ -43,7 +43,7 @@ from erpnext.stock.stock_ledger import get_previous_sle
class TestDeliveryNote(FrappeTestCase): class TestDeliveryNote(FrappeTestCase):
def test_over_billing_against_dn(self): def test_over_billing_against_dn(self):
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
dn = create_delivery_note(do_not_submit=True) dn = create_delivery_note(do_not_submit=True)
self.assertRaises(frappe.ValidationError, make_sales_invoice, dn.name) self.assertRaises(frappe.ValidationError, make_sales_invoice, dn.name)
@ -709,7 +709,7 @@ class TestDeliveryNote(FrappeTestCase):
# Testing if Customer's Purchase Order No was rightly copied # Testing if Customer's Purchase Order No was rightly copied
self.assertEqual(so.po_no, si.po_no) self.assertEqual(so.po_no, si.po_no)
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
dn1 = make_delivery_note(so.name) dn1 = make_delivery_note(so.name)
dn1.get("items")[0].qty = 2 dn1.get("items")[0].qty = 2
@ -741,7 +741,7 @@ class TestDeliveryNote(FrappeTestCase):
make_sales_invoice as make_sales_invoice_from_so, make_sales_invoice as make_sales_invoice_from_so,
) )
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
so = make_sales_order() so = make_sales_order()

View File

@ -585,7 +585,7 @@ class Item(Document):
existing_allow_negative_stock = frappe.db.get_value( existing_allow_negative_stock = frappe.db.get_value(
"Stock Settings", None, "allow_negative_stock" "Stock Settings", None, "allow_negative_stock"
) )
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
repost_stock_for_warehouses = frappe.get_all( repost_stock_for_warehouses = frappe.get_all(
"Stock Ledger Entry", "Stock Ledger Entry",
@ -601,8 +601,8 @@ class Item(Document):
for warehouse in repost_stock_for_warehouses: for warehouse in repost_stock_for_warehouses:
repost_stock(new_name, warehouse) repost_stock(new_name, warehouse)
frappe.db.set_value( frappe.db.set_single_value(
"Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock "Stock Settings", "allow_negative_stock", existing_allow_negative_stock
) )
def update_bom_item_desc(self): def update_bom_item_desc(self):

View File

@ -25,7 +25,7 @@ from erpnext.stock.serial_batch_bundle import SerialNoValuation
class TestLandedCostVoucher(FrappeTestCase): class TestLandedCostVoucher(FrappeTestCase):
def test_landed_cost_voucher(self): def test_landed_cost_voucher(self):
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
pr = make_purchase_receipt( pr = make_purchase_receipt(
company="_Test Company with perpetual inventory", company="_Test Company with perpetual inventory",

View File

@ -400,7 +400,7 @@ class TestMaterialRequest(FrappeTestCase):
mr.insert() mr.insert()
mr.submit() mr.submit()
frappe.db.set_value("Stock Settings", None, "mr_qty_allowance", 20) frappe.db.set_single_value("Stock Settings", "mr_qty_allowance", 20)
# map a stock entry # map a stock entry

View File

@ -27,7 +27,7 @@ from erpnext.stock.stock_ledger import SerialNoExistsInFutureTransaction
class TestPurchaseReceipt(FrappeTestCase): class TestPurchaseReceipt(FrappeTestCase):
def setUp(self): def setUp(self):
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
def test_purchase_receipt_received_qty(self): def test_purchase_receipt_received_qty(self):
""" """
@ -1925,7 +1925,7 @@ def make_purchase_receipt(**args):
if not frappe.db.exists("Location", "Test Location"): if not frappe.db.exists("Location", "Test Location"):
frappe.get_doc({"doctype": "Location", "location_name": "Test Location"}).insert() frappe.get_doc({"doctype": "Location", "location_name": "Test Location"}).insert()
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
pr = frappe.new_doc("Purchase Receipt") pr = frappe.new_doc("Purchase Receipt")
args = frappe._dict(args) args = frappe._dict(args)
pr.posting_date = args.posting_date or today() pr.posting_date = args.posting_date or today()

View File

@ -167,13 +167,13 @@ class TestQualityInspection(FrappeTestCase):
reference_type="Stock Entry", reference_name=se.name, readings=readings, status="Rejected" reference_type="Stock Entry", reference_name=se.name, readings=readings, status="Rejected"
) )
frappe.db.set_value("Stock Settings", None, "action_if_quality_inspection_is_rejected", "Stop") frappe.db.set_single_value("Stock Settings", "action_if_quality_inspection_is_rejected", "Stop")
se.reload() se.reload()
self.assertRaises( self.assertRaises(
QualityInspectionRejectedError, se.submit QualityInspectionRejectedError, se.submit
) # when blocked in Stock settings, block rejected QI ) # when blocked in Stock settings, block rejected QI
frappe.db.set_value("Stock Settings", None, "action_if_quality_inspection_is_rejected", "Warn") frappe.db.set_single_value("Stock Settings", "action_if_quality_inspection_is_rejected", "Warn")
se.reload() se.reload()
se.submit() # when allowed in Stock settings, allow rejected QI se.submit() # when allowed in Stock settings, allow rejected QI
@ -182,7 +182,7 @@ class TestQualityInspection(FrappeTestCase):
qa.cancel() qa.cancel()
se.reload() se.reload()
se.cancel() se.cancel()
frappe.db.set_value("Stock Settings", None, "action_if_quality_inspection_is_rejected", "Stop") frappe.db.set_single_value("Stock Settings", "action_if_quality_inspection_is_rejected", "Stop")
def test_qi_status(self): def test_qi_status(self):
make_stock_entry( make_stock_entry(

View File

@ -55,7 +55,7 @@ class TestStockEntry(FrappeTestCase):
frappe.set_user("Administrator") frappe.set_user("Administrator")
def test_fifo(self): def test_fifo(self):
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
item_code = "_Test Item 2" item_code = "_Test Item 2"
warehouse = "_Test Warehouse - _TC" warehouse = "_Test Warehouse - _TC"
@ -142,7 +142,7 @@ class TestStockEntry(FrappeTestCase):
or 0 or 0
) )
frappe.db.set_value("Stock Settings", None, "auto_indent", 1) frappe.db.set_single_value("Stock Settings", "auto_indent", 1)
# update re-level qty so that it is more than projected_qty # update re-level qty so that it is more than projected_qty
if projected_qty >= variant.reorder_levels[0].warehouse_reorder_level: if projected_qty >= variant.reorder_levels[0].warehouse_reorder_level:
@ -154,7 +154,7 @@ class TestStockEntry(FrappeTestCase):
mr_list = reorder_item() mr_list = reorder_item()
frappe.db.set_value("Stock Settings", None, "auto_indent", 0) frappe.db.set_single_value("Stock Settings", "auto_indent", 0)
items = [] items = []
for mr in mr_list: for mr in mr_list:
@ -792,24 +792,24 @@ class TestStockEntry(FrappeTestCase):
remove_user_permission("Company", "_Test Company 1", "test2@example.com") remove_user_permission("Company", "_Test Company 1", "test2@example.com")
def test_freeze_stocks(self): def test_freeze_stocks(self):
frappe.db.set_value("Stock Settings", None, "stock_auth_role", "") frappe.db.set_single_value("Stock Settings", "stock_auth_role", "")
# test freeze_stocks_upto # test freeze_stocks_upto
frappe.db.set_value("Stock Settings", None, "stock_frozen_upto", add_days(nowdate(), 5)) frappe.db.set_single_value("Stock Settings", "stock_frozen_upto", add_days(nowdate(), 5))
se = frappe.copy_doc(test_records[0]).insert() se = frappe.copy_doc(test_records[0]).insert()
self.assertRaises(StockFreezeError, se.submit) self.assertRaises(StockFreezeError, se.submit)
frappe.db.set_value("Stock Settings", None, "stock_frozen_upto", "") frappe.db.set_single_value("Stock Settings", "stock_frozen_upto", "")
# test freeze_stocks_upto_days # test freeze_stocks_upto_days
frappe.db.set_value("Stock Settings", None, "stock_frozen_upto_days", -1) frappe.db.set_single_value("Stock Settings", "stock_frozen_upto_days", -1)
se = frappe.copy_doc(test_records[0]) se = frappe.copy_doc(test_records[0])
se.set_posting_time = 1 se.set_posting_time = 1
se.posting_date = nowdate() se.posting_date = nowdate()
se.set_stock_entry_type() se.set_stock_entry_type()
se.insert() se.insert()
self.assertRaises(StockFreezeError, se.submit) self.assertRaises(StockFreezeError, se.submit)
frappe.db.set_value("Stock Settings", None, "stock_frozen_upto_days", 0) frappe.db.set_single_value("Stock Settings", "stock_frozen_upto_days", 0)
def test_work_order(self): def test_work_order(self):
from erpnext.manufacturing.doctype.work_order.work_order import ( from erpnext.manufacturing.doctype.work_order.work_order import (
@ -1211,7 +1211,7 @@ class TestStockEntry(FrappeTestCase):
) )
def test_conversion_factor_change(self): def test_conversion_factor_change(self):
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
repack_entry = frappe.copy_doc(test_records[3]) repack_entry = frappe.copy_doc(test_records[3])
repack_entry.posting_date = nowdate() repack_entry.posting_date = nowdate()
repack_entry.posting_time = nowtime() repack_entry.posting_time = nowtime()

View File

@ -416,8 +416,8 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin):
def test_back_dated_entry_not_allowed(self): def test_back_dated_entry_not_allowed(self):
# Back dated stock transactions are only allowed to stock managers # Back dated stock transactions are only allowed to stock managers
frappe.db.set_value( frappe.db.set_single_value(
"Stock Settings", None, "role_allowed_to_create_edit_back_dated_transactions", "Stock Manager" "Stock Settings", "role_allowed_to_create_edit_back_dated_transactions", "Stock Manager"
) )
# Set User with Stock User role but not Stock Manager # Set User with Stock User role but not Stock Manager
@ -453,8 +453,8 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin):
stock_entry_on_today.cancel() stock_entry_on_today.cancel()
finally: finally:
frappe.db.set_value( frappe.db.set_single_value(
"Stock Settings", None, "role_allowed_to_create_edit_back_dated_transactions", None "Stock Settings", "role_allowed_to_create_edit_back_dated_transactions", None
) )
frappe.set_user("Administrator") frappe.set_user("Administrator")
user.remove_roles("Stock Manager") user.remove_roles("Stock Manager")

View File

@ -33,7 +33,7 @@ class TestStockReconciliation(FrappeTestCase, StockTestMixin):
def setUpClass(cls): def setUpClass(cls):
create_batch_or_serial_no_items() create_batch_or_serial_no_items()
super().setUpClass() super().setUpClass()
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
def tearDown(self): def tearDown(self):
frappe.local.future_sle = {} frappe.local.future_sle = {}

View File

@ -10,7 +10,7 @@ from frappe.tests.utils import FrappeTestCase
class TestStockSettings(FrappeTestCase): class TestStockSettings(FrappeTestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
frappe.db.set_value("Stock Settings", None, "clean_description_html", 0) frappe.db.set_single_value("Stock Settings", "clean_description_html", 0)
def test_settings(self): def test_settings(self):
item = frappe.get_doc( item = frappe.get_doc(

View File

@ -18,7 +18,7 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False,
existing_allow_negative_stock = frappe.db.get_value( existing_allow_negative_stock = frappe.db.get_value(
"Stock Settings", None, "allow_negative_stock" "Stock Settings", None, "allow_negative_stock"
) )
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
item_warehouses = frappe.db.sql( item_warehouses = frappe.db.sql(
""" """
@ -37,8 +37,8 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False,
frappe.db.rollback() frappe.db.rollback()
if allow_negative_stock: if allow_negative_stock:
frappe.db.set_value( frappe.db.set_single_value(
"Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock "Stock Settings", "allow_negative_stock", existing_allow_negative_stock
) )
frappe.db.auto_commit_on_many_writes = 0 frappe.db.auto_commit_on_many_writes = 0

View File

@ -20,7 +20,7 @@ class TestSetUp(unittest.TestCase):
frappe.db.sql("delete from `tabSLA Fulfilled On Status`") frappe.db.sql("delete from `tabSLA Fulfilled On Status`")
frappe.db.sql("delete from `tabPause SLA On Status`") frappe.db.sql("delete from `tabPause SLA On Status`")
frappe.db.sql("delete from `tabService Day`") frappe.db.sql("delete from `tabService Day`")
frappe.db.set_value("Support Settings", None, "track_service_level_agreement", 1) frappe.db.set_single_value("Support Settings", "track_service_level_agreement", 1)
create_service_level_agreements_for_issues() create_service_level_agreements_for_issues()

View File

@ -16,7 +16,7 @@ from erpnext.support.doctype.service_level_agreement.service_level_agreement imp
class TestServiceLevelAgreement(unittest.TestCase): class TestServiceLevelAgreement(unittest.TestCase):
def setUp(self): def setUp(self):
self.create_company() self.create_company()
frappe.db.set_value("Support Settings", None, "track_service_level_agreement", 1) frappe.db.set_single_value("Support Settings", "track_service_level_agreement", 1)
lead = frappe.qb.DocType("Lead") lead = frappe.qb.DocType("Lead")
frappe.qb.from_(lead).delete().where(lead.company == self.company).run() frappe.qb.from_(lead).delete().where(lead.company == self.company).run()

View File

@ -17,7 +17,7 @@ class TestIssueAnalytics(unittest.TestCase):
@classmethod @classmethod
def setUpClass(self): def setUpClass(self):
frappe.db.sql("delete from `tabIssue` where company='_Test Company'") frappe.db.sql("delete from `tabIssue` where company='_Test Company'")
frappe.db.set_value("Support Settings", None, "track_service_level_agreement", 1) frappe.db.set_single_value("Support Settings", "track_service_level_agreement", 1)
current_month_date = getdate() current_month_date = getdate()
last_month_date = add_months(current_month_date, -1) last_month_date = add_months(current_month_date, -1)

View File

@ -12,7 +12,7 @@ class TestExotel(FrappeAPITestCase):
cls.test_employee_name = make_employee( cls.test_employee_name = make_employee(
user="test_employee_exotel@company.com", cell_number="9999999999" user="test_employee_exotel@company.com", cell_number="9999999999"
) )
frappe.db.set_value("Exotel Settings", "Exotel Settings", "enabled", 1) frappe.db.set_single_value("Exotel Settings", "enabled", 1)
phones = [{"phone": "+91 9999999991", "is_primary_phone": 0, "is_primary_mobile_no": 1}] phones = [{"phone": "+91 9999999991", "is_primary_phone": 0, "is_primary_mobile_no": 1}]
create_contact(name="Test Contact", salutation="Mr", phones=phones) create_contact(name="Test Contact", salutation="Mr", phones=phones)
frappe.db.commit() frappe.db.commit()