def get_formatted(self, fieldname, doc=None, currency=None, absolute_value=False, translated=False): from frappe.utils.formatters import format_value df = self.meta.get_field(fieldname) if not df and fieldname in default_fields: from frappe.model.meta import get_default_df df = get_default_df(fieldname) val = self.get(fieldname) if translated: val = _(val) if absolute_value and isinstance(val, (int, float)): val = abs(self.get(fieldname)) if not doc: doc = getattr(self, "parent_doc", None) or self return format_value(val, df=df, doc=doc, currency=currency)
def get_formatted( self, fieldname, doc=None, currency=None, absolute_value=False, translated=False, format=None ): from frappe.utils.formatters import format_value df = self.meta.get_field(fieldname) if not df and fieldname in default_fields: from frappe.model.meta import get_default_df df = get_default_df(fieldname) if df and not currency: currency = self.get(df.get("options")) if not frappe.db.exists("Currency", currency, cache=True): currency = None val = self.get(fieldname) if translated: val = _(val) if not doc: doc = getattr(self, "parent_doc", None) or self if (absolute_value or doc.get("absolute_value")) and isinstance(val, (int, float)): val = abs(self.get(fieldname)) return format_value(val, df=df, doc=doc, currency=currency, format=format)
def get_formatted(self, fieldname, doc=None, currency=None): from frappe.utils.formatters import format_value df = self.meta.get_field(fieldname) if not df and fieldname in default_fields: from frappe.model.meta import get_default_df df = get_default_df(fieldname) return format_value(self.get(fieldname), df=df, doc=doc or self, currency=currency)
def get_formatted(self, fieldname, doc=None, currency=None, absolute_value=False): from frappe.utils.formatters import format_value df = self.meta.get_field(fieldname) if not df and fieldname in default_fields: from frappe.model.meta import get_default_df df = get_default_df(fieldname) val = self.get(fieldname) if absolute_value and isinstance(val, (int, float)): val = abs(self.get(fieldname)) return format_value(val, df=df, doc=doc or self, currency=currency)
def get_currency(self, fieldname, doc=None): df = self.meta.get_field(fieldname) if not df and fieldname in default_fields: from frappe.model.meta import get_default_df df = get_default_df(fieldname) val = 1 if not doc: doc = getattr(self, "parent_doc", None) or self from frappe.model.meta import get_field_currency return get_field_currency(df, doc=doc)
def set_fetch_from_value(self, doctype, df, values): fetch_from_fieldname = df.fetch_from.split('.')[-1] value = values[fetch_from_fieldname] if df.fieldtype == 'Small Text' or df.fieldtype == 'Text' or df.fieldtype == 'Data': if fetch_from_fieldname in default_fields: from frappe.model.meta import get_default_df fetch_from_df = get_default_df(fetch_from_fieldname) else: fetch_from_df = frappe.get_meta(doctype).get_field( fetch_from_fieldname) fetch_from_ft = fetch_from_df.get('fieldtype') if fetch_from_ft == 'Text Editor' and value: value = unescape_html(strip_html(value)) setattr(self, df.fieldname, value)
def set_fetch_from_value(self, doctype, df, values): fetch_from_fieldname = df.fetch_from.split('.')[-1] value = values[fetch_from_fieldname] if df.fieldtype in ['Small Text', 'Text', 'Data']: if fetch_from_fieldname in default_fields: from frappe.model.meta import get_default_df fetch_from_df = get_default_df(fetch_from_fieldname) else: fetch_from_df = frappe.get_meta(doctype).get_field(fetch_from_fieldname) if not fetch_from_df: frappe.throw( _('Please check the value of "Fetch From" set for field {0}').format(frappe.bold(df.label)), title = _('Wrong Fetch From value') ) fetch_from_ft = fetch_from_df.get('fieldtype') if fetch_from_ft == 'Text Editor' and value: value = unescape_html(strip_html(value)) setattr(self, df.fieldname, value)