def create_vars_from_doc(doc: Document, key=None) -> list: """ Utility function to prepare the template vars from a doc :param doc: The document as a dictionary :param key: Optionally specify the key name. If not specified, the scrub name of the doctype will be used For instance, Sales Order will be called sales_order :return: """ if not doc: return [] doc = doc.as_dict(convert_dates_to_str=True, no_nulls=True) if len(doc) == 0: return [] doctype = doc.get("doctype").lower() template_vars = [] to_del = [] for k, v in doc.items(): # Remove iterables from the variables if isinstance(v, (list, tuple, dict)): to_del.append(k) continue # Convert date object to string if isinstance(v, datetime.date): doc[k] = get_datetime_str(v) for k in to_del: del doc[k] template_vars.append({"name": key if key is not None else frappe.scrub(doctype), "content": doc}) return template_vars
def autoname(self): naming_series = Document.get("guardian_naming_series") if naming_series: self.naming_series = naming_series