Merge pull request #12099 from frappe/document-naming-rule-field-validation
fix: document naming rule validation for fields
This commit is contained in:
commit
3fdf78c5cb
1 changed files with 11 additions and 0 deletions
|
|
@ -6,8 +6,19 @@ from __future__ import unicode_literals
|
|||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils.data import evaluate_filters
|
||||
from frappe import _
|
||||
|
||||
class DocumentNamingRule(Document):
|
||||
def validate(self):
|
||||
self.validate_fields_in_conditions()
|
||||
|
||||
def validate_fields_in_conditions(self):
|
||||
if self.has_value_changed("document_type"):
|
||||
docfields = [x.fieldname for x in frappe.get_meta(self.document_type).fields]
|
||||
for condition in self.conditions:
|
||||
if condition.field not in docfields:
|
||||
frappe.throw(_("{0} is not a field of doctype {1}").format(frappe.bold(condition.field), frappe.bold(self.document_type)))
|
||||
|
||||
def apply(self, doc):
|
||||
'''
|
||||
Apply naming rules for the given document. Will set `name` if the rule is matched.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue