class log(models.Model):
_name = 'custom_timesheets.log'
_description = 'Timesheet Logs'
employee = fields.Many2one('res.users','Employee', default=lambda self: self.env.user,required=True)
name = fields.Char(string="Log",default=lambda self: fields.datetime.today().strftime('%m/%d/%Y'))
related_task = fields.Many2one('custom_timesheets.tasks',string="Task")
mark_complete = fields.Boolean(string='Mark Complete?')
related_timesheet = fields.Many2one('custom_timesheets.timesheet',string='Timesheet',readonly=True,ondelete="cascade")
hours = fields.Float()
note = fields.Text()
date = fields.Date(string="Log date",default=lambda self: fields.datetime.today())
@api.onchange('mark_complete')
def _isdone(self):
for record in self:
if record.related_task:
for task in record.related_task:
task.complete = True
class tasks(models.Model):
_name = 'custom_timesheets.tasks'
_description = 'Timesheet Tasks'
name= fields.Char(String="Name")
note = fields.Text()
employee = fields.Many2one('res.users','Assigned To', required=True)
related_logs = fields.One2many('custom_timesheets.log','related_task',string="Logs")
priority = fields.Selection(selection=[('High','High'),('Medium','Medium'),('Low','Low')],string="Priority")
complete = fields.Boolean(string="Complete?")
@api.onchange('mark_complete')
def _isdone(self):
if self.related_task:
self.env[''custom_timesheets.tasks'].sudo().browse(self.related_task.id).write({'complete': True})# Use Super Admin to update values
#self.env[''custom_timesheets.tasks'].browse(self.related_task.id).write({'complete': True})# Use Current User to update values
This was the correct solution thank you!