I am using Odoo 16. I want to add a button in the header inside the form view, and execute JS code, instead of Python code. How can I achieve that?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilità
- Magazzino
- PoS
- Project
- MRP
La domanda è stata contrassegnata
Hi,
You need to inherit the web.FormView template and add the button in it.Then you can write a JS function for that button.
Please refer to this blog to know more.https://www.cybrosys.com/blog/how-to-add-new-button-to-all-form-view-in-odoo-16
Hope it helps
Thanks, this is something I can use for sure. I will try. However, I would really like to add it inside the header. Any suggestion?
I checked and saw the component StatusBarButtons on web/static/src/views/status_bar_buttons (which is the component rendered when we add) <head></head> in our form views. But I had no sucess trying there :(
You could do it using a custom widget. Check toaster_button
as an example:
See the js code at: odoo/addons/purchase/static/src/js/purchase_toaster_button.js
Put it inside the header or where you wanna use it:
< widget name='toaster_button' button_name="send_reminder_preview" title="Preview the reminder email by sending it to yourself." attrs="{'invisible': [('id', '=', False)]}"/ >
Don't forget to define the js in the manifest of the module
'assets': {
'web.assets_backend': [
...
'purchase/static/src/js/purchase_toaster_button.js',
...
],
},
@Axel Mendoza - Exactly what I have been looking for. Thanks. Simple and working example code. Works in 17 as well.
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!
Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!
RegistratiPost correlati | Risposte | Visualizzazioni | Attività | |
---|---|---|---|---|
|
0
gen 24
|
1084 | ||
|
1
ott 23
|
1831 | ||
|
0
set 23
|
1358 | ||
|
1
gen 25
|
3121 | ||
|
1
giu 24
|
3568 |
To do what?
I am creating a driver/interface for an IoT Device. I want to add a button in the iot.device header form view to test the device. Clicking on that button have to call JS logic (to access the device) rather than python function.