Skip to Content
Menu
This question has been flagged
3 Replies
21617 Views

I want to domain this actions by user's company but there's an error goes by.

"Uncaught Error: Failed to evaluate search criterions:"

here is my code anyway, I hope you can fix this.

Thank You!

<record id="action_account_asset_asset_forms" model="ir.actions.act_window">
<field
name="name">Assets</field>
<field
name="res_model">account.asset.asset</field>
<field
name="view_type">form</field>
<field
name="view_mode">kanban,tree,form</field>
<field
name="view_id" ref="account_asset.view_account_asset_asset_purchase_tree"/>
<field
name="domain">[('category_id.type', '=', 'purchase'), ("company_id", "=", [user.company_id.id])]</field>
<field
name="help" type="html">
<p
class="oe_view_nocontent_create">
Create assets here!
</p>
</field>
</record>
Avatar
Discard

try using single quotes

Best Answer

Soujiro,

Try this,

....
 <field name="domain">[('category_id.type', '=', 'purchase'), ('company_id', '=', user.company_id.id)]</field> ....  

I hope this will help.

Rgds,

Anil.

Avatar
Discard

Actually , user record is only available when data is created. You will still get the error "variable user is not defined"

Best Answer

In Odoo to show records that are related to Active User or Active User Company is not a big deal. First understand what we are going to do here.

Problem Statement

Let say we have a company and in that company we have different active user related to different department. And we want to display some data or records in a tree view or list view according to active user department, when some one clicks on related menu. To achieve this goal we need to create dynamic domain on action window.

Solution

To put dynamic domain on action window we need a computed filed in Odoo 8 or function field in older version of Odoo, in that computed field we need to create two method first one for computed field and second one for search.

 

 department_clo_acl_ids=fields.Char(compute="_compute_department_clo_acl_ids",search=' department_clo_acl_ids_search')
@api.one
@api.depends('department_id')
def _compute_department_clo_acl_ids(self):
print('View My Department CLO ACL')
def department_clo_acl_ids_search(self, operator, operand):
clo_acl_obj = self.env['obe.clo.acl'].search([('department_id','=',self.env.user.faculty_id.department_id.id)]).ids
return [('id','in',clo_acl_obj)]

get complete code from here: http://learnopenerp.blogspot.com/2017/11/show-records-on-treeview-that-are.html

Avatar
Discard