Through clicking a button the user should create a new order from given values and be directly redirected to the form view of the newly created order. Following method is called through the button:
@api.one
def method_name(self):
[...]
vals = [...]
new_order = self.env['sale.order'].create(vals)
self.write({ 'state': 'review', })
return {
'type': 'ir.actions.act_window',
'name': 'sale.view_order_form',
'res_model': 'sale.order',
'res_id': new_order.id,
'view_type': 'form',
'view_mode': 'form',
'target' : 'self',
}
Sadly nothing happens and I have no clue, what to try next. I tried to change the target to new
or current
or the name but nothing changes. Both without success.
Edit: see my comment on Carlos' answer.
To execute a method of your model from a button, you must define the button as a object
type like this in your xml view:
<button name="method_name" string="My Button" type="object"/>
Then in your model
, if you want to redirect to another view after doing something, you must return the new action:
@api.multi
def method_name(self):
.......
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'my.model',
'target': 'current',
'res_id': the_resource_id,
'type': 'ir.actions.act_window'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With