def on_update(self): if frappe.flags.in_patch: self.flags.validate_fields_for_doctype = False if not self.flags.ignore_validate and self.flags.validate_fields_for_doctype: from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.doc_type)
def sync_customizations_for_doctype(data): '''Sync doctype customzations for a particular data set''' from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype doctype = data['doctype'] update_schema = False def sync(key, custom_doctype, doctype_fieldname): frappe.db.sql( 'delete from `tab{0}` where `{1}`=%s'.format( custom_doctype, doctype_fieldname), doctype) for d in data[key]: d['doctype'] = custom_doctype doc = frappe.get_doc(d) doc.db_insert() if data['custom_fields']: sync('custom_fields', 'Custom Field', 'dt') update_schema = True if data['property_setters']: sync('property_setters', 'Property Setter', 'doc_type') if data.get('custom_perms'): sync('custom_perms', 'Custom DocPerm', 'parent') print 'Updating customizations for {0}'.format(doctype) validate_fields_for_doctype(doctype) if update_schema and not frappe.db.get_value('DocType', doctype, 'issingle'): from frappe.model.db_schema import updatedb updatedb(doctype)
def save_customization(self): if not self.doc_type: return validate_series(self, self.autoname, self.doc_type) self.flags.update_db = False self.flags.rebuild_doctype_for_global_search = False self.set_property_setters() self.update_custom_fields() self.set_name_translation() validate_fields_for_doctype(self.doc_type) check_email_append_to(self) if self.flags.update_db: frappe.db.updatedb(self.doc_type) if not hasattr(self, 'hide_success') or not self.hide_success: frappe.msgprint(_("{0} updated").format(_(self.doc_type)), alert=True) frappe.clear_cache(doctype=self.doc_type) self.fetch_to_customize() if self.flags.rebuild_doctype_for_global_search: frappe.enqueue('frappe.utils.global_search.rebuild_for_doctype', now=True, doctype=self.doc_type)
def post(self): """ Save diff between Customize Form Bean and DocType Bean as property setter entries """ if self.doc.doc_type: from frappe.model import doc from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype this_doclist = frappe.doclist([self.doc] + self.doclist) ref_doclist = self.get_ref_doclist() dt_doclist = doc.get('DocType', self.doc.doc_type) # get a list of property setter docs self.idx_dirty = False diff_list = self.diff(this_doclist, ref_doclist, dt_doclist) if self.idx_dirty: self.make_idx_property_setter(this_doclist, diff_list) self.set_properties(diff_list) validate_fields_for_doctype(self.doc.doc_type) frappe.clear_cache(doctype=self.doc.doc_type) frappe.msgprint("Updated")
def sync_customizations_for_doctype(data): '''Sync doctype customzations for a particular data set''' from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype doctype = data['doctype'] update_schema = False def sync(key, custom_doctype, doctype_fieldname): doctypes = list(set(map(lambda row: row.get(doctype_fieldname), data[key]))) frappe.db.sql('delete from `tab{0}` where `{1}` in ({2})'.format( custom_doctype, doctype_fieldname, ",".join(["'%s'" % dt for dt in doctypes]))) for d in data[key]: d['doctype'] = custom_doctype doc = frappe.get_doc(d) doc.db_insert() if data['custom_fields']: sync('custom_fields', 'Custom Field', 'dt') update_schema = True if data['property_setters']: sync('property_setters', 'Property Setter', 'doc_type') if data.get('custom_perms'): sync('custom_perms', 'Custom DocPerm', 'parent') print('Updating customizations for {0}'.format(doctype)) validate_fields_for_doctype(doctype) if update_schema and not frappe.db.get_value('DocType', doctype, 'issingle'): from frappe.model.db_schema import updatedb updatedb(doctype)
def sync_customizations_for_doctype(data, folder): '''Sync doctype customzations for a particular data set''' from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype doctype = data['doctype'] update_schema = False def sync(key, custom_doctype, doctype_fieldname): doctypes = list(set(map(lambda row: row.get(doctype_fieldname), data[key]))) # sync single doctype exculding the child doctype def sync_single_doctype(doc_type): def _insert(data): if data.get(doctype_fieldname) == doc_type: data['doctype'] = custom_doctype doc = frappe.get_doc(data) doc.db_insert() if custom_doctype != 'Custom Field': frappe.db.sql('delete from `tab{0}` where `{1}` =%s'.format( custom_doctype, doctype_fieldname), doc_type) for d in data[key]: _insert(d) else: for d in data[key]: field = frappe.db.get_value("Custom Field", {"dt": doc_type, "fieldname": d["fieldname"]}) if not field: d["owner"] = "Administrator" _insert(d) else: custom_field = frappe.get_doc("Custom Field", field) custom_field.flags.ignore_validate = True custom_field.update(d) custom_field.db_update() for doc_type in doctypes: # only sync the parent doctype and child doctype if there isn't any other child table json file if doc_type == doctype or not os.path.exists(os.path.join(folder, frappe.scrub(doc_type)+".json")): sync_single_doctype(doc_type) if data['custom_fields']: sync('custom_fields', 'Custom Field', 'dt') update_schema = True if data['property_setters']: sync('property_setters', 'Property Setter', 'doc_type') if data.get('custom_perms'): sync('custom_perms', 'Custom DocPerm', 'parent') print('Updating customizations for {0}'.format(doctype)) validate_fields_for_doctype(doctype) if update_schema and not frappe.db.get_value('DocType', doctype, 'issingle'): frappe.db.updatedb(doctype)
def on_update(self): frappe.clear_cache(doctype=self.dt) if not self.flags.ignore_validate: # validate field from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.dt) # update the schema if not frappe.db.get_value('DocType', self.dt, 'issingle'): frappe.db.updatedb(self.dt)
def on_update(self): frappe.clear_cache(doctype=self.dt) if not self.flags.ignore_validate: # validate field from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.dt) # update the schema # if not frappe.flags.in_test: from frappe.model.db_schema import updatedb updatedb(self.dt)
def save_customization(self): if not self.doc_type: return self.set_property_setters() self.update_custom_fields() validate_fields_for_doctype(self.doc_type) frappe.msgprint(_("{0} updated").format(_(self.doc_type))) frappe.clear_cache(doctype=self.doc_type) self.fetch_to_customize()
def on_update(self): frappe.clear_cache(doctype=self.dt) if not self.flags.ignore_validate: # validate field from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.dt) # update the schema if not frappe.db.get_value('DocType', self.dt, 'issingle'): if (self.fieldname not in frappe.db.get_table_columns(self.dt) or getattr(self, "_old_fieldtype", None) != self.fieldtype): frappe.db.updatedb(self.dt)
def on_update(self): frappe.clear_cache(doctype=self.dt) if not self.flags.ignore_validate: # validate field from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.dt) # update the schema if not frappe.db.get_value('DocType', self.dt, 'issingle'): if (self.fieldname not in frappe.db.get_table_columns(self.dt) or getattr(self, "_old_fieldtype", None) != self.fieldtype): from frappe.model.db_schema import updatedb updatedb(self.dt)
def on_update(self): # validate field from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.doc.dt) frappe.clear_cache(doctype=self.doc.dt) # create property setter to emulate insert after self.create_property_setter() # update the schema from frappe.model.db_schema import updatedb updatedb(self.doc.dt)
def on_update(self): frappe.clear_cache(doctype=self.dt) if not getattr(self, "ignore_validate", False): # validate field from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.dt) # create property setter to emulate insert after self.create_property_setter() # update the schema # if not frappe.flags.in_test: from frappe.model.db_schema import updatedb updatedb(self.dt)
def on_update(self): if not frappe.flags.in_setup_wizard: frappe.clear_cache(doctype=self.dt) if not self.flags.ignore_validate: # validate field from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.dt) # update the schema if not frappe.db.get_value( "DocType", self.dt, "issingle") and not frappe.flags.in_setup_wizard: frappe.db.updatedb(self.dt)
def on_update(self): frappe.clear_cache(doctype=self.dt) if not self.flags.ignore_validate: # validate field from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.dt) # create property setter to emulate insert after self.create_property_setter() # update the schema # if not frappe.flags.in_test: from frappe.model.db_schema import updatedb updatedb(self.dt)
def save_customization(self): if not self.doc_type: return if docfield_properties.has_key('allow_on_submit'): del docfield_properties['allow_on_submit'] self.set_property_setters() self.set_allow_on_submit() self.update_custom_fields() validate_fields_for_doctype(self.doc_type) frappe.msgprint(_("Completed Updating {0}").format(_(self.doc_type))) frappe.clear_cache(doctype=self.doc_type) self.fetch_to_customize()
def on_update(self): frappe.clear_cache(doctype=self.dt) if not self.flags.ignore_validate: # validate field from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.dt) # create property setter to emulate insert after if self.insert_after: self.set_property_setter_for_idx() # update the schema # if not frappe.flags.in_test: from frappe.model.db_schema import updatedb updatedb(self.dt)
def save_customization(self): if not self.doc_type: return self.flags.update_db = False self.set_property_setters() self.update_custom_fields() self.set_name_translation() validate_fields_for_doctype(self.doc_type) if self.flags.update_db: from frappe.model.db_schema import updatedb updatedb(self.doc_type) frappe.msgprint(_("{0} updated").format(_(self.doc_type))) frappe.clear_cache(doctype=self.doc_type) self.fetch_to_customize()
def save_customization(self): if not self.doc_type: return self.flags.update_db = False self.set_property_setters() self.update_custom_fields() self.set_name_translation() validate_fields_for_doctype(self.doc_type) if self.flags.update_db: frappe.db.updatedb(self.doc_type) if not hasattr(self, 'hide_success') or not self.hide_success: frappe.msgprint(_("{0} updated").format(_(self.doc_type))) frappe.clear_cache(doctype=self.doc_type) self.fetch_to_customize()
def sync_customizations_for_doctype(data, folder): '''Sync doctype customzations for a particular data set''' from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype doctype = data['doctype'] update_schema = False def sync(key, custom_doctype, doctype_fieldname): doctypes = list(set(map(lambda row: row.get(doctype_fieldname), data[key]))) # sync single doctype exculding the child doctype def sync_single_doctype(doc_type): frappe.db.sql('delete from `tab{0}` where `{1}` =%s'.format( custom_doctype, doctype_fieldname), doc_type) for d in data[key]: if d.get(doctype_fieldname) == doc_type: d['doctype'] = custom_doctype doc = frappe.get_doc(d) doc.db_insert() for doc_type in doctypes: # only sync the parent doctype and child doctype if there isn't any other child table json file if doc_type == doctype or not os.path.exists(os.path.join(folder, frappe.scrub(doc_type)+".json")): sync_single_doctype(doc_type) if data['custom_fields']: sync('custom_fields', 'Custom Field', 'dt') update_schema = True if data['property_setters']: sync('property_setters', 'Property Setter', 'doc_type') if data.get('custom_perms'): sync('custom_perms', 'Custom DocPerm', 'parent') print('Updating customizations for {0}'.format(doctype)) validate_fields_for_doctype(doctype) if update_schema and not frappe.db.get_value('DocType', doctype, 'issingle'): from frappe.model.db_schema import updatedb updatedb(doctype)
def sync_customizations_for_doctype(data): '''Sync doctype customzations for a particular data set''' from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype doctype = data['doctype'] if data['custom_fields']: frappe.db.sql('delete from `tabCustom Field` where dt=%s', doctype) for d in data['custom_fields']: d['doctype'] = 'Custom Field' doc = frappe.get_doc(d) doc.db_insert() if data['property_setters']: frappe.db.sql('delete from `tabProperty Setter` where doc_type=%s', doctype) for d in data['property_setters']: d['doctype'] = 'Property Setter' doc = frappe.get_doc(d) doc.db_insert() print 'Updating customizations for {0}'.format(doctype) validate_fields_for_doctype(doctype)
def save_customization(self): if not self.doc_type: return self.flags.update_db = False self.flags.rebuild_doctype_for_global_search = False self.set_property_setters() self.update_custom_fields() self.set_name_translation() validate_fields_for_doctype(self.doc_type) if self.flags.update_db: from frappe.model.db_schema import updatedb updatedb(self.doc_type) if not hasattr(self, 'hide_success') or not self.hide_success: frappe.msgprint(_("{0} updated").format(_(self.doc_type))) frappe.clear_cache(doctype=self.doc_type) self.fetch_to_customize() if self.flags.rebuild_doctype_for_global_search: frappe.enqueue('frappe.utils.global_search.rebuild_for_doctype', now=True, doctype=self.doc_type)
def on_update(self): if not getattr(self, "ignore_validate", False): from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.doc_type)
def on_update(self): from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.doc_type)
def on_update(self): from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.doc.doc_type)
def on_update(self): if not getattr(self, "ignore_validate", False) and getattr(self, "validate_fields_for_doctype", True): from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.doc_type)