[英]Odoo TypeError: expected string or buffer
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. 然后,当我关闭错误时,我的onchange方法无法正常工作,我收到了此错误。
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 我只需要一个大写或长度在3到6之间的数字的代码
EDITED 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
代码,因为您一次仅与一条记录进行交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.