Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Open a view as result of button click

35 views
Skip to first unread message

Carlos Gálvez

unread,
Jun 28, 2018, 8:40:06 AM6/28/18
to tryto...@googlegroups.com
Hi all,

I would like to know if is possible to open another view when a button placed in a form view is clicked.

For example:
I'm in a form view of a model named 'foo' and through a button click i want to create an instance of another model named 'bar' and show the form view of this instance.

Would it be possible??

Thanks in advance

Sergi Almacellas Abellana

unread,
Jun 28, 2018, 8:47:11 AM6/28/18
to tryto...@googlegroups.com
El 28/06/18 a les 14:15, Carlos Gálvez ha escrit:
> Hi all,

Hi Carlos,
>
> I would like to know if is possible to open another view when a button
> placed in a form view is clicked.
>
> For example:
> I'm in a form view of a model named 'foo' and through a button click i
> want to create an instance of another model named 'bar' and show the
> form view of this instance.
>
> Would it be possible??

Yes, it is possible. You should use the button_action decorator to
returns an wizard with an StateAction from the model of the new created
instance.

You should set the res_id of the action on the wizard to the ids of the
new created instances.





--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Carlos Gálvez

unread,
Jun 29, 2018, 4:30:06 AM6/29/18
to tryto...@googlegroups.com
Hi Sergi,


2018-06-28 14:47 GMT+02:00 Sergi Almacellas Abellana 

Yes, it is possible. You should use the button_action decorator to
returns an wizard with an StateAction from the model of the new created
instance.

You should set the res_id of the action on the wizard to the ids of the
new created instances.

Finally, I did not use a "button_action" decorator to return an assistant because
I was not interested in having a wizard dirtying my code, but his suggestions showed me the way.

The way I have done it is returning on my Modelview.button an Action id that points to an act_window that open the desired view:

return Action.get_action_id(ModelData.get_id('mymodule', 'myaction'))

and adding a domain to this act_window:
<field name="domain" eval="[('myfield.id', 'in', Eval('active_ids'))]" pyson="1"/>


Yours gratefully, 

Cédric Krier

unread,
Jun 29, 2018, 4:40:05 AM6/29/18
to tryto...@googlegroups.com
On 2018-06-29 09:52, Carlos Gálvez wrote:
> 2018-06-28 14:47 GMT+02:00 Sergi Almacellas Abellana <se...@koolpi.com>:
> >
> >
> > Yes, it is possible. You should use the button_action decorator to
> > returns an wizard with an StateAction from the model of the new created
> > instance.
> >
> > You should set the res_id of the action on the wizard to the ids of the
> > new created instances.
>
>
> Finally, I did not use a "button_action" decorator to return an assistant
> because
> I was not interested in having a wizard dirtying my code, but his
> suggestions showed me the way.

button_action is not limited to wizard, it can be used for any action.

> The way I have done it is returning on my Modelview.button an Action id
> that points to an act_window that open the desired view:
>
> return Action.get_action_id(ModelData.get_id('mymodule', 'myaction'))

This would be cleaner to use the button_action decorator.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Sergi Almacellas Abellana

unread,
Jun 29, 2018, 5:36:19 AM6/29/18
to tryto...@googlegroups.com
El 29/06/18 a les 09:52, Carlos Gálvez ha escrit:
>
> The way I have done it is returning on my Modelview.button an Action id
> that points to an act_window that open the desired view:
>
> return Action.get_action_id(ModelData.get_id('mymodule', 'myaction'))
>

This is the same as button_acciont('mymodule.myaction') which is simplier.


> and adding a domain to this act_window:
>
> <field name="domain" eval="[('myfield.id', 'in',
> Eval('active_ids'))]" pyson="1"/>

Of course, if the new created records are related to the current records
a domain can be used to remove the wizard.

Just for the record if myfield is a many2one field, there is no need to
include the '.id' part and this will avoid and extra join to the target
table.

Carlos Gálvez

unread,
Jun 29, 2018, 8:40:05 AM6/29/18
to tryto...@googlegroups.com
2018-06-29 10:39 GMT+02:00 Cédric Krier <cedric...@b2ck.com>:

button_action is not limited to wizard, it can be used for any action.

This would be cleaner to use the button_action decorator.
2018-06-29 11:36 GMT+02:00 Sergi Almacellas Abellana <se...@koolpi.com>:

This is the same as button_acciont('mymodule.myaction') which is simplier.


> and adding a domain to this act_window:
> 
>     <field name="domain" eval="[('myfield.id', 'in',
>     Eval('active_ids'))]" pyson="1"/>

Of course, if the new created records are related to the current records
a domain can be used to remove the wizard.

Just for the record if myfield is a many2one field, there is no need to
include the '.id' part and this will avoid and extra join to the target
table.


You're right, i tried with a button_action and I obtained the same result with a more clean code.

Thanks to both of you!
Reply all
Reply to author
Forward
0 new messages