Пример #1
0
	def on_update(self):
		"""Update database schema, make controller templates if `custom` is not set and clear cache."""
		from frappe.model.db_schema import updatedb
		updatedb(self.name, self)

		self.change_modified_of_parent()
		make_module_and_roles(self)

		self.update_fields_to_fetch()

		from frappe import conf
		if not self.custom and not (frappe.flags.in_import or frappe.flags.in_test) and conf.get('developer_mode'):
			self.export_doc()
			self.make_controller_template()

			if self.has_web_view:
				self.set_base_class_for_controller()

		# update index
		if not self.custom:
			self.run_module_method("on_doctype_update")
			if self.flags.in_insert:
				self.run_module_method("after_doctype_insert")

		delete_notification_count_for(doctype=self.name)
		frappe.clear_cache(doctype=self.name)

		if not frappe.flags.in_install and hasattr(self, 'before_update'):
			self.sync_global_search()

		# clear from local cache
		if self.name in frappe.local.meta_cache:
			del frappe.local.meta_cache[self.name]
Пример #2
0
    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)
Пример #3
0
	def on_update(self):
		"""Update database schema, make controller templates if `custom` is not set and clear cache."""
		from frappe.model.db_schema import updatedb
		updatedb(self.name, self)

		self.change_modified_of_parent()
		make_module_and_roles(self)

		self.update_fields_to_fetch()

		from frappe import conf
		if not self.custom and not (frappe.flags.in_import or frappe.flags.in_test) and conf.get('developer_mode'):
			self.export_doc()
			self.make_controller_template()

			if self.has_web_view:
				self.set_base_class_for_controller()

		# update index
		if not self.custom:
			self.run_module_method("on_doctype_update")
			if self.flags.in_insert:
				self.run_module_method("after_doctype_insert")

		delete_notification_count_for(doctype=self.name)
		frappe.clear_cache(doctype=self.name)

		if not frappe.flags.in_install and hasattr(self, 'before_update'):
			self.sync_global_search()

		# clear from local cache
		if self.name in frappe.local.meta_cache:
			del frappe.local.meta_cache[self.name]
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
    def on_update(self):
        """Update database schema, make controller templates if `custom` is not set and clear cache."""
        from frappe.model.db_schema import updatedb
        updatedb(self.name, self)

        self.change_modified_of_parent()
        make_module_and_roles(self)

        self.update_fields_to_fetch()

        from frappe import conf
        if not self.custom and not (
                frappe.flags.in_import
                or frappe.flags.in_test) and conf.get('developer_mode'):
            self.export_doc()
            self.make_controller_template()

        # update index
        if not self.custom:
            self.run_module_method("on_doctype_update")
            if self.flags.in_insert:
                self.run_module_method("after_doctype_insert")

        delete_notification_count_for(doctype=self.name)
        frappe.clear_cache(doctype=self.name)
Пример #7
0
    def set_property_setters(self):
        meta = frappe.get_meta(self.doc_type)
        # doctype property setters
        for property in self.doctype_properties:
            if property != "idx" and self.get(property) != meta.get(property):
                self.make_property_setter(
                    property=property, value=self.get(property), property_type=self.doctype_properties[property]
                )

        update_db = False
        for df in self.get("fields"):
            if df.get("__islocal"):
                continue

            meta_df = meta.get("fields", {"fieldname": df.fieldname})

            if not meta_df or meta_df[0].get("is_custom_field"):
                continue

            for property in self.docfield_properties:
                if df.get(property) != meta_df[0].get(property):
                    if property == "fieldtype":
                        self.validate_fieldtype_change(df, meta_df[0].get(property), df.get(property))

                    elif property == "allow_on_submit" and df.get(property):
                        frappe.msgprint(
                            _("Row {0}: Not allowed to enable Allow on Submit for standard fields").format(df.idx)
                        )
                        continue
                    elif (
                        property == "in_list_view"
                        and df.get(property)
                        and df.fieldtype != "Image"
                        and df.fieldtype in no_value_fields
                    ):
                        frappe.msgprint(
                            _("'In List View' not allowed for type {0} in row {1}").format(df.fieldtype, df.idx)
                        )
                        continue

                    elif (
                        property == "precision"
                        and cint(df.get("precision")) > 6
                        and cint(df.get("precision")) > cint(meta_df[0].get("precision"))
                    ):
                        update_db = True

                    self.make_property_setter(
                        property=property,
                        value=df.get(property),
                        property_type=self.docfield_properties[property],
                        fieldname=df.fieldname,
                    )

        if update_db:
            from frappe.model.db_schema import updatedb

            updatedb(self.doc_type)
