简体   繁体   English

Odoo 13:代码中的 act_window 操作忽略了 search_view

[英]Odoo 13: act_window action in code ignores search_view

I've got a smart button which should open a specific view with a specific search_view.我有一个智能按钮,它应该用特定的 search_view 打开一个特定的视图。 I created an action in xml for the smart button with view_id and search_view_id:我在 xml 中为带有 view_id 和 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.现在过滤器 (search_default_...) 应该根据父 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:为此,我将智能按钮和 xml-action 更改为 function 以创建操作,以便稍后添加动态:

<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.现在视图是正确的,但 search_view 不是特定的,它是默认的 search_view。 I've debugged the function and can confirm that the id of the search view is added correctly in the returned json.我已经调试了 function 并且可以确认在返回的 json 中正确添加了搜索视图的 id。

Can anybody help me?有谁能够帮我?

I got a solution for that in my github post:我在我的 github 帖子中得到了解决方案:

https://github.com/odoo/odoo/issues/66147 https://github.com/odoo/odoo/issues/66147

'search_view_id': (self.env.ref('my_project.project_expert_position_tree_search').id, ), '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该文档说“(id,名称)对,id是要加载的特定搜索视图的数据库标识符” https://www.odoo.com/documentation/12.0/reference/actions.html#window-actions-ir-动作-动作-窗口

Thanks for that!感谢那!

Impacted versions: 13.0受影响的版本: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当前行为:使用 function 生成操作时忽略指定的 search_view

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.我有一个智能按钮,它应该用特定的 search_view 打开一个特定的视图。 I created an action in xml for the smart button with view_id and search_view_id:我在 xml 中为带有 view_id 和 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.现在过滤器 (search_default_...) 应该根据父 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:为此,我将智能按钮和 xml-action 更改为 function 以创建操作,以便稍后添加动态:

<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你可以看到: https://github.com/odoo/odoo/issues/66147

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM