odoo 通过数据库验证

问题描述

我想在字段 customer_id 和 project_product_id 一起插入并与数据库检查时进行验证,如果两者与数据库相同则显示错误

我的py代码就像

_name='crm.project'
customer_id = fields.Many2one('res.partner','Customer')
@api.multi 
@api.constrains('customer_id','project_product_id')
def _check_total_value(self):
    target_list = []
    get_customer_id = self.customer_id
    get_project_product_id = self.project_product_id
self.env.cr.execute('''
                            select * 
                            from crm_project 
                            where customer_id = %s 
                                AND project_product_id = %s
                                
    ''',(get_customer_id,get_project_product_id))
    for target in self.env.cr.dictfetchall():
        target_list.append(target)
    if target_list:
        raise Warning("data duplicate")  

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)