Reputation: 769
Is there a way to call a python function (server action) to a view being opened. So when I click a menuitem not only a tree view opens (window action) but also a python function executes (server action).
Maybe something like an onload() function? Or a server action from within the tree view?
Thanks
Upvotes: 1
Views: 2730
Reputation: 307
There is one way to make it happen. Just add that functional field in tree view and make it invisible So it will be also called in tree view
Upvotes: 3
Reputation: 836
you can, for example do it from an action.server, i will give you an example that i used to open a wizard from a transient model.
<record id="action_current_account_conciliate" model="ir.actions.server">
<field name="name">Conciliate</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="l10n_ar_current_account.model_current_account"/>
<field name="code">
if obj.raise_imputation_wizard():
action = {
"type": "ir.actions.act_window",
"res_model": 'current.account.imputation.wizard',
"view_mode": "form",
"target": "new",
"res_id": obj.wizard_id,
}
</field>
</record>
with the field code you can write python code. The action was the return of the wizard (you can changue that view_mode for tree and without target new), depending on from where you want to open the tree view.
Hope it helps.
Upvotes: 0