This question has been flagged
4 Replies
6350 Views

I want 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 a custom module, extending sale order module.But its not showing the button in saleorder.

My model is:-# -*- coding: utf-8 -*-

from odoo import models, fields, api


#Model of sale-order
class SaleOrder(models.Model):
    _inherit = 'sale.order'

    @api.multi
    def update_sales_button(self):    
        pass   

Button in my sale_filters/static/src/xml/qweb.xml is:

<?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>

My javascript is:-

odoo.define('sale_filters.sync.tree', function (require) {
"use strict";
    console.log("fgfgfgfhghghghghfgdfgfgfgfgfgfgfgfgfg")
ListView = require('web.ListView')

ListView.include({
    render_buttons: function() {

        // GET BUTTON REFERENCE
        this._super.apply(this, arguments)
        if (this.$buttons) {
            var btn = this.$buttons.find('.update_sales_button')
        }

        // PERFORM THE ACTION
        btn.on('click', this.proxy('do_new_button'))

    },
    do_new_button: function() {

        instance.web.Model('sale.order')
            .call('update_sales_button', [[]])
          
            }
})
  }); 

My view is:-

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <data>
     <template id="assets_backend" name="x_export_view assets" inherit_id="web.assets_backend">
     <xpath expr="." position="inside">
       <script type="text/javascript" src="/sale_filters/static/src/js/sale_dashboard.js">
       </script>
     </xpath>
    </template>
   </data>
</odoo>
   

Please help..

Thanks in Advance


Avatar
Discard
Author

Now I can see the button...

But my javascript is not working..

Author Best Answer

Thank You  it works...

by giving widget.modelName=='sale.order'

Avatar
Discard
Best Answer

Just remove the t-if condition from the template from the code and see, you will get the button once you remove the if condition. For checking the model name, i think widget.model is not giving the model name

Avatar
Discard