From bb18ae82cfd235ca0dc6b85059df77cf7d002f48 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 9 Jan 2024 21:56:47 +0530 Subject: [PATCH] refactor: use db.get_single_value --- erpnext/accounts/doctype/account/account.py | 4 ++-- erpnext/accounts/doctype/gl_entry/gl_entry.py | 4 ++-- .../accounts/doctype/purchase_invoice/purchase_invoice.py | 4 ++-- .../doctype/purchase_invoice/test_purchase_invoice.py | 4 ++-- erpnext/accounts/general_ledger.py | 6 +++--- .../report/accounts_receivable/accounts_receivable.py | 4 ++-- .../accounts_receivable_summary.py | 4 ++-- .../customer_ledger_summary/customer_ledger_summary.py | 4 ++-- erpnext/assets/doctype/asset/depreciation.py | 2 +- .../doctype/request_for_quotation/request_for_quotation.py | 6 +++--- .../doctype/tally_migration/tally_migration.py | 4 +--- erpnext/manufacturing/doctype/workstation/workstation.py | 2 +- .../patches/v13_0/modify_invalid_gain_loss_gl_entries.py | 2 +- erpnext/patches/v14_0/migrate_crm_settings.py | 3 +-- erpnext/selling/doctype/sales_order/test_sales_order.py | 4 ++-- .../customer_credit_balance/customer_credit_balance.py | 2 +- erpnext/startup/boot.py | 2 +- erpnext/stock/doctype/item/item.py | 4 ++-- erpnext/stock/doctype/price_list/price_list.py | 4 ++-- erpnext/stock/doctype/purchase_receipt/purchase_receipt.py | 2 +- .../doctype/repost_item_valuation/repost_item_valuation.py | 7 ++----- erpnext/stock/reorder_item.py | 4 ++-- erpnext/stock/stock_balance.py | 4 ++-- erpnext/stock/utils.py | 2 +- erpnext/support/doctype/issue/issue.py | 2 +- erpnext/utilities/doctype/video/video.py | 4 ++-- 26 files changed, 44 insertions(+), 50 deletions(-) diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index 82af85d702..651599dafd 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -91,8 +91,8 @@ class Account(NestedSet): super(Account, self).on_update() def onload(self): - frozen_accounts_modifier = frappe.db.get_value( - "Accounts Settings", "Accounts Settings", "frozen_accounts_modifier" + frozen_accounts_modifier = frappe.db.get_single_value( + "Accounts Settings", "frozen_accounts_modifier" ) if not frozen_accounts_modifier or frozen_accounts_modifier in frappe.get_roles(): self.set_onload("can_freeze_account", True) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index 139f52696b..777a5bb91c 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -435,8 +435,8 @@ def update_outstanding_amt( def validate_frozen_account(account, adv_adj=None): frozen_account = frappe.get_cached_value("Account", account, "freeze_account") if frozen_account == "Yes" and not adv_adj: - frozen_accounts_modifier = frappe.db.get_value( - "Accounts Settings", None, "frozen_accounts_modifier" + frozen_accounts_modifier = frappe.db.get_single_value( + "Accounts Settings", "frozen_accounts_modifier" ) if not frozen_accounts_modifier: diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index e676560c5c..7f145c569e 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -552,7 +552,7 @@ class PurchaseInvoice(BuyingController): self.against_expense_account = ",".join(against_accounts) def po_required(self): - if frappe.db.get_value("Buying Settings", None, "po_required") == "Yes": + if frappe.db.get_single_value("Buying Settings", "po_required") == "Yes": if frappe.get_value( "Supplier", self.supplier, "allow_purchase_invoice_creation_without_purchase_order" @@ -572,7 +572,7 @@ class PurchaseInvoice(BuyingController): def pr_required(self): stock_items = self.get_stock_items() - if frappe.db.get_value("Buying Settings", None, "pr_required") == "Yes": + if frappe.db.get_single_value("Buying Settings", "pr_required") == "Yes": if frappe.get_value( "Supplier", self.supplier, "allow_purchase_invoice_creation_without_purchase_receipt" diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 8aa95bfa44..5acd8b074b 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -1237,8 +1237,8 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin): @change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_gain_loss_with_advance_entry(self): - unlink_enabled = frappe.db.get_value( - "Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice" + unlink_enabled = frappe.db.get_single_value( + "Accounts Settings", "unlink_payment_on_cancel_of_invoice" ) frappe.db.set_single_value("Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 91ba239f33..b48a8e6115 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -654,10 +654,10 @@ def check_freezing_date(posting_date, adv_adj=False): Hence stop admin to bypass if accounts are freezed """ if not adv_adj: - acc_frozen_upto = frappe.db.get_value("Accounts Settings", None, "acc_frozen_upto") + acc_frozen_upto = frappe.db.get_single_value("Accounts Settings", "acc_frozen_upto") if acc_frozen_upto: - frozen_accounts_modifier = frappe.db.get_value( - "Accounts Settings", None, "frozen_accounts_modifier" + frozen_accounts_modifier = frappe.db.get_single_value( + "Accounts Settings", "frozen_accounts_modifier" ) if getdate(posting_date) <= getdate(acc_frozen_upto) and ( frozen_accounts_modifier not in frappe.get_roles() or frappe.session.user == "Administrator" diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index 9feda11d3f..3a70afc3f0 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -55,8 +55,8 @@ class ReceivablePayableReport(object): def run(self, args): self.filters.update(args) self.set_defaults() - self.party_naming_by = frappe.db.get_value( - args.get("naming_by")[0], None, args.get("naming_by")[1] + self.party_naming_by = frappe.db.get_single_value( + args.get("naming_by")[0], args.get("naming_by")[1] ) self.get_columns() self.get_data() diff --git a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py index 22b5c6ba76..0947cffc9f 100644 --- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py +++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py @@ -24,8 +24,8 @@ class AccountsReceivableSummary(ReceivablePayableReport): def run(self, args): self.account_type = args.get("account_type") self.party_type = get_party_types_from_account_type(self.account_type) - self.party_naming_by = frappe.db.get_value( - args.get("naming_by")[0], None, args.get("naming_by")[1] + self.party_naming_by = frappe.db.get_single_value( + args.get("naming_by")[0], args.get("naming_by")[1] ) self.get_columns() self.get_data(args) diff --git a/erpnext/accounts/report/customer_ledger_summary/customer_ledger_summary.py b/erpnext/accounts/report/customer_ledger_summary/customer_ledger_summary.py index 0464f99d20..a2c0f86f6c 100644 --- a/erpnext/accounts/report/customer_ledger_summary/customer_ledger_summary.py +++ b/erpnext/accounts/report/customer_ledger_summary/customer_ledger_summary.py @@ -21,8 +21,8 @@ class PartyLedgerSummaryReport(object): frappe.throw(_("From Date must be before To Date")) self.filters.party_type = args.get("party_type") - self.party_naming_by = frappe.db.get_value( - args.get("naming_by")[0], None, args.get("naming_by")[1] + self.party_naming_by = frappe.db.get_single_value( + args.get("naming_by")[0], args.get("naming_by")[1] ) self.get_gl_entries() diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index 66930c0e7c..017df90d41 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -35,7 +35,7 @@ from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_sched def post_depreciation_entries(date=None): # Return if automatic booking of asset depreciation is disabled if not cint( - frappe.db.get_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically") + frappe.db.get_single_value("Accounts Settings", "book_asset_depreciation_entry_automatically") ): return diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py index 9aaf86b3ab..eec996c6a9 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -358,8 +358,8 @@ def make_supplier_quotation_from_rfq(source_name, target_doc=None, for_supplier= target_doc.currency = args.currency or get_party_account_currency( "Supplier", for_supplier, source.company ) - target_doc.buying_price_list = args.buying_price_list or frappe.db.get_value( - "Buying Settings", None, "buying_price_list" + target_doc.buying_price_list = args.buying_price_list or frappe.db.get_single_value( + "Buying Settings", "buying_price_list" ) set_missing_values(source, target_doc) @@ -399,7 +399,7 @@ def create_supplier_quotation(doc): "currency": doc.get("currency") or get_party_account_currency("Supplier", doc.get("supplier"), doc.get("company")), "buying_price_list": doc.get("buying_price_list") - or frappe.db.get_value("Buying Settings", None, "buying_price_list"), + or frappe.db.get_single_value("Buying Settings", "buying_price_list"), } ) add_items(sq_doc, doc.get("supplier"), doc.get("items")) diff --git a/erpnext/erpnext_integrations/doctype/tally_migration/tally_migration.py b/erpnext/erpnext_integrations/doctype/tally_migration/tally_migration.py index 8ebca549a0..ba1fae925e 100644 --- a/erpnext/erpnext_integrations/doctype/tally_migration/tally_migration.py +++ b/erpnext/erpnext_integrations/doctype/tally_migration/tally_migration.py @@ -129,9 +129,7 @@ class TallyMigration(Document): self.default_cost_center, self.default_round_off_account = frappe.db.get_value( "Company", self.erpnext_company, ["cost_center", "round_off_account"] ) - self.default_warehouse = frappe.db.get_value( - "Stock Settings", "Stock Settings", "default_warehouse" - ) + self.default_warehouse = frappe.db.get_single_value("Stock Settings", "default_warehouse") def _process_master_data(self): def get_company_name(collection): diff --git a/erpnext/manufacturing/doctype/workstation/workstation.py b/erpnext/manufacturing/doctype/workstation/workstation.py index 0a247fc431..0f05eaac00 100644 --- a/erpnext/manufacturing/doctype/workstation/workstation.py +++ b/erpnext/manufacturing/doctype/workstation/workstation.py @@ -156,7 +156,7 @@ def check_if_within_operating_hours(workstation, operation, from_datetime, to_da if not frappe.db.get_single_value("Manufacturing Settings", "allow_production_on_holidays"): check_workstation_for_holiday(workstation, from_datetime, to_datetime) - if not cint(frappe.db.get_value("Manufacturing Settings", None, "allow_overtime")): + if not cint(frappe.db.get_single_value("Manufacturing Settings", "allow_overtime")): is_within_operating_hours(workstation, operation, from_datetime, to_datetime) diff --git a/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py b/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py index 0f77afda78..8e58d79b92 100644 --- a/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py +++ b/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py @@ -45,7 +45,7 @@ def execute(): message=json.dumps(purchase_invoices + sales_invoices, indent=2), ) - acc_frozen_upto = frappe.db.get_value("Accounts Settings", None, "acc_frozen_upto") + acc_frozen_upto = frappe.db.get_single_value("Accounts Settings", "acc_frozen_upto") if acc_frozen_upto: frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None) diff --git a/erpnext/patches/v14_0/migrate_crm_settings.py b/erpnext/patches/v14_0/migrate_crm_settings.py index 24772553d9..d093bc386e 100644 --- a/erpnext/patches/v14_0/migrate_crm_settings.py +++ b/erpnext/patches/v14_0/migrate_crm_settings.py @@ -2,8 +2,7 @@ import frappe def execute(): - settings = frappe.db.get_value( - "Selling Settings", + settings = frappe.db.get_single_value( "Selling Settings", ["campaign_naming_by", "close_opportunity_after_days", "default_valid_till"], as_dict=True, diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index a6c86a670d..ac7fdb1b45 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -35,8 +35,8 @@ class TestSalesOrder(FrappeTestCase): def setUpClass(cls): super().setUpClass() cls.unlink_setting = int( - frappe.db.get_value( - "Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order" + frappe.db.get_single_value( + "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order" ) ) diff --git a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py index 98633cb719..a584d3ae53 100644 --- a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py +++ b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py @@ -13,7 +13,7 @@ def execute(filters=None): if not filters: filters = {} # Check if customer id is according to naming series or customer name - customer_naming_type = frappe.db.get_value("Selling Settings", None, "cust_master_name") + customer_naming_type = frappe.db.get_single_value("Selling Settings", "cust_master_name") columns = get_columns(customer_naming_type) data = [] diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py index 4b4d14f89e..4cd0ef4eef 100644 --- a/erpnext/startup/boot.py +++ b/erpnext/startup/boot.py @@ -9,7 +9,7 @@ from frappe.utils import cint def boot_session(bootinfo): """boot session - send website info if guest""" - bootinfo.custom_css = frappe.db.get_value("Style Settings", None, "custom_css") or "" + bootinfo.custom_css = frappe.db.get_single_value("Style Settings", "custom_css") or "" if frappe.session["user"] != "Guest": update_page_info(bootinfo) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 2d9e11ab84..feb4583436 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -635,8 +635,8 @@ class Item(Document): def recalculate_bin_qty(self, new_name): from erpnext.stock.stock_balance import repost_stock - existing_allow_negative_stock = frappe.db.get_value( - "Stock Settings", None, "allow_negative_stock" + existing_allow_negative_stock = frappe.db.get_single_value( + "Stock Settings", "allow_negative_stock" ) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1) diff --git a/erpnext/stock/doctype/price_list/price_list.py b/erpnext/stock/doctype/price_list/price_list.py index 580c7c00b1..882c3f5c9c 100644 --- a/erpnext/stock/doctype/price_list/price_list.py +++ b/erpnext/stock/doctype/price_list/price_list.py @@ -39,11 +39,11 @@ class PriceList(Document): def set_default_if_missing(self): if cint(self.selling): - if not frappe.db.get_value("Selling Settings", None, "selling_price_list"): + if not frappe.db.get_single_value("Selling Settings", "selling_price_list"): frappe.set_value("Selling Settings", "Selling Settings", "selling_price_list", self.name) elif cint(self.buying): - if not frappe.db.get_value("Buying Settings", None, "buying_price_list"): + if not frappe.db.get_single_value("Buying Settings", "buying_price_list"): frappe.set_value("Buying Settings", "Buying Settings", "buying_price_list", self.name) def update_item_price(self): diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index c7e36e9904..5cfa739242 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -302,7 +302,7 @@ class PurchaseReceipt(BuyingController): ) def po_required(self): - if frappe.db.get_value("Buying Settings", None, "po_required") == "Yes": + if frappe.db.get_single_value("Buying Settings", "po_required") == "Yes": for d in self.get("items"): if not d.purchase_order: frappe.throw(_("Purchase Order number required for Item {0}").format(d.item_code)) diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index 79b8ee30cf..909aa36710 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -140,11 +140,8 @@ class RepostItemValuation(Document): return query[0][0] if query else None def validate_accounts_freeze(self): - acc_settings = frappe.db.get_value( - "Accounts Settings", - "Accounts Settings", - ["acc_frozen_upto", "frozen_accounts_modifier"], - as_dict=1, + acc_settings = frappe.db.get_single_value( + "Accounts Settings", ["acc_frozen_upto", "frozen_accounts_modifier"], as_dict=1 ) if not acc_settings.acc_frozen_upto: return diff --git a/erpnext/stock/reorder_item.py b/erpnext/stock/reorder_item.py index a6f52f3731..4cd9cbb9d5 100644 --- a/erpnext/stock/reorder_item.py +++ b/erpnext/stock/reorder_item.py @@ -18,7 +18,7 @@ def reorder_item(): if not (frappe.db.a_row_exists("Company") and frappe.db.a_row_exists("Fiscal Year")): return - if cint(frappe.db.get_value("Stock Settings", None, "auto_indent")): + if cint(frappe.db.get_single_value("Stock Settings", "auto_indent")): return _reorder_item() @@ -212,7 +212,7 @@ def create_material_request(material_requests): if mr_list: if getattr(frappe.local, "reorder_email_notify", None) is None: frappe.local.reorder_email_notify = cint( - frappe.db.get_value("Stock Settings", None, "reorder_email_notify") + frappe.db.get_single_value("Stock Settings", "reorder_email_notify") ) if frappe.local.reorder_email_notify: diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index a4fe2ee52f..ba03ff2ad7 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -15,8 +15,8 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False, frappe.db.auto_commit_on_many_writes = 1 if allow_negative_stock: - existing_allow_negative_stock = frappe.db.get_value( - "Stock Settings", None, "allow_negative_stock" + existing_allow_negative_stock = frappe.db.get_single_value( + "Stock Settings", "allow_negative_stock" ) frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1) diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 4b0e2845c4..f29e7ea6a1 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -338,7 +338,7 @@ def get_valuation_method(item_code): val_method = frappe.db.get_value("Item", item_code, "valuation_method", cache=True) if not val_method: val_method = ( - frappe.db.get_value("Stock Settings", None, "valuation_method", cache=True) or "FIFO" + frappe.db.get_single_value("Stock Settings", "valuation_method", cache=True) or "FIFO" ) return val_method diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py index c03fb3ea1f..dc1529b26f 100644 --- a/erpnext/support/doctype/issue/issue.py +++ b/erpnext/support/doctype/issue/issue.py @@ -230,7 +230,7 @@ def set_status(name, status): def auto_close_tickets(): """Auto-close replied support tickets after 7 days""" auto_close_after_days = ( - frappe.db.get_value("Support Settings", "Support Settings", "close_issue_after_days") or 7 + frappe.db.get_single_value("Support Settings", "close_issue_after_days") or 7 ) table = frappe.qb.DocType("Issue") diff --git a/erpnext/utilities/doctype/video/video.py b/erpnext/utilities/doctype/video/video.py index 1a9fe19732..7a04329cb9 100644 --- a/erpnext/utilities/doctype/video/video.py +++ b/erpnext/utilities/doctype/video/video.py @@ -78,8 +78,8 @@ def get_frequency(value): def update_youtube_data(): # Called every 30 minutes via hooks - enable_youtube_tracking, frequency = frappe.db.get_value( - "Video Settings", "Video Settings", ["enable_youtube_tracking", "frequency"] + enable_youtube_tracking, frequency = frappe.db.get_single_value( + "Video Settings", ["enable_youtube_tracking", "frequency"] ) if not cint(enable_youtube_tracking):