Skip to Content
Menu
This question has been flagged
1 Reply
1935 Views

In a model with 2 one2many fields from the table but with a different domain:


inter_put_ids = fields.One2many(
    comodel_name='project.roadmap.inter.rel', inverse_name='roadmap_id',
    domain=[('category_id.is_put', '=', True)]
)

inter_get_ids = fields.One2many(
    comodel_name='project.roadmap.inter.rel', inverse_name='roadmap_id',

    domain=[('category_id.is_put', '=', False)]
)

Trying to populate the fields from a date:

    @api.onchange('date')
def _populate_roadmap(self):
Intervention = self.env['project.intervention']
for roadmap in self:
# Installation
roadmap.inter_put_ids = [(5, 0, 0)]
inter_ids = Intervention.search([
'&',
('date', '=', roadmap.date),
('category_id.is_put', '=', True),
])
for inter in inter_ids:
roadmap.inter_put_ids = [(0, 0, {'roadmap_id': roadmap.id, 'inter_id': inter.id})]

# Getting back
roadmap.inter_get_ids = [(5, 0, 0)]
inter_ids = Intervention.search([
'&',
('date', '=', roadmap.date),
('category_id.is_put', '=', False),
])
for inter in inter_ids:
roadmap.inter_get_ids = [(0, 0, {'roadmap_id': roadmap.id, 'inter_id': inter.id})]


I'm sure that it worked, but now when adding to roadmap.inter_get_ids, roadmap.inter_put_ids is empty by the ORM.


How the framework is supposed to handle this ? If it is expected that it cleans the first field, how am i supposed to insert then consult those values ?

Avatar
Discard
Best Answer

try roadmap.write({ 'inter_get_ids': [(0, 0, {'roadmap_id': roadmap.id, 'inter_id': inter.id})]}) OR try creating the records with .create(...) and then use roadmap.inter_get_ids = [(4, id)]

Avatar
Discard
Author

I can't use write or create when the roadmap is in new form, roadmap.id doesn't exist

Related Posts Replies Views Activity
1
Mar 21
3841
0
Jan 22
3040
1
Nov 24
1486
1
Nov 24
1195
2
Sep 24
1047