2
votes

Using Odoo 10 (fetched from GitHub commit 7413b26, branch 10.0), I try to use the environnement in a search filter domain applied to a tree view. Like this:

<filter string="Metal" domain="[('attribute_id','=', self.env['ir.config_parameter'].get_param('my_module.attrib_metal', None))]" help="metal"/>

But Odoo won't let me use self:

NameError: name 'self' is not defined


I also tried to filter my ­­­attrib_metal with Python by saving the result in a field but I don't want to store it in my database, however Odoo search requires it to be.

In my Python:

def get_my_params(self):
    attrid = self.env['ir.config_parameter'].get_param(
            'my_module.attrib_metal', None)
    if attrid:
        for rec in self:
            setattr(rec, attrib_metal, rec.attribute_id.id == int(attrid))

attrib_metal = fields.Boolean(store=False, compute="get_cr_params")

This code is part of an inhereted product.attribute.value model.

In my XML view:

<filter string="Metal" domain="[('attrib_metal', '=', 'True')]" help="metal"/>

I have tried with the store = True parameter, but this way the value is stored in the database and is only computed once, which is not what I'm looking for.

So this is not the right way of doing it.


How can one use the environnement in a <filter> domain?

1
store=False means that odoo won't store that field in dbDachi Darchiashvili

1 Answers

1
votes

The domain is being evaluated in the web client (frontend/Javascript). The web client knows nothing about self. Also, the dot notation in the filters is not supported. You will need to create a new field for this as the domains are run on the javascript side and you cannot execute code there. The new field must also be stored in the database. This pattern is used all over Odoo.

use: <field name="your_field" invisible="1" /> to bring it to your view and to keep it invisible and then

<filter string="Metal" domain="[('attribute_id','=', your_field]" help="metal"/>