p.ry
p.ry

Reputation: 489

Filter inherited model field odoo

I am creating a custom module in which i have a many2one field that has the entries from res.partner with supplier= True. My field,

seller = fields.Many2one('res.partner', string="Select Seller")

Read that i can do this in my xml file and tried,

 <data>

          <record id="test_menu_action" model="ir.actions.act_window">
            <field name="name">Tests</field>
            <field name="res_model">tests.alltests</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[('supplier','=',True)]</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">Create The First Test
                </p>
            </field>
        </record>





        <menuitem id="quality_main_menu"
                name="Quality"/>
        <menuitem id="test_create" parent="quality_main_menu" name="Test" action="test_menu_action"/>

    </data>

which gave me the following error,

Odoo Server Error ........
ValueError: Invalid field 'supplier' in leaf "<osv.ExtendedLeaf: ('supplier', '=', True) on tests_alltests (ctx: )

How do i do it correctly?

I am using odoo V12 community edition.

Upvotes: 1

Views: 684

Answers (1)

Charif DZ
Charif DZ

Reputation: 14721

First of all you don't need to do that in the action, instead you should do this in the field it self:

  1. If the domain must be always applied best thing you do is put it in the field declaration so when ever you use it in any view the domain is automatically applied.
     seller = fields.Many2one('res.partner', 
                        string="Select Seller",
                        domain="[('supplier','=',True)]")
  1. If the domain is not always applied then add it the XML view when ever you need it
    <field name="seller" domain="[('supplier','=',True)]"/>

And for the domain that you used in the action is for another situation for example if you want to create a menu for res.partner and you want the users to see only supplier, you can add the domain to action this way no matter what the user do with the search view this domain is always added to the chosen filter.

Upvotes: 2

Related Questions