在我的自定义模块中,我添加了
application_no = fields.Char(string="Application Number")
Run Code Online (Sandbox Code Playgroud)
_sql_constraints = [
('application_no_unique',
'UNIQUE(application_no)',
"Application Number already exist.Please specify another number or make sure the application number is correct"),
Run Code Online (Sandbox Code Playgroud)
]
我使用sql约束来显示警告.
它工作正常,当我们输入重复的应用程序编号时,它会显示警告并阻止保存记录的访问权限
题
警告发生时如何保存记录?
注意
我认为SQL约束不适合这个.是这个功能的任何其他方法?
我认为它可能会帮助您使用onchange方法:
@api.onchange('your_field')
def your_onchange(self):
count=self.search_count([('your_field','=',self.your_field)])
return {
'warning': {'title': _('Warning'), 'message': _('Warning message'),},
}
Run Code Online (Sandbox Code Playgroud)
这将显示消息,您可以毫无问题地保存.我希望这对你有帮助.
| 归档时间: |
|
| 查看次数: |
540 次 |
| 最近记录: |