返回Odoo中的过滤视图

问题描述 投票:0回答:2

我正在尝试通过参数过滤返回Odoo中的树视图。有人知道如何编码视图的变量my_context吗?我需要对字段应用过滤器:father_competence_id

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)],
        }

filter view odoo
2个回答
0
投票

请使用下面的代码

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)],
    }

0
投票
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)],
}
© www.soinside.com 2019 - 2024. All rights reserved.