Odoo - prevent button from closing wizard

后端 未结 6 1975
死守一世寂寞
死守一世寂寞 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:20

    yesterday I bumped on this same issue. I needed to show a button to do something without submitting the whole wizaard. I worked around it by not using a button at all. It's pretty simple and effective. What you need:

    1. a boolean flag in your wizard model
    2. an onchange attached to the flag (that replaces you sumbmit function)
    3. replace the button in the view w/ the flag w/ invisible="1" and a label to be styled as a button

    Here's the code:

    source_it = fields.Boolean(string='Source')
    [...]
    def action_source(self):
        # do stuff
    
    @api.onchange('source_it')
    def onchange_source_it(self):
        if self.env.context.get('sourcing_now') or not self.source_it:
            return
        self.action_source()
    [...]
    

    The trick works because when a label has for attribute is going to act like the checkbox itself, so if you click on the label you are actually switching the checkbox.

提交回复
热议问题