refactor: use db.get_single_value
This commit is contained in:
parent
74ceb6da5e
commit
bb18ae82cf
@ -91,8 +91,8 @@ class Account(NestedSet):
|
|||||||
super(Account, self).on_update()
|
super(Account, self).on_update()
|
||||||
|
|
||||||
def onload(self):
|
def onload(self):
|
||||||
frozen_accounts_modifier = frappe.db.get_value(
|
frozen_accounts_modifier = frappe.db.get_single_value(
|
||||||
"Accounts Settings", "Accounts Settings", "frozen_accounts_modifier"
|
"Accounts Settings", "frozen_accounts_modifier"
|
||||||
)
|
)
|
||||||
if not frozen_accounts_modifier or frozen_accounts_modifier in frappe.get_roles():
|
if not frozen_accounts_modifier or frozen_accounts_modifier in frappe.get_roles():
|
||||||
self.set_onload("can_freeze_account", True)
|
self.set_onload("can_freeze_account", True)
|
||||||
|
@ -435,8 +435,8 @@ def update_outstanding_amt(
|
|||||||
def validate_frozen_account(account, adv_adj=None):
|
def validate_frozen_account(account, adv_adj=None):
|
||||||
frozen_account = frappe.get_cached_value("Account", account, "freeze_account")
|
frozen_account = frappe.get_cached_value("Account", account, "freeze_account")
|
||||||
if frozen_account == "Yes" and not adv_adj:
|
if frozen_account == "Yes" and not adv_adj:
|
||||||
frozen_accounts_modifier = frappe.db.get_value(
|
frozen_accounts_modifier = frappe.db.get_single_value(
|
||||||
"Accounts Settings", None, "frozen_accounts_modifier"
|
"Accounts Settings", "frozen_accounts_modifier"
|
||||||
)
|
)
|
||||||
|
|
||||||
if not frozen_accounts_modifier:
|
if not frozen_accounts_modifier:
|
||||||
|
@ -552,7 +552,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
self.against_expense_account = ",".join(against_accounts)
|
self.against_expense_account = ",".join(against_accounts)
|
||||||
|
|
||||||
def po_required(self):
|
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(
|
if frappe.get_value(
|
||||||
"Supplier", self.supplier, "allow_purchase_invoice_creation_without_purchase_order"
|
"Supplier", self.supplier, "allow_purchase_invoice_creation_without_purchase_order"
|
||||||
@ -572,7 +572,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
|
|
||||||
def pr_required(self):
|
def pr_required(self):
|
||||||
stock_items = self.get_stock_items()
|
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(
|
if frappe.get_value(
|
||||||
"Supplier", self.supplier, "allow_purchase_invoice_creation_without_purchase_receipt"
|
"Supplier", self.supplier, "allow_purchase_invoice_creation_without_purchase_receipt"
|
||||||
|
@ -1237,8 +1237,8 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
|
|||||||
|
|
||||||
@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
|
@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
|
||||||
def test_gain_loss_with_advance_entry(self):
|
def test_gain_loss_with_advance_entry(self):
|
||||||
unlink_enabled = frappe.db.get_value(
|
unlink_enabled = frappe.db.get_single_value(
|
||||||
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice"
|
"Accounts Settings", "unlink_payment_on_cancel_of_invoice"
|
||||||
)
|
)
|
||||||
|
|
||||||
frappe.db.set_single_value("Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1)
|
frappe.db.set_single_value("Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1)
|
||||||
|
@ -654,10 +654,10 @@ def check_freezing_date(posting_date, adv_adj=False):
|
|||||||
Hence stop admin to bypass if accounts are freezed
|
Hence stop admin to bypass if accounts are freezed
|
||||||
"""
|
"""
|
||||||
if not adv_adj:
|
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:
|
if acc_frozen_upto:
|
||||||
frozen_accounts_modifier = frappe.db.get_value(
|
frozen_accounts_modifier = frappe.db.get_single_value(
|
||||||
"Accounts Settings", None, "frozen_accounts_modifier"
|
"Accounts Settings", "frozen_accounts_modifier"
|
||||||
)
|
)
|
||||||
if getdate(posting_date) <= getdate(acc_frozen_upto) and (
|
if getdate(posting_date) <= getdate(acc_frozen_upto) and (
|
||||||
frozen_accounts_modifier not in frappe.get_roles() or frappe.session.user == "Administrator"
|
frozen_accounts_modifier not in frappe.get_roles() or frappe.session.user == "Administrator"
|
||||||
|
@ -55,8 +55,8 @@ class ReceivablePayableReport(object):
|
|||||||
def run(self, args):
|
def run(self, args):
|
||||||
self.filters.update(args)
|
self.filters.update(args)
|
||||||
self.set_defaults()
|
self.set_defaults()
|
||||||
self.party_naming_by = frappe.db.get_value(
|
self.party_naming_by = frappe.db.get_single_value(
|
||||||
args.get("naming_by")[0], None, args.get("naming_by")[1]
|
args.get("naming_by")[0], args.get("naming_by")[1]
|
||||||
)
|
)
|
||||||
self.get_columns()
|
self.get_columns()
|
||||||
self.get_data()
|
self.get_data()
|
||||||
|
@ -24,8 +24,8 @@ class AccountsReceivableSummary(ReceivablePayableReport):
|
|||||||
def run(self, args):
|
def run(self, args):
|
||||||
self.account_type = args.get("account_type")
|
self.account_type = args.get("account_type")
|
||||||
self.party_type = get_party_types_from_account_type(self.account_type)
|
self.party_type = get_party_types_from_account_type(self.account_type)
|
||||||
self.party_naming_by = frappe.db.get_value(
|
self.party_naming_by = frappe.db.get_single_value(
|
||||||
args.get("naming_by")[0], None, args.get("naming_by")[1]
|
args.get("naming_by")[0], args.get("naming_by")[1]
|
||||||
)
|
)
|
||||||
self.get_columns()
|
self.get_columns()
|
||||||
self.get_data(args)
|
self.get_data(args)
|
||||||
|
@ -21,8 +21,8 @@ class PartyLedgerSummaryReport(object):
|
|||||||
frappe.throw(_("From Date must be before To Date"))
|
frappe.throw(_("From Date must be before To Date"))
|
||||||
|
|
||||||
self.filters.party_type = args.get("party_type")
|
self.filters.party_type = args.get("party_type")
|
||||||
self.party_naming_by = frappe.db.get_value(
|
self.party_naming_by = frappe.db.get_single_value(
|
||||||
args.get("naming_by")[0], None, args.get("naming_by")[1]
|
args.get("naming_by")[0], args.get("naming_by")[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.get_gl_entries()
|
self.get_gl_entries()
|
||||||
|
@ -35,7 +35,7 @@ from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_sched
|
|||||||
def post_depreciation_entries(date=None):
|
def post_depreciation_entries(date=None):
|
||||||
# Return if automatic booking of asset depreciation is disabled
|
# Return if automatic booking of asset depreciation is disabled
|
||||||
if not cint(
|
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
|
return
|
||||||
|
|
||||||
|
@ -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(
|
target_doc.currency = args.currency or get_party_account_currency(
|
||||||
"Supplier", for_supplier, source.company
|
"Supplier", for_supplier, source.company
|
||||||
)
|
)
|
||||||
target_doc.buying_price_list = args.buying_price_list or frappe.db.get_value(
|
target_doc.buying_price_list = args.buying_price_list or frappe.db.get_single_value(
|
||||||
"Buying Settings", None, "buying_price_list"
|
"Buying Settings", "buying_price_list"
|
||||||
)
|
)
|
||||||
set_missing_values(source, target_doc)
|
set_missing_values(source, target_doc)
|
||||||
|
|
||||||
@ -399,7 +399,7 @@ def create_supplier_quotation(doc):
|
|||||||
"currency": doc.get("currency")
|
"currency": doc.get("currency")
|
||||||
or get_party_account_currency("Supplier", doc.get("supplier"), doc.get("company")),
|
or get_party_account_currency("Supplier", doc.get("supplier"), doc.get("company")),
|
||||||
"buying_price_list": doc.get("buying_price_list")
|
"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"))
|
add_items(sq_doc, doc.get("supplier"), doc.get("items"))
|
||||||
|
@ -129,9 +129,7 @@ class TallyMigration(Document):
|
|||||||
self.default_cost_center, self.default_round_off_account = frappe.db.get_value(
|
self.default_cost_center, self.default_round_off_account = frappe.db.get_value(
|
||||||
"Company", self.erpnext_company, ["cost_center", "round_off_account"]
|
"Company", self.erpnext_company, ["cost_center", "round_off_account"]
|
||||||
)
|
)
|
||||||
self.default_warehouse = frappe.db.get_value(
|
self.default_warehouse = frappe.db.get_single_value("Stock Settings", "default_warehouse")
|
||||||
"Stock Settings", "Stock Settings", "default_warehouse"
|
|
||||||
)
|
|
||||||
|
|
||||||
def _process_master_data(self):
|
def _process_master_data(self):
|
||||||
def get_company_name(collection):
|
def get_company_name(collection):
|
||||||
|
@ -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"):
|
if not frappe.db.get_single_value("Manufacturing Settings", "allow_production_on_holidays"):
|
||||||
check_workstation_for_holiday(workstation, from_datetime, to_datetime)
|
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)
|
is_within_operating_hours(workstation, operation, from_datetime, to_datetime)
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ def execute():
|
|||||||
message=json.dumps(purchase_invoices + sales_invoices, indent=2),
|
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:
|
if acc_frozen_upto:
|
||||||
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)
|
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@ import frappe
|
|||||||
|
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
settings = frappe.db.get_value(
|
settings = frappe.db.get_single_value(
|
||||||
"Selling Settings",
|
|
||||||
"Selling Settings",
|
"Selling Settings",
|
||||||
["campaign_naming_by", "close_opportunity_after_days", "default_valid_till"],
|
["campaign_naming_by", "close_opportunity_after_days", "default_valid_till"],
|
||||||
as_dict=True,
|
as_dict=True,
|
||||||
|
@ -35,8 +35,8 @@ class TestSalesOrder(FrappeTestCase):
|
|||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
cls.unlink_setting = int(
|
cls.unlink_setting = int(
|
||||||
frappe.db.get_value(
|
frappe.db.get_single_value(
|
||||||
"Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order"
|
"Accounts Settings", "unlink_advance_payment_on_cancelation_of_order"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ def execute(filters=None):
|
|||||||
if not filters:
|
if not filters:
|
||||||
filters = {}
|
filters = {}
|
||||||
# Check if customer id is according to naming series or customer name
|
# 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)
|
columns = get_columns(customer_naming_type)
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
|
@ -9,7 +9,7 @@ from frappe.utils import cint
|
|||||||
def boot_session(bootinfo):
|
def boot_session(bootinfo):
|
||||||
"""boot session - send website info if guest"""
|
"""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":
|
if frappe.session["user"] != "Guest":
|
||||||
update_page_info(bootinfo)
|
update_page_info(bootinfo)
|
||||||
|
@ -635,8 +635,8 @@ class Item(Document):
|
|||||||
def recalculate_bin_qty(self, new_name):
|
def recalculate_bin_qty(self, new_name):
|
||||||
from erpnext.stock.stock_balance import repost_stock
|
from erpnext.stock.stock_balance import repost_stock
|
||||||
|
|
||||||
existing_allow_negative_stock = frappe.db.get_value(
|
existing_allow_negative_stock = frappe.db.get_single_value(
|
||||||
"Stock Settings", None, "allow_negative_stock"
|
"Stock Settings", "allow_negative_stock"
|
||||||
)
|
)
|
||||||
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
|
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
|
||||||
|
|
||||||
|
@ -39,11 +39,11 @@ class PriceList(Document):
|
|||||||
|
|
||||||
def set_default_if_missing(self):
|
def set_default_if_missing(self):
|
||||||
if cint(self.selling):
|
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)
|
frappe.set_value("Selling Settings", "Selling Settings", "selling_price_list", self.name)
|
||||||
|
|
||||||
elif cint(self.buying):
|
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)
|
frappe.set_value("Buying Settings", "Buying Settings", "buying_price_list", self.name)
|
||||||
|
|
||||||
def update_item_price(self):
|
def update_item_price(self):
|
||||||
|
@ -302,7 +302,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def po_required(self):
|
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"):
|
for d in self.get("items"):
|
||||||
if not d.purchase_order:
|
if not d.purchase_order:
|
||||||
frappe.throw(_("Purchase Order number required for Item {0}").format(d.item_code))
|
frappe.throw(_("Purchase Order number required for Item {0}").format(d.item_code))
|
||||||
|
@ -140,11 +140,8 @@ class RepostItemValuation(Document):
|
|||||||
return query[0][0] if query else None
|
return query[0][0] if query else None
|
||||||
|
|
||||||
def validate_accounts_freeze(self):
|
def validate_accounts_freeze(self):
|
||||||
acc_settings = frappe.db.get_value(
|
acc_settings = frappe.db.get_single_value(
|
||||||
"Accounts Settings",
|
"Accounts Settings", ["acc_frozen_upto", "frozen_accounts_modifier"], as_dict=1
|
||||||
"Accounts Settings",
|
|
||||||
["acc_frozen_upto", "frozen_accounts_modifier"],
|
|
||||||
as_dict=1,
|
|
||||||
)
|
)
|
||||||
if not acc_settings.acc_frozen_upto:
|
if not acc_settings.acc_frozen_upto:
|
||||||
return
|
return
|
||||||
|
@ -18,7 +18,7 @@ def reorder_item():
|
|||||||
if not (frappe.db.a_row_exists("Company") and frappe.db.a_row_exists("Fiscal Year")):
|
if not (frappe.db.a_row_exists("Company") and frappe.db.a_row_exists("Fiscal Year")):
|
||||||
return
|
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()
|
return _reorder_item()
|
||||||
|
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ def create_material_request(material_requests):
|
|||||||
if mr_list:
|
if mr_list:
|
||||||
if getattr(frappe.local, "reorder_email_notify", None) is None:
|
if getattr(frappe.local, "reorder_email_notify", None) is None:
|
||||||
frappe.local.reorder_email_notify = cint(
|
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:
|
if frappe.local.reorder_email_notify:
|
||||||
|
@ -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
|
frappe.db.auto_commit_on_many_writes = 1
|
||||||
|
|
||||||
if allow_negative_stock:
|
if allow_negative_stock:
|
||||||
existing_allow_negative_stock = frappe.db.get_value(
|
existing_allow_negative_stock = frappe.db.get_single_value(
|
||||||
"Stock Settings", None, "allow_negative_stock"
|
"Stock Settings", "allow_negative_stock"
|
||||||
)
|
)
|
||||||
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
|
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ def get_valuation_method(item_code):
|
|||||||
val_method = frappe.db.get_value("Item", item_code, "valuation_method", cache=True)
|
val_method = frappe.db.get_value("Item", item_code, "valuation_method", cache=True)
|
||||||
if not val_method:
|
if not val_method:
|
||||||
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
|
return val_method
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ def set_status(name, status):
|
|||||||
def auto_close_tickets():
|
def auto_close_tickets():
|
||||||
"""Auto-close replied support tickets after 7 days"""
|
"""Auto-close replied support tickets after 7 days"""
|
||||||
auto_close_after_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")
|
table = frappe.qb.DocType("Issue")
|
||||||
|
@ -78,8 +78,8 @@ def get_frequency(value):
|
|||||||
|
|
||||||
def update_youtube_data():
|
def update_youtube_data():
|
||||||
# Called every 30 minutes via hooks
|
# Called every 30 minutes via hooks
|
||||||
enable_youtube_tracking, frequency = frappe.db.get_value(
|
enable_youtube_tracking, frequency = frappe.db.get_single_value(
|
||||||
"Video Settings", "Video Settings", ["enable_youtube_tracking", "frequency"]
|
"Video Settings", ["enable_youtube_tracking", "frequency"]
|
||||||
)
|
)
|
||||||
|
|
||||||
if not cint(enable_youtube_tracking):
|
if not cint(enable_youtube_tracking):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user