Hi,
I am newbie in python and odoo. Please help me.
Below is my code:
work_type = fields.Selection([('normal', 'Normal')
,('overtime', 'Overtime'), ('holiday', 'Holiday Overtime')],'Work Type')
overtimes_hours = fields.Float(compute='onchange_overtimes', string='Overtime Hours',store=True)
@api.depends('timesheet_ids')
def onchange_overtimes(self):
for record in self:
total = 0.0
if self.timesheet_ids:
for line in self.timesheet_ids:
total += line.unit_amount
self.overtimes_hours = total
timesheet_ids is my one2many field. I added work_type as a selection field into this one2many field.
Each time i add a new record i select work_type, if the work_type = overtime. i want to call the above function.
For ex: first overtimes_hours = 0. On each addition of record (work_type = overtime). Each time value added to the existing value. After 1 week we will get the total overtime working hours seperately. But my code is not working properly.
Please correct me.
first time for loop working. Next time it shows Singleton error. I think error in for loop. Please correct me.
Updated code, please check self.overtimes_hours change into record.overtimes_hours
Hope this will helps: http://learnopenerp.blogspot.com/2020/05/show-one2many-field-records-as-radio-button-in-odoo-wizard.html