【问题标题】:Closing Wizard on button click in OpenERP 7在 OpenERP 7 中单击按钮时关闭向导
【发布时间】:2023-03-18 17:18:01
【问题描述】:

我从 OpenERP 7 中的按钮打开向导。但是当单击向导的按钮 Compute 时,我的向导关闭了,但我不想在单击 Compute 当点击向导的按钮关闭时,而不是我的向导关闭。 我正在使用 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()

沉S选择第一个学生检查,如果他/她的分数大于50则添加one2many,然后再次检查另一个学生,同样的事情再次重复。

【问题讨论】:

  • 感谢您更新问题,但您的问题仍然不是很清楚。您能否在问题中清楚地提及您看到此代码的结果以及您的预期?到目前为止,您的代码看起来还不错。您可能不需要_reopen 中的contextdefault_model 部分(邮件撰写向导需要,但这里没有),但它不会引起问题。也许您可以显示您正在使用的 XML 视图的来源,并在出现问题时显示更大的日志摘录(这比仅显示错误消息要好)。
  • 我认为这个问题的标题应该是“NOT Closing Wizard on button click in openerp 7”,因为这是你想要的。

标签: python openerp odoo


【解决方案1】:

自 OpenERP 6.1(因此在 7.0 中也是如此)的向导按钮(带有type="object)的默认行为是立即关闭向导弹出窗口。按钮调用的方法可以返回一个将被执行的动作定义字典。 当您不想关闭向导时,通常是因为您有几个步骤。由于多步骤向导通常具有不同的表单视图,它们的按钮方法只是返回操作以使用下一步的视图打开相同的向导记录(如果需要再次显示,也可以是相同的视图)。

您可以在官方插件源代码中找到示例,例如在mail.compose.message 向导modified by the email_template module 中,它使用类似的技巧重新打开自身。

questionother one 也可能包含有用的示例。

【讨论】:

  • 感谢您宝贵的回复 odony。但是当我做同样的技巧时,它给了我错误弹出窗口服务器遇到内部错误并且无法完成您的请求。要么服务器超载,要么应用程序出错 并且在终端 **TypeError: ------- is not JSON serializable **
  • @user1576199:此时你应该编辑你的问题并准确解释你做了什么(包括你写的代码),否则很难帮助你;-)
  • 我编辑了这个问题。希望这会对你有所帮助,并为我糟糕的英语和解释感到抱歉:(
【解决方案2】:

要关闭按钮上的向导,请单击在视图表单 xml 上添加此代码:

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

【讨论】:

    【解决方案3】:

    无需编写单独的方法来再次打开向导。您可以只获取对象引用并将其与视图 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
        }
    

    希望对你有帮助!

    【讨论】:

    • 但是当我按照你说的做时,向导上的数据就会丢失。我不想丢失当前向导的数据。
    【解决方案4】:

    我在向导中回复自己,如果我放置按钮类型对象而不是按钮类型工作流,​​并且那里触发 wf 工作(不关闭),但这是正确的路径吗?

    如果有人需要,这是我的对象按钮事件代码(用于我的picking.import.wizard 向导):

    def signal_import_load_2(self, cr, uid, ids, context=None):
        import netsvc
    
        wf_service = netsvc.LocalService("workflow")
        wf_service.trg_validate(uid, 'picking.import.wizard', ids[0], 'signal_import_load', cr)
    
        view_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','picking.import.wizard'), ('name','=','Wizard import picking from CSV')])
    
        return {
             'type': 'ir.actions.act_window',
             'name': "Import",
             'res_model': 'picking.import.wizard',
             'res_id': ids[0],
             'view_type': 'form',
             'view_mode': 'form',
             'view_id': view_id,
             'target': 'new',
             'nodestroy': True,
               }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 1970-01-01
      相关资源
      最近更新 更多