python - 单击统计按钮后如何过滤与同一型号相关的特定记录

标签 python odoo

在注册.学校模型中

def action_count_student(self):
    return {
        'name': 'action',
        'type': 'ir.actions.act_window',
        'view_mode': 'tree,form,search',
        'res_model': 'registration.student',
        'res_id': self.id,
        }

registration.school 模型的 xml 文件

<div class="oe_button_box" name="button_box">
                    <button class="oe_stat_button" type="object"  name="action_count_student" icon="fa-graduation-cap" >
                        <field name="count" string="Student" widget="statinfo"/>
                    </button>
                    <button class="oe_stat_button" type="object"  name="action_count_teacher" icon="fa-teacher" >
                        <field name="count_teacher" string="Teacher" widget="statinfo"/>
                    </button>
                </div>

它显示registration.student 表中存在的学生人数。 但单击统计按钮后,它应该仅显示与该学校相关的学生数据。因为学校和学生之间是一对多的关系。但它显示了学生模型中存在的所有学生记录。怎么解决呢。有人吗?

最佳答案

添加域以过滤您的操作中的记录

 @api.multi  
 def action_count_student(self):
        self.ensure_one()
        return {
            'name': 'action',
            'type': 'ir.actions.act_window',
            'view_mode': 'tree,form', # and remove search because it appears automatically in searchable view like tree view 
            'res_model': 'registration.student',
            # id don't know the name of m2o in student registration is assumed it's school_id
            'domain': [('school_id', '=', self.id)],  
            'res_id': self.id,
            }

关于python - 单击统计按钮后如何过滤与同一型号相关的特定记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56785850/

相关文章:

python - 在不同的机器上安装带有数据库服务器的 openerp 7

python-3.x - 从复杂字典生成列表

Python 脚本,参数未传输到脚本

python - 创建一个 Cron 作业 - Linux/Python

python - openerp return中如何返回多个表单 View ?

python - 从 odoo 中备份 Odoo 数据库

python - 如何按两行排序并打印具有最高值的行

python - 在 FreeBSD 程序中加载 linux 库(Python 脚本)

python-3.x - 字典中的产品不能重复odoo

python - 如何在 python 列表中追加字段值并忽略 None 值