how can i add a custom action (More-Button) that directly calls a method of my module?
most documentation/tutorials just call views/wizards but i want to directly call the custom python methon without any wizard.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
how can i add a custom action (More-Button) that directly calls a method of my module?
most documentation/tutorials just call views/wizards but i want to directly call the custom python methon without any wizard.
Hello Jack,
I cannot tell if you want this action to be on the action drop-down or as a button by itself so I will explain both.
To create an action in the drop-down you have to create a server action and click the "Create Contextual Action" button, it should now appear in the dropdown. You would then put the code in for your function which would be either:
model.your_function()
if your function is linked to the model and has no relation to the record whereas you would call:
record.your_function()
when there is a relation to the record. Eg when you would be using the records field to send a POST request.
For a button on the view you would create the button on the view as something like this:
<button name="your_function" type="object" string="String" class="oe_highlight"/>
Or to call the server action that you created from your button:
<button name="<id_of_server_action>" type="action" string="String" class="oe_highlight"/>
I hope this helps,
Thanks,
<record id="your_id" model="ir.actions.server">
<field name="name">Button name here</field>
<field name="model_id" ref="module_name.model_name_here"/>
<field name="binding_model_id" ref="module_name.model_name_here_where_you_want_to_bind_this_button"/>
<field name="binding_view_types">form,list</field>
<field name="state">code</field>
<field name="code">action = records.your_function_name()</field>
</record>
Hi Please refer the above code, For more information you can refer the in sale module action button (more button) "mark quatation as sent". you can check on it Cheers :)
Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!
Registrieren
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.