Hello there,
The new api is great. I become better each day with it.
Here, I have a field to_invoice_hours who is computed an stored each time the timesheet_ids or timesheet_ids.unit_amount fields (in a task) are changed. It works well when we edit a task and we a timesheet line.
But, if the timesheet is changed directly in the account.analytic.line model, in the menu Timesheet, the field is not recomputed...
How to recompute the field to_invoice_hours no matter where is modified the account.analytic.line???
I hope you understand my question.
THanks to help.
class Task(models.Model):
_inherit = "project.task"
@api.depends('timesheet_ids','timesheet_ids.unit_amount')
def _to_invoice_hours_get(self):
#_logger.error("_to_invoice_hours_get BEGIN")
hours = 0
for task in self.browse(self.ids):
analytic_line_ids = self.env['account.analytic.line'].search([('task_id', 'in', [task.id]), ('to_invoice', '=', True)])
for record in analytic_line_ids:
hours = hours + record.unit_amount
self.to_invoice_hours = hours
to_invoice_hours = fields.Float(compute='_to_invoice_hours_get', string='Hours To Invoice', store=True, default=0)