Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged

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)]}" />
Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
úno 19
3732
2
led 16
35308
1
srp 20
4452
1
dub 20
4994
1
zář 19
8595