from odoo import fields, models class ProjectTimesheetMatrixWizard(models.TransientModel): _name = 'project.timesheet.matrix.wiz' def _default_line_ids(self): recs = self.env['account.analytic.account'].search([]) users = self.env['account.analytic.line'].search([]).mapped('user_id') return [ (0, 0, { 'name': "{}'s task on {}".format(usr.name, rec.name), 'account_id': rec.id, 'user_id': usr.id, 'unit_amount': 0, }) if not rec.line_ids.filtered(lambda x:x.user_id == usr) else (4, rec.line_ids.filtered(lambda x:x.user_id == usr)[0].id) for rec in recs for usr in users ] line_ids = fields.Many2many('account.analytic.line', default=_default_line_ids)