From 77c318691df230c76ee8f7b5e9a7f47c81edf9dc Mon Sep 17 00:00:00 2001 From: Samir Ladoui Date: Mon, 13 Jan 2025 08:25:57 +0100 Subject: [PATCH] [FIX] partner_custom: add email regex --- odex25_base/partner_custom/models/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/odex25_base/partner_custom/models/models.py b/odex25_base/partner_custom/models/models.py index 37b097099..e51a4e906 100644 --- a/odex25_base/partner_custom/models/models.py +++ b/odex25_base/partner_custom/models/models.py @@ -4,6 +4,7 @@ from odoo import models, fields, api, exceptions, tools, _ from datetime import datetime, date, timedelta from odoo.exceptions import Warning, ValidationError from odoo.modules.module import get_module_resource +import re class ResPartner(models.Model): _inherit = 'res.partner' @@ -55,7 +56,7 @@ class ResPartner(models.Model): @api.constrains('email') def _check_email_format(self): + email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' for record in self: - if record.email: - if '@' not in record.email or not record.email.endswith('.com'): - raise ValidationError(_("The email address must contain '@' and end with '.com'.")) \ No newline at end of file + if record.email and not re.match(email_regex, record.email): + raise ValidationError(_("Invalid email address.")) \ No newline at end of file