python - ValueError Expected singleton , Odoo8 -
i have been working on module in odoo8 on ubuntu 14.04. have come strange issue when saving form record based on one2many fields. error says
valueerror expected singleton: hr.employee.pay.change(84, 85)
my python code below
class hr_employee_pay_change(models.model): _name='hr.employee.pay.change' hr_payroll_change_ids = fields.many2one("employee.salary.change", "employee", ondelete="cascade") @api.onchange('emp_basic', 'emp_allowance') @api.depends('emp_basic', 'emp_allowance') def _current_total(self): self.emp_current_total = self.emp_basic + self.emp_allowance @api.onchange('emp_propose_allowance', 'emp_propose_basic') @api.depends('emp_propose_allowance', 'emp_propose_basic') def _proposed_total(self): data_val={} self.emp_propose_total = self.emp_propose_basic + self.emp_propose_allowance cr=self._cr uid=self._uid ids=self._ids val=int(self.employee_name) if val: cr.execute("select max_salary,min_salary hr_job id in (select job_id hr_employee id='"+str(val)+"')") res=cr.fetchall() data_val in res: max_sal=data_val[0] min_sal=data_val[1] if not min_sal < self.emp_propose_total < max_sal: self.emp_propose_basic = 0.0 self.emp_propose_allowance = 0.0 return {'warning':{'title':'warning','message':'out of range, proposed total must in between "'+str(max_sal)+'"to"'+str(min_sal)+'"'}} else: cr.execute("select wage hr_contract employee_id=0") @api.onchange('employee_name') @api.depends('employee_name') def get_data(self): data={} cr=self._cr uid=self._uid ids=self._ids value=int(self.employee_name) if(self.employee_name): cr.execute("select wage,allowance hr_contract employee_id ='"+str(value)+"'") res=cr.fetchall() data in res: self.emp_basic=data[0] self.emp_allowance = data[1] else: cr.execute("select wage,allowance hr_contract employee_id=0") employee_name = fields.many2one('hr.employee', 'employee name', required=true ) zeo_number = fields.char(related='employee_name.zeo_number', string='zeo number', readonly=true ) emp_basic = fields.float('basic salary', compute='get_data',readonly=true, store=true ) emp_allowance = fields.float('allowance', compute='get_data',readonly=true, store=true ) emp_current_total = fields.float('totals', compute='_current_total', store=true, track_visibility='always') emp_propose_basic = fields.float('proposed basic') emp_propose_allowance = fields.float('proposed allowance') emp_propose_total = fields.float('proposed totals', compute='_proposed_total', store=true, track_visibility='always')
i unable issue . tried remove 'readonly=true' property of field , issue gets fixed need have them readonly . hopes suggestion
expected singleton:
class methods required single invoking object (single browsable record) invoke method , suppose call multiple invoking objects (browsable recordsets) method not able identify object should process, therefore raise error expected singleton.
new api decorator used define method calling pattern whether methods allows single object or multiple objects invoke method.
@api.one
this decorator loops automatically on records of recordset you. self redefined current record
note: caution: returned value put in list. not supported web client, e.g. on button action methods. in case, should use @api.multi decorate method, , call self.ensure_one() in method definition.
@api.multi
self current recordset without iteration. default behavior (multiple browsable objects). methods returns non premitive type data(list, dictionary, function) must decorated @api.multi
@api.model
this decorator convert old api calls decorated function new api signature. allows polite when migrating code. self not contain record/recordset in methods decorated decorator.
so call this
self.env['model_name'].method_name(arguments)
you should try following,
class hr_employee_pay_change(models.model): _name='hr.employee.pay.change' hr_payroll_change_ids = fields.many2one("employee.salary.change", "employee", ondelete="cascade") @api.onchange('emp_basic', 'emp_allowance') @api.depends('emp_basic', 'emp_allowance') def _current_total(self): rec in self: rec.emp_current_total = rec.emp_basic + rec.emp_allowance @api.onchange('emp_propose_allowance', 'emp_propose_basic') @api.depends('emp_propose_allowance', 'emp_propose_basic') def _proposed_total(self): rec in self: data_val={} rec.emp_propose_total = rec.emp_propose_basic + rec.emp_propose_allowance cr=self._cr uid=self._uid ids=self._ids val=int(rec.employee_name) if val: cr.execute("select max_salary,min_salary hr_job id in (select job_id hr_employee id='"+str(val)+"')") res=cr.fetchall() data_val in res: max_sal=data_val[0] min_sal=data_val[1] if not min_sal < self.emp_propose_total < max_sal: self.emp_propose_basic = 0.0 self.emp_propose_allowance = 0.0 return {'warning':{'title':'warning','message':'out of range, proposed total must in between "'+str(max_sal)+'"to"'+str(min_sal)+'"'}} else: cr.execute("select wage hr_contract employee_id=0") @api.onchange('employee_name') @api.depends('employee_name') def get_data(self): rec in self: data={} cr=self._cr uid=rec._uid ids=rec._ids value=int(rec.employee_name) if(rec.employee_name): cr.execute("select wage,allowance hr_contract employee_id ='"+str(value)+"'") res=cr.fetchall() data in res: rec.emp_basic=data[0] rec.emp_allowance = data[1] else: cr.execute("select wage,allowance hr_contract employee_id=0")
Comments
Post a Comment