【发布时间】:2021-04-26 10:10:50
【问题描述】:
我想在字段 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")
【问题讨论】:
标签: odoo odoo-8 odoo-10 odoo-9