I have two HTML fields that I am writing custom validation logic for within the overwritten functions for Create and Write methods. For one, the validations are getting fired for both create and write. But for the other field, it is firing only for the create method, not the write method. It's a bit mysterious. Please let me know if I'm missing something here.
Model definition:-
request_text = fields.Html('Incident Description', required=True)
# medical information
has_medical_reasons = fields.Boolean('Has Medical Reasons')
medical_description = fields.Html('Medical Reasons Description', required=True)
Create method:-
@api.model
def create(self, vals):
# Checking if mandatory HTML fields are filled
if vals.get('request_text') == "<p><br></p>":
raise exceptions.Warning("Incident Description cannot be empty!")
if vals.get('has_medical_reasons') == True and vals.get('medical_description') == "<p><br></p>":
raise exceptions.Warning("Please fill in Medical Reasons Description")
Write method:-
def write(self, vals):
# Checking if mandatory HTML fields are filled
if vals.get('request_text') == "<p><br></p>":
raise exceptions.Warning("Incident Description cannot be empty!")
if vals.get('has_medical_reasons') == True and vals.get('medical_description') == "<p><br></p>":
raise exceptions.Warning("Please fill in Medical Reasons Description")
XML:-
<field name="request_text" widget="html" />
<field name="has_medical_reasons"/>
<field name="medical_description"
widget="html"
attrs="{'invisible': [('has_medical_reasons','=', False)]}" />