From c90cea89cb74f52c73c54713c590be9b1ee69968 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 24 May 2021 12:29:28 +0530 Subject: [PATCH] feat(minor): Nudge for method exists for button fieldtype This doesn't throw an exception, rather a msgprint in case the developer isn't ready for that yet. This serves as a nudge rather than a validation --- frappe/core/doctype/doctype/doctype.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 4f97b7d136..b40b36cc55 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -18,6 +18,7 @@ from frappe import _ from frappe.utils import now, cint from frappe.model import no_value_fields, default_fields, data_fieldtypes, table_fields, data_field_options from frappe.model.document import Document +from frappe.model.base_document import get_controller from frappe.custom.doctype.property_setter.property_setter import make_property_setter from frappe.custom.doctype.custom_field.custom_field import create_custom_field from frappe.desk.notifications import delete_notification_count_for @@ -107,8 +108,6 @@ class DocType(Document): if self.name in core_doctypes: return - from frappe.model.base_document import get_controller - try: controller = get_controller(self.name) except ImportError: @@ -123,12 +122,10 @@ class DocType(Document): } for docfield in self.get("fields") or []: - if docfield.fieldtype == "Button": - continue - conflict_type = None field = docfield.fieldname field_label = docfield.label or docfield.fieldname + conflict_should_exist = docfield.fieldtype == "Button" if docfield.fieldname in method_set: conflict_type = "controller method" @@ -136,6 +133,12 @@ class DocType(Document): conflict_type = "class property" if conflict_type: + if conflict_should_exist: + frappe.msgprint( + _("Button '{0}' should have corresponding method with the name '{1}' in the {2}'s controller") + .format(field_label, field, self.name) + ) + frappe.throw( _("Fieldname '{0}' conflicting with a {1} of the name {2} in {3}") .format(field_label, conflict_type, field, self.name)