def get_single_value(self, doctype, fieldname, cache=False): """Get property of Single DocType. Cache locally by default :param doctype: DocType of the single object whose value is requested :param fieldname: `fieldname` of the property whose value is requested Example: # Get the default value of the company from the Global Defaults doctype. company = frappe.db.get_single_value('Global Defaults', 'default_company') """ if not doctype in self.value_cache: self.value_cache[doctype] = {} if fieldname in self.value_cache[doctype]: return self.value_cache[doctype][fieldname] val = self.sql( """select `value` from `tabSingles` where `doctype`=%s and `field`=%s""", (doctype, fieldname)) val = val[0][0] if val else None df = frappe.get_meta(doctype).get_field(fieldname) if not df: frappe.throw( _('Invalid field name: {0}').format(frappe.bold(fieldname)), self.InvalidColumnName) val = cast(df.fieldtype, val) self.value_cache[doctype][fieldname] = val return val
def apply_property_setters(self): """ Property Setters are set via Customize Form. They override standard properties of the doctype or its child properties like fields, links etc. This method applies the customized properties over the standard meta object """ if not frappe.db.table_exists("Property Setter"): return property_setters = frappe.db.sql( """select * from `tabProperty Setter` where doc_type=%s""", (self.name,), as_dict=1, ) if not property_setters: return for ps in property_setters: if ps.doctype_or_field == "DocType": self.set(ps.property, cast(ps.property_type, ps.value)) elif ps.doctype_or_field == "DocField": for d in self.fields: if d.fieldname == ps.field_name: d.set(ps.property, cast(ps.property_type, ps.value)) break elif ps.doctype_or_field == "DocType Link": for d in self.links: if d.name == ps.row_name: d.set(ps.property, cast(ps.property_type, ps.value)) break elif ps.doctype_or_field == "DocType Action": for d in self.actions: if d.name == ps.row_name: d.set(ps.property, cast(ps.property_type, ps.value)) break