Пример #8
0
	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)
Пример #9
0
	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 set_property_setters(self):
        meta = frappe.get_meta(self.doc_type)
        # doctype property setters
        for property in self.doctype_properties:
            if self.get(property) != meta.get(property):
                self.make_property_setter(
                    property=property,
                    value=self.get(property),
                    property_type=self.doctype_properties[property])

        update_db = False
        for df in self.get("fields"):
            if df.get("__islocal"):
                continue

            meta_df = meta.get("fields", {"fieldname": df.fieldname})

            if not meta_df or meta_df[0].get("is_custom_field"):
                continue

            for property in self.docfield_properties:
                if property != "idx" and df.get(property) != meta_df[0].get(
                        property):
                    if property == "fieldtype":
                        self.validate_fieldtype_change(
                            df, meta_df[0].get(property), df.get(property))

                    elif property == "allow_on_submit" and df.get(property):
                        frappe.msgprint(_("Row {0}: Not allowed to enable Allow on Submit for standard fields")\
                         .format(df.idx))
                        continue
                    elif property == "in_list_view" and df.get(property) \
                     and df.fieldtype!="Image" and df.fieldtype in no_value_fields:
                        frappe.msgprint(
                            _("'In List View' not allowed for type {0} in row {1}"
                              ).format(df.fieldtype, df.idx))
                        continue

                    elif property == "precision" and cint(df.get("precision")) > 6 \
                      and cint(df.get("precision")) > cint(meta_df[0].get("precision")):
                        update_db = True

                    elif property == "unique":
                        update_db = True

                    self.make_property_setter(
                        property=property,
                        value=df.get(property),
                        property_type=self.docfield_properties[property],
                        fieldname=df.fieldname)

        if update_db:
            from frappe.model.db_schema import updatedb
            updatedb(self.doc_type)
Пример #11
0
	def set_property_setters(self):
		meta = frappe.get_meta(self.doc_type)
		# doctype property setters
		for property in doctype_properties:
			if self.get(property) != meta.get(property):
				self.make_property_setter(property=property, value=self.get(property),
					property_type=doctype_properties[property])

		update_db = False
		for df in self.get("fields"):
			if df.get("__islocal"):
				continue

			meta_df = meta.get("fields", {"fieldname": df.fieldname})

			if not meta_df or meta_df[0].get("is_custom_field"):
				continue

			for property in docfield_properties:
				if property != "idx" and df.get(property) != meta_df[0].get(property):
					if property == "fieldtype":
						self.validate_fieldtype_change(df, meta_df[0].get(property), df.get(property))

					elif property == "allow_on_submit" and df.get(property):
						frappe.msgprint(_("Row {0}: Not allowed to enable Allow on Submit for standard fields")\
							.format(df.idx))
						continue
					elif property == "in_list_view" and df.get(property) \
						and df.fieldtype!="Image" and df.fieldtype in no_value_fields:
								frappe.msgprint(_("'In List View' not allowed for type {0} in row {1}")
									.format(df.fieldtype, df.idx))
								continue

					elif property == "precision" and cint(df.get("precision")) > 6 \
							and cint(df.get("precision")) > cint(meta_df[0].get("precision")):
						update_db = True

					elif property == "unique":
						update_db = True

					elif (property == "read_only" and cint(df.get("read_only"))==0
						and frappe.db.get_value("DocField", {"parent": self.doc_type, "fieldname": df.fieldname}, "read_only")==1):
						# if docfield has read_only checked and user is trying to make it editable, don't allow it
						frappe.msgprint(_("You cannot unset 'Read Only' for field {0}").format(df.label))
						continue

					self.make_property_setter(property=property, value=df.get(property),
						property_type=docfield_properties[property], fieldname=df.fieldname)

		if update_db:
			from frappe.model.db_schema import updatedb
			updatedb(self.doc_type)
	def set_property_setters(self):
		meta = frappe.get_meta(self.doc_type)
		# doctype property setters
		for property in doctype_properties:
			if self.get(property) != meta.get(property):
				self.make_property_setter(property=property, value=self.get(property),
					property_type=doctype_properties[property])

		update_db = False
		for df in self.get("fields"):
			if df.get("__islocal"):
				continue

			meta_df = meta.get("fields", {"fieldname": df.fieldname})

			if not meta_df or meta_df[0].get("is_custom_field"):
				continue

			for property in docfield_properties:
				if property != "idx" and df.get(property) != meta_df[0].get(property):
					if property == "fieldtype":
						self.validate_fieldtype_change(df, meta_df[0].get(property), df.get(property))

					elif property == "allow_on_submit" and df.get(property):
						frappe.msgprint(_("Row {0}: Not allowed to enable Allow on Submit for standard fields")\
							.format(df.idx))
						continue
					elif property == "in_list_view" and df.get(property) \
						and df.fieldtype!="Image" and df.fieldtype in no_value_fields:
								frappe.msgprint(_("'In List View' not allowed for type {0} in row {1}")
									.format(df.fieldtype, df.idx))
								continue

					elif property == "precision" and cint(df.get("precision")) > 6 \
							and cint(df.get("precision")) > cint(meta_df[0].get("precision")):
						update_db = True

					elif property == "unique":
						update_db = True

					elif (property == "read_only" and cint(df.get("read_only"))==0
						and frappe.db.get_value("DocField", {"parent": self.doc_type, "fieldname": df.fieldname}, "read_only")==1):
						# if docfield has read_only checked and user is trying to make it editable, don't allow it
						frappe.msgprint(_("You cannot unset 'Read Only' for field {0}").format(df.label))
						continue

					self.make_property_setter(property=property, value=df.get(property),
						property_type=docfield_properties[property], fieldname=df.fieldname)

		if update_db:
			from frappe.model.db_schema import updatedb
			updatedb(self.doc_type)
