You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
949 B

  1. from odoo import fields, models
  2. class DemoWizard(models.TransientModel):
  3. _name = 'x2m.matrix.demo.wiz'
  4. line_ids = fields.Many2many(
  5. 'x2m.demo.line', default=lambda self: self._default_line_ids())
  6. def _default_line_ids(self):
  7. recs = self.env['x2m.demo'].search([])
  8. # same with users
  9. users = self.env['x2m.demo.line'].search([]).mapped('user_id')
  10. return [
  11. (0, 0, {
  12. 'name': "{}'s task on {}".format(usr.name, rec.name),
  13. 'demo_id': rec.id,
  14. 'user_id': usr.id,
  15. 'value': 0,
  16. })
  17. # if the project doesn't have a task for the user, create a new one
  18. if not rec.line_ids.filtered(lambda x: x.user_id == usr) else
  19. # otherwise, return the task
  20. (4, rec.line_ids.filtered(lambda x: x.user_id == usr)[0].id)
  21. for rec in recs
  22. for usr in users
  23. ]