I've got a smart button which should open a specific view with a specific search_view. I created an action in xml for the smart button with view_id and search_view_id:
<button class="oe_stat_button" type="action" name="%(action_expert_positions)d" icon="fa-list-ol">
<field string="Positions" name="positions_count" widget="statinfo"/>
</button>
<record id="action_expert_positions" model="ir.actions.act_window">
<field name="name">Positions</field>
<field name="res_model">expert.position</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="project_expert_position_tree"/>
<field name="domain">[("project_id", "=", active_id)]</field>
<field name="search_view_id" ref="project_expert_position_tree_search"/>
<field name="context">{'default_project_id': active_id, 'search_default_project_phase_closed': 1}</field>
</record>
This works very well. It shows the specific view and also the search view with specific filter.
Now the filter (search_default_...) should be activated dynamically depending on a field in of parent object. For this I changed the smart button and the xml-action to a function which creates the action so that I can add the dynamic later:
<button class="oe_stat_button" type="object" name="get_positions" icon="fa-list-ol">
<field string="Positions" name="positions_count" widget="statinfo"/>
</button>
def get_positions(self):
self.ensure_one()
return {
'name': 'Positions',
'res_model': 'expert.position',
'type': 'ir.actions.act_window',
'view_mode': 'tree',
'view_id': self.env.ref('my_project.project_expert_position_tree').id,
'domain': [('project_id', '=', self.id)],
'search_view_id': self.env.ref('my_project.project_expert_position_tree_search').id,
'context': "{'default_project_id': active_id, 'search_default_project_phase_closed': 1}"
}
Now the view is correct but the search_view is not the specific, it is the default search_view. I've debugged the function and can confirm that the id of the search view is added correctly in the returned json.
Can anybody help me?
I got a solution for that in my github post:
https://github.com/odoo/odoo/issues/66147
'search_view_id': (self.env.ref('my_project.project_expert_position_tree_search').id, ),
The doc says "(id, name) pair, id is the database identifier of a specific search view to load" https://www.odoo.com/documentation/12.0/reference/actions.html#window-actions-ir-actions-act-window
Thanks for that!
Impacted versions: 13.0
Steps to reproduce: see below the second code block
Current behavior: specified search_view is ignored when using the function to generate action
Expected behavior: specified search view should be used
Description:
I've got a smart button which should open a specific view with a specific search_view. I created an action in xml for the smart button with view_id and search_view_id:
<button class="oe_stat_button" type="action" name="%(action_expert_positions)d" icon="fa-list-ol">
<field string="Positions" name="positions_count" widget="statinfo"/>
</button>
<record id="action_expert_positions" model="ir.actions.act_window">
<field name="name">Positions</field>
<field name="res_model">expert.position</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="project_expert_position_tree"/>
<field name="domain">[("project_id", "=", active_id)]</field>
<field name="search_view_id" ref="project_expert_position_tree_search"/>
<field name="context">{'default_project_id': active_id, 'search_default_project_phase_closed': 1}</field>
</record>
This works very well. It shows the specific view and also the search view with a specific filter.
Now the filter (search_default_...) should be activated dynamically depending on a field in of parent object. For this I changed the smart button and the xml-action to a function which creates the action so that I can add the dynamic later:
<button class="oe_stat_button" type="object" name="get_positions" icon="fa-list-ol">
<field string="Positions" name="positions_count" widget="statinfo"/>
</button>
def get_positions(self):
self.ensure_one()
return {
'name': 'Positions',
'res_model': 'expert.position',
'type': 'ir.actions.act_window',
'view_mode': 'tree,form',
'view_ids': [self.env.ref('my_project.project_expert_position_tree').id, self.env.ref('my_project.expert_position_form').id],
'domain': [('project_id', '=', self.id)],
'search_view_id': self.env.ref('my_project.project_expert_position_tree_search').id,
'context': {'default_project_id': self.id, 'search_default_project_phase_closed': 1}
}
you can see: https://github.com/odoo/odoo/issues/66147
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.