Пример #13
0
    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)
Пример #14
0
	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)
Пример #15
0
    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)
Пример #16
0
	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)
Пример #17
0
    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)
Пример #18
0
	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)
Пример #19
0
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)
Пример #20
0
    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()
Пример #21
0
	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()
Пример #22
0
	def on_update(self):
		from frappe.model.db_schema import updatedb
		updatedb(self.name)

		self.change_modified_of_parent()
		make_module_and_roles(self)

		from frappe import conf
		if (not frappe.flags.in_import) and conf.get('developer_mode') or 0:
			self.export_doc()
			self.make_controller_template()

		# update index
		if not getattr(self, "custom", False):
			from frappe.modules import load_doctype_module
			module = load_doctype_module(self.name, self.module)
			if hasattr(module, "on_doctype_update"):
				module.on_doctype_update()
		frappe.clear_cache(doctype=self.name)
Пример #23
0
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)
Пример #24
0
	def on_update(self):
		"""Update database schema, make controller templates if `custom` is not set and clear cache."""
		from frappe.model.db_schema import updatedb
		updatedb(self.name)

		self.change_modified_of_parent()
		make_module_and_roles(self)

		from frappe import conf
		if not self.custom and not (frappe.flags.in_import or frappe.flags.in_test) and conf.get('developer_mode'):
			self.export_doc()
			self.make_controller_template()

		# update index
		if not self.custom:
			self.run_module_method("on_doctype_update")
			if self.flags.in_insert:
				self.run_module_method("after_doctype_insert")

		delete_notification_count_for(doctype=self.name)
		frappe.clear_cache(doctype=self.name)
Пример #25
0
    def on_update(self):
        """Update database schema, make controller templates if `custom` is not set and clear cache."""
        from frappe.model.db_schema import updatedb
        updatedb(self.name)

        self.change_modified_of_parent()
        make_module_and_roles(self)

        from frappe import conf
        if not (frappe.flags.in_import
                or frappe.flags.in_test) and conf.get('developer_mode') or 0:
            self.export_doc()
            self.make_controller_template()

        # update index
        if not getattr(self, "custom", False):
            from frappe.modules import load_doctype_module
            module = load_doctype_module(self.name, self.module)
            if hasattr(module, "on_doctype_update"):
                module.on_doctype_update()

        delete_notification_count_for(doctype=self.name)
        frappe.clear_cache(doctype=self.name)
Пример #26
0
	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)