Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2932 มุมมอง

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 ?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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)]

อวตาร
ละทิ้ง
ผู้เขียน

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 21
4901
0
ม.ค. 22
4084
0
ส.ค. 25
162
1
ส.ค. 25
2117
1
ก.ค. 25
2591