我正在尝试通过参数过滤返回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)],
}
请使用下面的代码
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)],
}
[如果您知道过滤器名称,该名称通常由搜索name
条目上的属性<filter>
设置,则可以通过以下操作自动激活它们:在过滤器名称的前面加上search_default_
作为值,并将其作为值真实值,例如True
或1
。
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)],
}