Odoo Help

0

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

By
Jesse Rye
on 8/9/15, 1:50 AM 1,001 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:

<sheet>
<group>
<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}" />
</group>
<notebook>
<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}" />
</tree>
</field>
</page>
</notebook>
</sheet>

2
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}" />
</field>

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.


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

Question tools

2 follower(s)

Stats

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