I am trying to add a button in the tree view of sale order module, next to create and import buttons. That button will execute a python method.
I have created my custom module, extending sale order module and then, I have followed these steps:
Step 1: Create the button in my_module/static/src/xml/qweb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<templates 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=='sale.order'">
<button class="btn btn-sm btn-primary update_sales_button" type="button">Run my stuff</button>
</t>
</t>
</t>
</templates>
Step 2: Add the file to the qweb section in __openerp.py__ of my module:
'depends': ['sale'],
'data': [],
'qweb': ['static/src/xml/qweb.xml'],
Now, the button appears.
Step 3: Create the python method to give functionality to the button in my_module/my_python_file.py:
from openerp import api, fields, models, _
class SaleOrderExtended(models.Model):
_inherit = ['sale.order']
@api.multi
def update_sales_button(self):
...
Note: The python method has been tested outside of odoo and works fine.
How can I link this python method with the button?