Odoo Help


How can I filter a field inside a many2one_list based on the value of a many2many tag outside the many2one_list widget

Jesse Rye
on 8/9/15, 1:50 AM 1,698 views

I am trying to create a domain filter that filters the selectable attributes based on the value of a many2many tag field outside of the many2one_list widget. I want the options the user can select in the attribute_id field to be limited based on the attributes in the attribute_value_ids field. But I get an error "Uncaught Error: NameError: name 'attribute_value_ids' is not defined" when trying to select a value in the attribute_id field inside the many2one_list widget.

Part of Current view code:

<field name="active" />
<field name="name" />
<field name="description" string="Description" widget="html" class="oe_edit_only" />
<field name="attribute_value_ids" string="Attributes" widget="many2many_tags" options="{'no_create': True}" />
<page string="Inventory Mapping">
<field name="webattribute_line_ids" widget="many2one_list" context="{'show_attribute': False}" nolabel="notrue">
<tree string="Variants" editable="bottom">
<field name="attribute_id" options="{'no_create': True}" domain="[('attribute_id','in',attribute_value_ids.attribute_id)]" />
<field name="value_ids" options="{'no_create': True}" domain="[('attribute_id', '=', attribute_id)]" context="{'default_attribute_id': attribute_id}" />


Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 8/9/15, 1:31 PM

First of all, to refers to the field attribute_value_ids from the field attribute_id(of the tree definition for the field webattribute_line_ids) you should use parent.attribute_value_ids but fields of attribute_value_ids are not available, meaning that you cannot do parent.attribute_value_ids.attribute_id.

For that you need to build your domain in python re-implementing search or name_search method, for that I suggest that you need to pass some values in the context of the field attribute_id in the tree. For that you need to begin to pass the contexts values from the main form. Something like this seudo-code:

<field name="webattribute_line_ids" widget="many2one_list" context="{'show_attribute': False, 'attribute_value_ids': attribute_value_ids}" nolabel="notrue">
<field name="attribute_id" options="{'no_create': True}" context="{'attribute_value_ids': attribute_value_ids, 'special_search': True}" />

Using those values in the context you could implement your business rules for filtering those fields based on the others by re-implementing you search or name_search method.

*** Example ***

def search(self, args, offset=0, limit=None, order=None, count=False):
if self.env.context.get('split_name', False):
name = False
for item in args:
if item[0] == 'name':
name = item
if name:
name = item[2]
domain = split_name_domain(name)
if domain:
args += domain
if self.env.context.get('current_user', False):
group_id = self.env['ir.model.data'].xmlid_to_res_id('medical_install.group_medical_doctor')
group_user = self.env['res.groups'].search([('id', '=', group_id), ('users.id', '=', self.env.uid)])
if group_user:
args.extend([('partner_id', '=', self.env.user.partner_id.id)])
return super(medical_physician, self).search(args, offset=offset, limit=limit, order=order, count=count)

Alexander Starostin
On 12/7/17, 12:19 PM

Axel, your solution sounds good, but the details are still unclear. 
Does re-implemented search of the model should refer to attribute_value_ids? Is it possible to find an example of implementation somewhere in custom addons?
Have things changed in ORM 10?

No changes for v10 and no expected changes in the future, you would be able to use that way.

For an example I have updated my answer providing one


Axel Mendoza
on 12/7/17, 12:38 PM

Thanks a lot!

Alexander Starostin
on 12/7/17, 2:01 PM

Thanks me with an upvote

Axel Mendoza
on 12/7/17, 2:21 PM

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.


Odoo Training Center

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

Test it now

Question tools

3 follower(s)


Asked: 8/9/15, 1:50 AM
Seen: 1698 times
Last updated: 12/8/17, 12:40 AM