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.

29 lines
1.0 KiB

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