【问题标题】:Return view with activated filter in Odoo在 Odoo 中使用激活的过滤器返回视图
【发布时间】:2020-03-27 23:53:04
【问题描述】:

我试图在 Odoo 中返回一个按参数过滤的树视图。有人知道如何编写视图的变量 my_context 吗? 我需要使用以下字段应用过滤器:father_competence_id

过滤器定义为:

<filter name="groupby_fathercompetence"
    context="{'group_by' : 'father_competence_id'}"
    string="Father competence" />
academic_record_lines = self.env['education.record']
for line in self:
            academic_record_lines = academic_record_lines + line.env['education.record'].search([('n_line_id', '=', line.id)])
return {
            'name': _('Academic records for {} [{}]').format(
                description, self.planification_id.teacher_id.name),
            'view_type': 'form',
            'view_mode': 'tree,form',
            'res_model': 'education.record',
            'type': 'ir.actions.act_window',
            'context': **my_context**,
            'domain': [('id', 'in', academic_record_lines.ids)],
        }

【问题讨论】:

  • 模型的搜索视图中是否已有过滤器?如果是,它的name 怎么样?
  • @CZoellner 是的,它的名字是:

标签: filter view odoo


【解决方案1】:

请使用以下代码

my_context = dict(self._context or {})
my_context.update({'':})

使用 my_context.update 您可以通过上下文添加过滤器。

return {
        'name': _('Academic records for {} [{}]').format(
            description, self.planification_id.teacher_id.name),
        'view_type': 'form',
        'view_mode': 'tree,form',
        'res_model': 'education.record',
        'type': 'ir.actions.act_window',
        'context': my_context,
        'domain': [('id', 'in', academic_record_lines.ids)],
    }

【讨论】:

  • 我尝试使用以下方法解决问题: my_context = dict(self._context or {}) my_context.update({'group_by':'father_competence_id'}) ,但错误仍然存​​在。跨度>
  • 请使用 my_context.update({'search_default_groupby_fathercompetence':1})。您应该在搜索中编写一个 groupby,如下所示
【解决方案2】:

如果您知道过滤器名称(通常由搜索 &lt;filter&gt; 条目上的属性 name 设置),您可以通过在过滤器名称前面提供 search_default_ 并作为重视像 True1 这样的真实值。

academic_record_lines = self.env['education.record'].search(
    [('n_line_id', 'in', self.ids)])
context = dict(self.env.context or {})
context['search_default_groupby_fathercompetence'] = True
return {
    # self.pla... only working with singleton!!!
    'name': _('Academic records for {} [{}]').format(
        description, self.planification_id.teacher_id.name),
    'view_type': 'form',
    'view_mode': 'tree,form',
    'res_model': 'education.record',
    'type': 'ir.actions.act_window',
    'context': context,
    'domain': [('id', 'in', academic_record_lines.ids)],
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多