我在贷款模块中检查重复员工时遇到以下错误 " InternalError":当前事务被中止,命令被忽略直到事务块结束 以下是我的代码:
@api.multi
def _check_duplicate_employee(self):
employee_loan_ids=self.search([('state','=',"approved"),('id','!=','ids')])
loan_employee=[]
for emp_ids in self(employee_loan_ids):
loan_employee.append(emp_ids.employee_id.id)
if self.state == "approved" and self.employee_id.id in loan_employee:
return False
return True
_constraints = [
(_check_duplicate_employee, 'One of the loan of this employee is already approved ', ['employee_id']),
]
答案 0 :(得分:0)
我注意到了:
employee_loan_ids已经是记录集,因此您不需要使用self(employee_loan_ids)
for emp_ids in employee_loan_ids:
如果翻译了self.state
,您还需要翻译“已批准”。