Odoo Help


This community 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.


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 552 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--
| 6 7 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 an 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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)


Asked: 8/9/15, 1:50 AM
Seen: 552 times
Last updated: 8/10/15, 1:46 AM