1
votes

wanna ask bout expected singleton error in odoo. even ive fixed it with @api.one, iam still confused bout the error and want to know could i fix it without @api.one ? here is my code with @api.one :

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)')

here is the traceback and iam using odoo 8:

    File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\fields.py", line 825, i
n __get__
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\models.py", line 5323,
in ensure_one
except_orm: ('ValueError', 'Expected singleton: overtime.overtime_details(2,
 3, 4)')

iam a newbie in odoo and python this is my 1st time facing this kind of error, thanks before

2
Can you provide stack trace and odoo's version?hgminh
@api.model might also work, but you still need a decorator.. to know more about decorators. refer to the following link Methods and decoratorsWalid Mashal
sorry, ive provided the traceback error. you guys can check itAdam Junior

2 Answers

5
votes

@api.one means record when @api.multi means multiple records. In case of @api.multi you should use for rec in self: only. You doesn't need to use for in case of single record, it just doesn't makes sense.

Error message says expected singleton, that means: you are using recordset instead of record, you didn't post error logs so I just can guess that you need to pop single record from search results.

Good luck

0
votes

in the following code there has been two values are coming at a time of looping, It seems like a duplicate or over riding record . so u i'll check the both the record by using the database id shown in error log.