콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
3057 화면

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

관련 게시물 답글 화면 활동
1
3월 21
5039
0
1월 22
4251
3
9월 25
2921
0
8월 25
526
1
8월 25
2638