1

In odoo 16 I cannot add buttons to the top of list view. I have seen several treads about this issue online - all with no solution. please help me with right direction to solve this issue.

Impacted versions:

16 - latest version from repo

Video/Screenshot link (optional):

https://monosnap.com/file/zyMHtPbDvhMmtryBeXON0dM8hnQ4WQ

Steps to reproduce:

  1. Create a new module with some models
  2. Have a desire to extend ListView.buttons with extra buttons. Let's do it!
  3. Create a file mu_module/static/src/xml/my_buttons.xml
<?xml version="1.0" encoding="UTF-8"?>
<templates>
    <t t-extend="ListView.buttons" t-name="my_button_extension.buttons">
        <t t-jquery="button.o_list_button_add" t-operation="after">
            <button class="btn btn-primary import_your_action">
                Jump1
            </button>
        </t>
    </t>
</templates>
  1. In __manifest__.py add the following block of code:
    'assets': {
        'web.assets_backend': [
            'static/src/xml/my_buttons.xml',
        ],
    },

Current behavior:

Odoo system returns an error:

UncaughtPromiseError
Uncaught Promise > QWeb2: Can't clone undefined template 'ListView.buttons' to create 'my_button_extension.buttons'
Error: QWeb2: Can't clone undefined template 'ListView.buttons' to create 'my_button_extension.buttons'
    at Object.exception (http://localhost:8069/web/assets/20-aacf356/web.assets_common.min.js:5526:7)
    at Engine.add_template (http://localhost:8069/web/assets/20-aacf356/web.assets_common.min.js:5542:361)
    at http://localhost:8069/web/assets/20-aacf356/web.assets_common.min.js:5601:97

Expected behavior:

In every tree/list view will appear button wuth text "Jump1".

1 Answers1

1

The only real difference between the enterprise module hr_expense and your approach i can see, is the file path for the assets. I took the module hr_expense because it is extending the listview buttons ;-)

In Odoo's manifest the paths start with the module's name:

    'assets': {
        'web.assets_backend': [
            'my_button_extension/static/src/xml/my_buttons.xml',
        ],
    },

Another hint: add web module as dependency to your manifest.

CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • Thank you! I am checking code of `hr_expense` now! – Marko Peips Jun 26 '23 at 13:27
  • According to the path to the XML file - I checked it. So, in my code it is like in your example. So, I fixed the code sample. Thank you! – Marko Peips Jun 26 '23 at 13:35
  • I was missing something in the code! Thank you! – Marko Peips Jun 26 '23 at 16:30
  • And what exactly? Seems my answer wasn't right. – CZoellner Jun 27 '23 at 07:12
  • 1
    I just had to carefully follow the code in `hr_expense`. I suggest everybody to have a look into this module - great code to study! Thank you @CZoellner ! – Marko Peips Jun 29 '23 at 09:47
  • A lot of "special" implementations/solutions are already solved by Odoo itself. If you find such thing, always try to look into the code, because those implementations are rarely found in the official documentation. Plus the documentation always lags behind although it has become much better over the years. – CZoellner Jun 29 '23 at 11:11
  • Thank you @CZoellner! Unfortunately I cannot vote up your suggestions due to my low ranking. Thank you very much! – Marko Peips Jun 29 '23 at 12:11