odoo form视图点击按钮打开弹出视图

# 跳转到弹出的视图
    def jump_up_view(self, name, view_mode, model, module,
                     act_window, type, target, view_name):
        """
        视图跳转(弹框)
        name:自定义名称
        view_mode:视图类型(tree,form,或者其他)
        model:模型名
        module:模块名(包名)
        act_window:action id,就是指定tree,form视图那个action
        type:'ir.actions.act_window'
        target:打开视图的方式:new打开弹窗,form跳转,current新页面
        view_name:新的视图id
        """
        action = {
            'name': _(name),
            'view_mode': view_mode,
            'res_model': model,
            'type': type,
            'target': target,
            'act_window_id': self.env.ref('{}.{}'.format(module, act_window)).id,
            'view_id': self.env.ref('{}.{}'.format(module, view_name)).id,
            'res_id': self.id,
        }
        return action

    # 跳转视图
    def add_student(self):
        action = self.jump_up_view("添加学生", 'form', 'hw.class', 'hw_student',
                                   'action_add_student', 'ir.actions.act_window',
                                   'new', 'view_class_add_student_form')
        if self.class_student_ids.exists():
            student_list = self.class_student_ids.read(['student_id'])
            student_list = [item['student_id'][0] for item in student_list]
            self.student_ids = [(6, 0, student_list)]
        return action

    def button_true(self):
        # 添加学生
        for student_item in self.student_ids:
            # 查询学生是否被添加
            class_student_id = self.env['hw.class.student'].sudo().search([('student_id', '=', student_item.id), ('class_id', '=', self.id)])
            if class_student_id.exists():
                continue
            else:
                # 创建学生和班级的关联
                self.env['hw.class.student'].sudo().create({
                    'class_id': self.id,
                    'student_id': student_item.id,
                })
        self.student_ids = None

        添加学生
        hw.class
        
        
            
添加学生 hw.class form

你可能感兴趣的:(odoo,python)