refactor: use db.get_single_value

This commit is contained in:
Ankush Menat 2024-01-09 21:56:47 +05:30
parent 74ceb6da5e
commit bb18ae82cf
26 changed files with 44 additions and 50 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 = []

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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