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

Set context depending on many2many ids to domain or filter other many2many.

In model

batch_id = fields.Many2one('ae.batch', 'Batch')
subject_ids = fields.Many2many('ae.subject', string="Subjects")
topic_ids = fields.Many2many('ae.topic', string="Topics")
subtopic_ids = fields.Many2many('ae.subtopic', string="Subtopics")

The goal is to pass context in order to filter(domain), picking a Batch filters Subjects, choose Subjects, could be one or more, to filter Topics, and filter Subtopics.

Check view:

<group col="4" name="plan_detail" String='Choose t'>
<field name="batch_id" 
    context="{'batch_id':batch_id}"/>

<field name="subject_ids" 
    domain="[('batch_id', '=', batch_id)]" 
    context="{'subject_ids': subject_ids}"/>

<field name="topic_ids" 
    domain="[('subject_id', 'in', 'subject_ids')]"
    context="{'topic_ids': topic_ids}" />

<field name="subtopic_ids" widget="many2many_checkboxes" 
    domain="[('topic_id', 'in', topic_ids)]" />

What is working, picking the Batch filters correctly all Subjects. Stucked between Subjects to Topics, I think is a context or domain problem, I've tested changing the domain manually like so:

<field name="topic_ids" 
    domain="[('subject_id', 'in', '[1, 2]')]"
    context="{'topic_ids': topic_ids}" />

And successfully gets Topic list. I guess I am wrong passing context or getting domain. 

아바타
취소
베스트 답변

Hi, 

Is the current scenario like ,you need to filter subjects based on batches and topics based on the subjects and sub topics based on topics plus subjects ,topics and sub topics are manytomany fields. If yes then i hope passing domain  via .py file could solve your issue.i have provided an example below.Hope this could help you :)


@api.onchange('subject_ids')
def onchange_subject_ids(self):
listids=[]
if self.subject_ids:
for each in self.subject_ids:
listids.append(each.id)
domain = {
'topic_ids': [('id', 'in', listids)]}
return {'domain': domain, 'value': {'topic_ids': []}}
아바타
취소
작성자 베스트 답변

I just found another way to achieve this, very simple actually.

Since the context for many2many-one2many is a recordset (little changes in bold):

<field name="batch_id" 
    context="{'batch_id': 'batch_id'}"/>

<field name="subject_ids" 
    domain="[('batch_id', '=', batch_id)]" 
    context="{'subject_ids': 'subject_ids'}"/>

<field name="topic_ids" 
    domain="[('subject_id', 'in', subject_ids[0][2])]"
    context="{'topic_ids': 'topic_ids'}" />

<field name="subtopic_ids" widget="many2many_checkboxes" 
    domain="[('topic_id', 'in', topic_ids[0][2])]" />
아바타
취소
관련 게시물 답글 화면 활동
1
11월 24
4728
3
11월 24
45079
4
9월 24
47188
0
7월 24
9043
0
1월 21
4532