@@ -549,7 +549,7 @@ class Database(object): | |||||
return r and [[i[1] for i in r]] or [] | return r and [[i[1] for i in r]] or [] | ||||
def get_singles_dict(self, doctype, debug = False): | |||||
def get_singles_dict(self, doctype, debug=False, *, for_update=False): | |||||
"""Get Single DocType as dict. | """Get Single DocType as dict. | ||||
:param doctype: DocType of the single object whose value is requested | :param doctype: DocType of the single object whose value is requested | ||||
@@ -560,10 +560,13 @@ class Database(object): | |||||
account_settings = frappe.db.get_singles_dict("Accounts Settings") | account_settings = frappe.db.get_singles_dict("Accounts Settings") | ||||
""" | """ | ||||
result = self.query.get_sql( | result = self.query.get_sql( | ||||
"Singles", filters={"doctype": doctype}, fields=["field", "value"] | |||||
"Singles", | |||||
filters={"doctype": doctype}, | |||||
fields=["field", "value"], | |||||
for_update=for_update, | |||||
).run() | ).run() | ||||
dict_ = frappe._dict(result) | |||||
return dict_ | |||||
return frappe._dict(result) | |||||
@staticmethod | @staticmethod | ||||
def get_all(*args, **kwargs): | def get_all(*args, **kwargs): | ||||
@@ -96,14 +96,11 @@ class Document(BaseDocument): | |||||
if isinstance(args[0], str): | if isinstance(args[0], str): | ||||
# first arugment is doctype | # first arugment is doctype | ||||
self.doctype = args[0] | self.doctype = args[0] | ||||
self.name = self.doctype if len(args) == 1 else args[1] | |||||
if len(args) == 1: | |||||
# single | |||||
self.name = self.doctype | |||||
else: | |||||
self.name = args[1] | |||||
self.flags.for_update = kwargs.get("for_update") | |||||
# for_update is set in flags to avoid changing load_from_db signature | |||||
# since it is used in virtual doctypes and inherited in child classes | |||||
self.flags.for_update = kwargs.get("for_update") | |||||
self.load_from_db() | self.load_from_db() | ||||
return | return | ||||
@@ -130,7 +127,9 @@ class Document(BaseDocument): | |||||
"""Load document and children from database and create properties | """Load document and children from database and create properties | ||||
from fields""" | from fields""" | ||||
if not getattr(self, "_metaclass", False) and self.meta.issingle: | if not getattr(self, "_metaclass", False) and self.meta.issingle: | ||||
single_doc = frappe.db.get_singles_dict(self.doctype) | |||||
single_doc = frappe.db.get_singles_dict( | |||||
self.doctype, for_update=self.flags.for_update | |||||
) | |||||
if not single_doc: | if not single_doc: | ||||
single_doc = frappe.new_doc(self.doctype, as_dict=True) | single_doc = frappe.new_doc(self.doctype, as_dict=True) | ||||
single_doc["name"] = self.doctype | single_doc["name"] = self.doctype | ||||