在OpenERP 7中点击按钮关闭向导

1 投票
4 回答
4913 浏览
提问于 2025-04-17 13:21

我在OpenERP 7中通过一个按钮打开了一个向导。但是当我点击向导中的计算按钮时,向导就关闭了。我其实不想在点击计算按钮时关闭向导,而是希望只有在点击向导中的关闭按钮时才关闭它。我正在使用OpenERP 7。

class test_pass_student(osv.osv_memory):
    _name = 'test.pass.student'
    _column ={  
        'pass_id': fields.many2one('pass.student', 'Passed'),
        'student_id':fields.many2one('student.student', 'Student'),
    }

test_pass_student()

def _reopen(self, res_id, model):
    return {'type': 'ir.actions.act_window',
            'view_mode': 'form',
            'view_type': 'form',
            'res_id': res_id,
            'res_model': self._name,
            'target': 'new',
            'context': {
                'default_model': model,
            },
    }

class pass_student(osv.osv_memory):
    _name = 'pass.student'

    _columns = {    
        'student_id':fields.many2one('student.student', 'Student'),
        'lines': fields.one2many('test.pass.student','pass_id', 'Passed students'),
    }

    def add_student(self, cr, uid, ids,context=None):
        lines_obj = self.pool.get('test.pass.student')
        for record in self.browse(cr,uid,ids,context):
            for line in record.student_id.scores:
                    if line.pass_score > 50:
                        lines_obj.create(cr,uid,{'pass_id': record.id,'student_id':line.student_id.id})

            return _reopen(self, record.id, record._model)

pass_student()

Shen S先选择第一个学生,检查他的分数是否超过50,如果超过了,就把他加入到一个一对多的列表中,然后再检查下一个学生,重复同样的操作。

4 个回答

0

其实不需要单独写一个方法来再次打开向导。你只需要获取对象的引用,然后用视图的ID返回它就可以了。例如:

def add_student(self, cr, uid, ids,context=None):
    model_data_obj = self.pool.get('ir.model.data')
    lines_obj = self.pool.get('test.pass.student')
    for record in self.browse(cr,uid,ids,context):
        for line in record.student_id.scores:
                if line.pass_score > 50:
                    lines_obj.create(cr,uid,{'pass_id': record.id,'student_id':line.student_id.id})
    view_rec = model_data_obj.get_object_reference(cr, uid, 'pass_student', 'add_student_form_view_id')
    view_id = view_rec and view_rec[1] or False
    return {
       'view_type': 'form',
       'view_id' : [view_id],
       'view_mode': 'form',
       'res_model': 'pass.student',
       'type': 'ir.actions.act_window',
       'target': 'new',
       'context': context
    }

希望这对你有帮助!

1

要在点击按钮时关闭向导,可以在视图表单的XML中添加以下代码:

<button string="Cancel" class="oe_link" special="cancel"/>
1

在OpenERP 6.1(以及7.0)中,向导按钮(类型为type="object")的默认行为是立即关闭向导弹出窗口。当你点击按钮时,它会调用一个方法,这个方法可以返回一个动作定义的字典,然后这个动作就会被执行。

如果你不想让向导关闭,通常是因为你有多个步骤。因为多步骤的向导通常会有不同的表单视图,所以它们的按钮方法会返回动作,打开同一个向导记录的下一个步骤的视图(如果需要再次显示,也可以是相同的视图)。

你可以在官方的附加模块源代码中找到一些例子,比如在mail.compose.message向导中,这个被email_template模块修改过的例子,它使用了类似的技巧来重新打开自己。

这个问题和另一个问题也可能包含有用的例子。

撰写回答