简体   繁体   English

Odoo警告弹出错误

[英]Odoo warning pop-up bug

In odoo10, I wrote a @api.onchange function on change of name which return warning popup if name already in database, so As I click on save button after giving input in name field then It returning a warning popup but also form saving on background which I don't want. 在odoo10中,我写了一个@ api.onchange函数,用于更改名称,如果数据库中已经有名称,则返回警告弹出窗口,因此当我在名称字段中输入内容后单击“保存”按钮时,它会返回一个警告弹出窗口,但也会在后台保存我不要

So, what is the actual problem here? 那么,这里的实际问题是什么? Please find attached screenshot below. 请在下面找到所附的屏幕截图。 Thanks 谢谢

在此处输入图片说明

If the problem is that Odoo lets you save the record after the warning is shown (although the name already exists in the database), you have to add a SQL constraint to your model, because the warning in the onchange method does not prevent users from storing the records. 如果问题在于Odoo允许您在显示警告后保存记录(尽管名称已经存在于数据库中),则必须向模型中添加SQL约束,因为onchange方法中的警告不会阻止用户存储记录。

_sql_constraints = [
    ('name_unique', 'unique(name)',
    'There is another record with the same name stored in the database!')
]

Of course you can keep your onchange warning in order to let the user know that if they keep that name, they're getting an error when saving the record. 当然,您可以保留onchange警告,以使用户知道如果保留该名称,则在保存记录时会遇到错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM