Odoo-防止按钮关闭向导 [英] Odoo - prevent button from closing wizard

查看:392
本文介绍了Odoo-防止按钮关闭向导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充当对话框的瞬态模型.在我的表单视图中,我有一个像这样的按钮:

I have a transient model that serves as a dialog. In my form view I have a button like this:

<footer states="partnerId">
   <button name="check_tax_id" string="Tovább" type="object"/>
</footer>

该按钮调用此函数(我可以确认它实际上已调用):

The button invokes this function (I can confirm it actually invokes):

@api.one
    def check_tax_id(self, context=None):
        self.state = "partnerDetails"

        return None;

我的问题是,单击此按钮后,对话框窗口立即关闭! 我在做什么错了?

My problem is that the dialog window is closed immediately once I click this button! What am I doing wrong?

推荐答案

解决方案0

@api.multi
def check_tax_id(self):
    self.ensure_one()
    self.name = "New name"
    return {
        "type": "ir.actions.do_nothing",
    }

此解决方案由Tadeusz Karpinski 此处提供.

This solution was provided here by Tadeusz Karpinski.

解决方案1 ​​

您可以返回具有相同记录ID的新表格.

You can return a new form with the same record id.

@api.multi
def check_tax_id(self):
    self.ensure_one()
    self.name = "New name"
    return {
        'context': self.env.context,
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'model_name',
        'res_id': self.id,
        'view_id': False,
        'type': 'ir.actions.act_window',
        'target': 'new',
    }

解决方案2

您可以在jQuery中创建一个小部件.这将打开向导,您可以将所需的行为手动分配给按钮.您也可以使用call函数来调用python函数:

You can create a widget in jQuery. This will open the wizard and you can assign the behaviour you want to the buttons manually. You can use the call function to call python functions as well:

[...]

new instance.web.Dialog(this, { 
    title: _t("Title"), 
    width: '95%', 
    buttons: [
          { text: _t("First button"), click: function() { self.first_button(); }}, 
          { text: _t("Second button"), click: function() { self.second_button(); }},
          { text: _t("Close"), click: function() {  dialog.close(); }},                       
      ],
});

[...]

解决方案3

当然,您也可以覆盖create方法,以避免在某些情况下创建记录

Of course you can override the create method as well to avoid the creation of the record in some cases

解决方案4

最后一个选项.创建带有状态字段的工作流.创建工作流程按钮以发送信号以更改状态.您可以使用attrs属性和状态字段显示或隐藏其余字段.但是我不知道这是否适合您的需求.

One last option. Create a workflow with a state field. Create workflow buttons in order to send signals to change the state. You can show or hide the rest of the fields using the attrs attribute and the state field. But I do not know if that would adapt to your needs.

这篇关于Odoo-防止按钮关闭向导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