Odoo - prevent button from closing wizard

后端 未结 6 1976
死守一世寂寞
死守一世寂寞 2020-12-29 11:54

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

6条回答
  •  情书的邮戳
    2020-12-29 12:22

    Solution 0

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

    This solution was provided here by Tadeusz Karpinski.

    Solution 1

    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',
        }
    

    Solution 2

    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(); }},                       
          ],
    });
    
    [...]
    

    Solution 3

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

    Solution 4

    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.

提交回复
热议问题