Skip to Content
Menu
This question has been flagged

i try to filter odoo records by users allowed companies using ir.actions.act_window domain field

<record id="account.res_partner_action_supplier" model="ir.actions.act_window">

        <field name="name">Vendor Payables Report</field>

        <field name="res_model">res.partner</field>

        <field name="view_mode">list,form,kanban,graph,pivot</field>

        <!-- Show only vendors/suppliers -->

        <field name="domain">['|',

            ('supplier_rank','>',0),

            ('company_id', 'in', user.company_ids.ids)

          ]

        </field>

        <field name="context">{'search_default_supplier': 1,'res_partner_search_mode': 'supplier', 'default_is_company': True, 'default_supplier_rank': 1}</field>

        </record>

 but when use user it is returing error that says 

EvalError: Can not evaluate python expression: (['|', 
                ('supplier_rank','>',0), 
                ('company_id', 'in', user.company_ids.ids)
              ]
            )
    Error: Name 'user' is not defined
    EvalError: Can not evaluate python expression: (['|', 
                ('supplier_rank','>',0), 
                ('company_id', 'in', user.company_ids.ids)
              ]
            )
    Error: Name 'user' is not defined
        at evaluateExpr (http://127.0.0.1:8070/web/assets/69487ca/web.assets_web.min.js:3344:54)
        at _preprocessAction (http://127.0.0.1:8070/web/assets/69487ca/web.assets_web.min.js:9983:137)
        at Object.doAction (http://127.0.0.1:8070/web/assets/69487ca/web.assets_web.min.js:10076:170)
        at async Object.selectMenu (http://127.0.0.1:8070/web/assets/69487ca/web.assets_web.min.js:10276:1)

Avatar
Discard

In any case, company_ids.ids would be a list [] already, no need to wrap it in another list. Then, in your view you use uid, but you're posing an error message about using user in a domain. Where's that one coming from? Seems like there is a sentence missing before 'but [...]'...

Best Answer

Hi,

Please refer to the code below:

from odoo import models, fields, api

class ResPartner(models.Model):
_inherit = "res.partner"

allowed_company_ids = fields.Many2many(
'res.company',
compute='_compute_allowed_company_ids',
string='Allowed Companies',
store=False
)

@api.depends_context('allowed_company_ids')
def _compute_allowed_company_ids(self):
allowed_companies = self.env.companies
for rec in self:
rec.allowed_company_ids = allowed_companies

XML:

<record id="account.res_partner_action_supplier" model="ir.actions.act_window">
<field name="name">Vendor Payables Report</field>
<field name="res_model">res.partner</field>
<field name="view_mode">list,form,kanban,graph,pivot</field>
<field name="domain">['|',('supplier_rank','>',0), ('company_id', 'in', allowed_company_ids.ids)]</field>
<field name="context">
{
'search_default_supplier': 1,
'res_partner_search_mode': 'supplier',
'default_is_company': True,
'default_supplier_rank': 1
}
</field>
</record>

Hope it helps.

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 18
3945
0
Jan 17
3274
1
Aug 25
325
3
Jul 25
6953
0
Jul 25
517