Browse Source

validation phone, mobile, iban

master
root 3 years ago
parent
commit
f70715d263
1 changed files with 84 additions and 1 deletions
  1. +84
    -1
      models/partner.py

+ 84
- 1
models/partner.py View File

@ -3,6 +3,7 @@ from odoo.exceptions import UserError, ValidationError, Warning
from psycopg2 import sql, DatabaseError from psycopg2 import sql, DatabaseError
from werkzeug import utils from werkzeug import utils
import re
@ -201,4 +202,86 @@ class partner(models.Model):
def _onchange_street(self): def _onchange_street(self):
for rec in self: for rec in self:
rec.npai_count=0 rec.npai_count=0
return
return
@api.constrains('email')
def _onchange_email(self):
if self.email:
if not self.image_1920 and self._context.get('gravatar_image') and self.email:
self.image_1920 = self._get_gravatar_image(self.email)
regex = re.compile(r'([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+')
if not re.fullmatch(regex, self.email):
raise ValidationError('Invalid email')
@api.constrains('phone')
def _onchange_phone(self):
regex = re.compile(r'(^(?:(?:\+|00)33[\s.-]{0,3}(?:\(0\)[\s.-]{0,3})?|0)[1-9](?:(?:[\s.-]?\d{2}){4}|\d{2}(?:[\s.-]?\d{3}){2})$)+')
# 0123456789
# 01 23 45 67 89
# 01.23.45.67.89
# 0123 45.67.89
# 0033 123-456-789
# +33-1.23.45.67.89
# +33 - 123 456 789
# +33(0) 123 456 789
# +33 (0)123 45 67 89
# +33 (0)1 2345-6789
# +33(0) - 123456789
if not re.fullmatch(regex, self.phone):
raise ValidationError('Invalid phone')
@api.constrains('mobile')
def _onchange_mobile(self):
regex = re.compile(r'(^(?:(?:\+|00)33[\s.-]{0,3}(?:\(0\)[\s.-]{0,3})?|0)[1-9](?:(?:[\s.-]?\d{2}){4}|\d{2}(?:[\s.-]?\d{3}){2})$)+')
# 0123456789
# 01 23 45 67 89
# 01.23.45.67.89
# 0123 45.67.89
# 0033 123-456-789
# +33-1.23.45.67.89
# +33 - 123 456 789
# +33(0) 123 456 789
# +33 (0)123 45 67 89
# +33 (0)1 2345-6789
# +33(0) - 123456789
if not re.fullmatch(regex, self.mobile):
raise ValidationError('Invalid mobile')
class ResPartnerBank(models.Model):
_inherit = 'res.partner.bank'
@api.onchange('acc_number')
def _onchange_acc_number(self):
#validation IBAN
#https://www.regextester.com/115565
if self.acc_number:
regex = re.compile(r'(^(?:(?:IT|SM)\d{2}[A-Z]\d{22}|CY\d{2}[A-Z]\d{23}|NL\d{2}[A-Z]{4}\d{10}|LV\d{2}[A-Z]{4}\d{13}|(?:BG|BH|GB|IE)\d{2}[A-Z]{4}\d{14}|GI\d{2}[A-Z]{4}\d{15}|RO\d{2}[A-Z]{4}\d{16}|KW\d{2}[A-Z]{4}\d{22}|MT\d{2}[A-Z]{4}\d{23}|NO\d{13}|(?:DK|FI|GL|FO)\d{16}|MK\d{17}|(?:AT|EE|KZ|LU|XK)\d{18}|(?:BA|HR|LI|CH|CR)\d{19}|(?:GE|DE|LT|ME|RS)\d{20}|IL\d{21}|(?:AD|CZ|ES|MD|SA)\d{22}|PT\d{23}|(?:BE|IS)\d{24}|(?:FR|MR|MC)\d{25}|(?:AL|DO|LB|PL)\d{26}|(?:AZ|HU)\d{27}|(?:GR|MU)\d{28})$)+')
if not re.fullmatch(regex, self.acc_number):
raise Warning('Invalid IBAN')
@api.constrains('acc_number')
def _onchange_acc_number(self):
#validation IBAN
#https://www.regextester.com/115565
if self.acc_number:
regex = re.compile(r'(^(?:(?:IT|SM)\d{2}[A-Z]\d{22}|CY\d{2}[A-Z]\d{23}|NL\d{2}[A-Z]{4}\d{10}|LV\d{2}[A-Z]{4}\d{13}|(?:BG|BH|GB|IE)\d{2}[A-Z]{4}\d{14}|GI\d{2}[A-Z]{4}\d{15}|RO\d{2}[A-Z]{4}\d{16}|KW\d{2}[A-Z]{4}\d{22}|MT\d{2}[A-Z]{4}\d{23}|NO\d{13}|(?:DK|FI|GL|FO)\d{16}|MK\d{17}|(?:AT|EE|KZ|LU|XK)\d{18}|(?:BA|HR|LI|CH|CR)\d{19}|(?:GE|DE|LT|ME|RS)\d{20}|IL\d{21}|(?:AD|CZ|ES|MD|SA)\d{22}|PT\d{23}|(?:BE|IS)\d{24}|(?:FR|MR|MC)\d{25}|(?:AL|DO|LB|PL)\d{26}|(?:AZ|HU)\d{27}|(?:GR|MU)\d{28})$)+')
if not re.fullmatch(regex, self.acc_number):
raise Warning('Invalid IBAN')

Loading…
Cancel
Save