预期的单例错误od

2024-05-14 16:00:44 发布

您现在位置:Python中文网/ 问答频道 /正文

想问问奥多的单胎失误。我甚至用@api.1,我仍然对这个错误感到困惑,想知道我是否可以排除它@api.1? 这是我的密码@api.1以下内容:

class overtime_details(models.Model):
   _name='overtime.overtime_details'

   @api.onchange('employee_id')
   @api.one
   def attd_check(self):
     #import pdb;pdb.set_trace()
     for attds in self:
        if attds.id:
            ov = 0.0
            attd = self.env['hr.attendance']
            signin = attd.search([('name','=',self.overtime_id.start_date), 
                    ('employee_id','=', self.employee_id.id), ('action','=','sign_in')])
            signout = attd.search([('name','=',self.overtime_id.end_date), 
                    ('employee_id','=',self.employee_id.id), ('action','=','sign_out')])
            if signin:
                if signout:
                    ov = self.env['overtime.overtime'].calc_overtime(self.overtime_id.start_date, self.overtime_id.end_date)
                else:
                    ov = 0.0
            else:
                ov = 0.0

            self.ovrtm = ov


   nik = fields.Char('NIK', size=250, required=True)
   overtime_id = fields.Many2one('overtime.overtime', string="Overtime", ondelete='cascade')
   job_id = fields.Many2one('hr.job', string="Position")
   employee_id = fields.Many2one('hr.employee', "Employee", required=True, select=True)
   ovrtm = fields.Float(compute='attd_check', string='Overtime Hour(s)')

以下是使用odoo 8的回溯和iam:

^{pr2}$

我是一个新手在奥多和python这是我第一次面对这种错误,谢谢之前


Tags: nameselfidtruefieldsdatestringif
2条回答

在下面的代码中,有两个值在一次循环中出现,看起来像是一个重复的或覆盖的记录。所以我将使用错误日志中显示的数据库id来检查这两个记录。在

@api.one表示记录,@api.multi表示多个记录。 如果是@api.multi,则只应使用for rec in self:。您不需要在单个记录的情况下使用for,它只是没有意义。在

错误消息显示expected singleton,这意味着:您使用的是recordset而不是record,您没有发布错误日志,所以我可以猜测您需要从搜索结果中弹出单个记录。在

祝你好运

相关问题 更多 >

    热门问题