Tuesday, August 20, 2019

email validation in odoo

ODOO

we must make validation for the email field to be sure that the email which input by the user is an invalid email , and we can do that as bellow 

E.G .
let us say that we have email field as 

email = fields.Char(string="Email")

then we can make validation by adding the function bellow 

@api.constrains('email')
    def _validate_email(self):
        for rec in self:
            if self.email and not tools.single_email_re.match(rec.email):
                raise Warning(_("Please enter a valid email address."))
        return True

* to make this function work we must import tool and exceptions as bellow 

from odoo.exceptions import ValidationError
from odoo import api , fields, exceptions, tools, models,_

No comments:

Post a Comment

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...