Odoo Help

0

0
1 Answer
1
Ibrahim
11-04-19 05:03

Hi, 

Your question is : can we set a dynamic domain that will filter M2M field based on Another M2O field? 

Answer : Yes you can. 

First, remove the domain from the M2M declaration. Then add a onchange function like this:

@api.onchange('contact_id')
 _onchange_contact_id(self):
    if self.contact_id:
        domain = [('project_id', 'in', self.followers_search_to_list())]
        return {'domain': {'project_ids': domain}}

Upvote if this helps. If not, you can write back for further analysis.
Regards.
4 Comments
Tabla d.o.o., Samo Arko
11-04-19 05:35

Thanks! I only needed to change 'project_id' to 'id'. And you forgot to say that I needed to add compute='_on_change_contact_id' to M2M field. Is there a way to not show any M2M records until the contact is selected? Now I get all existing projects until I select the contact.

Tabla d.o.o., Samo Arko
11-04-19 05:38

I can't click on any of the checkboxes!?

Ibrahim
11-04-19 08:00

Hi,

1- I did not forget to mention that the field should have compute attribute because simply it should not.

2- Not show M2M record until contact is selected : in onchange_contact_id, i only added the condition where contact is set. In this case, you can add 'else' then apply another domain that suits your need.

3- you can't click on any of the checkboxes because you made the field compute... compute field is readonly. Since that is not what i suggested, remove compute attribute.

but to enlighten you more, even if a field is computed, you can still add records manually by adding the attribute "inverse".

Hope this helps you.

Tabla d.o.o., Samo Arko
11-04-19 08:22

yeah I figured that about compute field out, so I removed it and it saves. But the problem that I've got now is when the record is saved and when I open it again (go to a different view and back) there are again displayed all projects. But at least the ones that were selected remain selected.

Stel een vraag
Writer
Keep Informed
1 volger(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now