Skip to Content
Menu
This question has been flagged
2 Replies
10387 Views

I have one many2many functional field in product.pricelist.

revision_id = fields.Many2many(compute='_get_revision', comodel_name='product.pricelist', relation='product_pricelist_revision_rel', column1='pricelist_id', column2='parent_pricelist_id', string="Revision", store=True, readonly=True, copy=False)


This compute function returns the active and inactive records of pricelist. 

I gave many2many field in tree view. So many2many field appears in tree view. 

<xpath expr="//form/sheet/div/field[@name='item_ids']" position="after">

                <notebook>

                <page string="Revision">

                <field name="revision_id">

              <tree editable="bottom">

              <field name="name" string="Revision Name" readonly="1"/>

              <field name="version_no" string="Revision Version No" readonly="1"/>

              </tree>

                </field>

                </page>

                </notebook>

In this view, only active records are visible. I need to view active and inactive records of pricelist in many2many tree view in odoo 10.

Avatar
Discard
Best Answer

Try to add context={'active_test':False} in m2m field. It is working with me in odoo 14

tax_ids = fields.Many2many('account.tax', 'setup_wizard_tax_rel',
'setup_id', 'tax_id', string='Default Taxes',
context={'active_test':False},default=default_account_tax)

Avatar
Discard

still works in Odoo 17 too, good job!

Best Answer

Hi,

by default always the filter is active = true,

You can filter active true or false from here

Or if you want to do it by code try this domain for your field 

domain=['|', ('active', '=', True), ('active', '=', False)]


Avatar
Discard
Author

Hi Mohammad,

I already tried the domain in many2many field.

<field name="revision_id">

<tree editable="bottom">

<field name="name" string="Revision Name" readonly="1" domain="['|', ('active', '=', True), ('avtive, '=', False)]"/>

<field name="version_no" string="Revision Version No" readonly="1" domain="['|', ('active', '=', True), ('avtive, '=', False)]"/>

<field name="parent_id" invisible="1" domain="['|', ('active', '=', True), ('avtive, '=', False)]"/>

</tree>

</field>

But this also not working. Active records only showed in many2many tree view.

It looks like revision_id is your many2many field. have you tried giving domain for that.

I just tested it with many2many field in res.partner(tags in py) and works fine.

Author

I tried giving domain in revision_id many2many field.

<page string="Revision">

<field name="revision_id" domain="['|', ('active', '=', True), ('avtive, '=', False)]">

<tree editable="bottom">

<field name="name" string="Revision Name" readonly="1"/>

<field name="version_no" string="Revision Version No" readonly="1"/>

<field name="parent_id" invisible="1"/>

</tree>

</field>

</page>

But its not working.

Author

How to give domain for many2many field in python file?

category_id = fields.Many2many('res.partner.category', column1='partner_id',domain=['|', ('active', '=', True), ('active', '=', False)],

column2='category_id', string='Tags', default=_default_category)

Author

Its working correctly. Thanks.