Skip to Content
Menu
This question has been flagged
4 Replies
1913 Views

Steps to reproduce:

  1. Sales module is installed

  2. mymodule/static/src/xml/newbutton.xml:

<?xml version="1.0" encoding="UTF-8"?>
<template id="template" xml:space="preserve">       
  <t t-extend="ListView.buttons">
    <t t-jquery="button.o_list_button_add" t-operation="after">
        <t t-if="widget.model == 'product.template'">
             <button class="btn btn-primary btn-sm" type="button">New Button</button>
        </t>
    </t>
  </t>   
</template>

  1. mymodule/manifest.py:
:
   'qweb': [
        'static/src/xml/newbutton.xml',
    ],
:
  1. Upgrade module

Current behavior:

When in Sales Order, new button is not shown. However, when the element <t t-if="widget.model == 'product.template'"> is removed, the New Button is shown in every form.

Expected behavior:
New Button should be shown only in the Sales Order form.

Avatar
Discard

how product.template comes in the sales model? sale.order is the model name of sales and sale.order.line for lines.

Next time please use a meaningful title.

Best Answer

Hi,

Try the below code, instead of  widget.model use widget.modelName

<template id="template" xml:space="preserve">       
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after">
<t t-if="widget.modelName == 'sale.order'">
<button class="btn btn-primary btn-sm" type="button">New Button</button>
</t>
</t>
</t>
</template>

Thanks

Avatar
Discard
Author Best Answer

Thanks its working.

Avatar
Discard

Then you can upvote and accept the answer :)