I have this new field for hr holiday status model
class CodeLeaveType(models.Model):
_inherit = 'hr.holidays.status'
code = fields.Char('Código para regla salarial', required=True)
@api.one
@api.onchange('code')
def _check_code(self):
pattern = "^[A-Z0-9]{3,6}$"
if re.match(pattern, self.code) == None:
self.code = ""
return {
'warning': {'title': 'Error',
'message': 'Formato de código para regla salarial no valido, debe incluir términos alfanúmeros en mayúsculas sin espacios, longitud máxima de caracteres 6', }
}
But, when I try yo create a new holiday status get this error:
Then when I close the error my onchange method don't works normal I get this error.
I don't understand, plase help me. Maybe it's the regex?
I need a code only with uppercase or numbers with lenght between 3 and 6
EDITED
I change the regex by
class CodeLeaveType(models.Model):
_inherit = 'hr.holidays.status'
code = fields.Char('Código para regla salarial', required=True)
@api.multi
@api.onchange('code')
def _check_code(self):
if self.code:
pattern = "^[A-Z0-9]{3,6}$"
if re.match(pattern, self.code) == None:
self.code = ""
return {
'warning': {'title': 'Error',
'message': 'Formato de código no valido, debe incluir términos alfanúmeros y guion (si aplica), longitud 3 a 6 caracteres', }
}
And the method works normal !!! what is the cause for this error?
删除@api.multi
代码,因为您一次仅与一条记录进行交互。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.