Odoo - close button from closing the wizard

I have a transitional model that serves as a dialogue. 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 calls this function (I can confirm that it really calls):

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

My problem is that the dialog box closes right after clicking this button! What am I doing wrong?

+7
python xml odoo odoo-8
source share
7 answers

Solution 0

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

This decision was provided here by Tadeusz Karpinsky.

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

Decision 2

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

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

Decision 3

Of course, you can also override the create method to avoid creating an entry in some cases.

Decision 4

The last parameter. Create a workflow with a status field. Create workflow buttons to send alerts for status changes. You can show or hide the rest of the fields using the attrs attribute and the status field. But I do not know if this will fit your needs.

+16
source share

In my case, this code works.

 @api.multi def test(self): l = logging.getLogger() l.warn("xD") return { "type": "ir.actions.do_nothing", } 
+5
source share

The easiest way to do this is:

 @api.multi def null_action(self): return { "type": "set_scrollTop", } 

Since the type is used to call any method in the ActionManager class (javascript)

This is better than "type": "ir.actions.do_nothing" that throw an exception (this attribute does not exist)

+2
source share

Yesterday I came across the same issue. I needed to show a button to do something without sending the entire wizard. I worked around this without using a button at all. It is quite simple and effective. What you need:

  • boolean flag in your wizard model
  • flag-bound onchange (which replaces your sumbmit function)
  • replace the button in the w / flag view w / invisible="1" and the shortcut to be styled as a button

Here is 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() [...] <label for="source_it" class="pull-left btn btn-success" /> <field name="source_it" invisible="1" /> 

The trick works because when the label has the for attribute, it will act like the flag itself, so if you click on the label, you actually switch the flag.

+2
source share

Yes, you are right ... but we have no solution. Because when you click on any button of the wizard, the wizard is automatically destroyed.

But you can execute this method using the write onchange method of any field.

0
source share

on odoo 7

 def traszero(self ,cr ,uid ,ids ,context=None): data_obj = self.pool.get('stock.return.picking.line') ret_wizard = self.browse(cr, uid, ids, context=context) if ret_wizard.product_return_moves: line_ids = ret_wizard.product_return_moves.mapped('id') data_obj.write(cr, uid, line_ids, {'quantity': 0}, context=context) return {'name':"Return Shipment", 'res_model':"stock.return.picking", 'src_model':"stock.picking", 'view_mode':"form", 'target':"new", 'key2':"client_action_multi", 'multi':"True", 'res_id':ids[0], 'type': 'ir.actions.act_window', } 
0
source share

What you can do is open the open button of another wizard, with all the values ​​entered in the first wizard. This allows you to perform some function, i.e. your button. And save the state of your wizard. Therefore, the default value for the fields in your wizard should first check the context and discard it for something else.

Here is an example:

 class MyWizard(models.TransientModel): _name = 'myaddon.mywizard' def _get_default_char(self): return self._context.get('mychar',"") mychar = fields.Char(string="My Char", default=_get_default_char) @api.multi def my_button(self): # Execute Function Here # reload wizard with context return { 'view_type': 'form', 'view_mode': 'form', 'res_model': 'myaddon.mywizard', 'type': 'ir.actions.act_window', 'target': 'new', 'context': '{"mychar":'HELLO WORLD'}', } 
0
source share

All Articles