[MIG] web_widget_x2many_2d_matrix_example: Migration to 12.0.

This commit is contained in:
Anand Kansagra
2018-12-31 11:33:16 +05:30
parent 22441ad62f
commit 4aafcfa5a5
13 changed files with 76 additions and 64 deletions

View File

@@ -0,0 +1,29 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class X2mMatrixDemoWiz(models.TransientModel):
_name = 'x2m.matrix.demo.wiz'
_description = 'X2Many Matrix Demo Wizard'
line_ids = fields.Many2many(
'x2m.demo.line', default=lambda self: self._default_line_ids())
def _default_line_ids(self):
recs = self.env['x2m.demo'].search([])
# same with users
users = self.env['x2m.demo.line'].search([]).mapped('user_id')
return [
(0, 0, {
'name': "{}'s task on {}".format(usr.name, rec.name),
'demo_id': rec.id,
'user_id': usr.id,
'value': 0,
})
# if the project doesn't have a task for the user, create a new one
if not rec.line_ids.filtered(lambda x: x.user_id == usr) else
# otherwise, return the task
(4, rec.line_ids.filtered(lambda x: x.user_id == usr)[0].id)
for rec in recs
for usr in users
]