Odoo Help

3

0
2 Answers
2
Avatar

Sudhir Arya (ERP Harbor Consulting Services) India

--Sudhir Arya (ERP Harbor Consulting Services)--
26827
| 8 9 10
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 

LinkedIn

Blog

Stackoverflow

ERP Harbor Consulting Services

Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
Sudhir Arya (ERP Harbor Consulting Services) India
3/2/18, 12:46 AM

Hi,

You can add a button and bind it with the python method using JS.

Ex:

Create an XML (button_template.xml) file under "/static/src/xml" and add following code:

<t t-name="my_custom_button">
    <button class="btn btn-primary btn-sm o_tree_custom_button" type="button">My Button</button>
</t>

Add above file in "__manifest__.py" in qweb section:

'qweb': [   
    'static/src/xml/*.xml',
]

Now, create a JS file under "/static/src/js (button_render.js)" and register this JS in web asset:

<template id="button_render_js" inherit_id="web.assets_backend">
    <xpath expr="." position="inside">
        <script type="text/javascript" src="/my_module/static/src/js/button_render.js"/>
    </xpath>
</template>

Now, add following code in your JS file:

odoo.define('my_custom_module.my_custom_button', function (require) {
"use strict";

var core = require('web.core');
var ajax = require('web.ajax');
var ListView = require('web.ListView');
var Dialog = require('web.Dialog');
var web_client = require('web.web_client');

var _t = core._t;
var _lt = core._lt;
var QWeb = core.qweb;

ListView.include({
  render_buttons: function($node) {
  this._super($node)
  var self = this;
  if (this.$buttons && this.model == 'sale.order') {
  this.$GetIdsbutton = $(QWeb.render("my_custom_button", {'widget': this}));
  this.$GetIdsbutton.appendTo(this.$buttons);
  $(this.$buttons).find('.o_tree_custom_button').on('click', function() {
                // Following route / method will be called when button is clicked
  ajax.jsonRpc('/web/my_custom_method', 'call', {}).done(function() {
  self.reload_content()
  })
  });
  }
  },
})
});

Now, create a controller file (controllers/main.py) and add a route method using "/web/my_custom_method"

# -*- coding: utf-8 -*-
from odoo import http
from odoo.http import request

class CustomController(http.Controller):

  @http.route('/web/my_custom_method', type='http', method='POST',
  auth='user', csrf=False)
  def custom_method(self, **kw):
  # Your code goes here
        return True

Hope this will help you.

Let me know for any guidance.

Sudhir Arya
ERP Harbor Consulting Services
Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
4 Comments
Carlo Alva Peru
3/2/18, 11:18 AM

Thanks for your help. I follow all the intructions but got this error:

Uncaught Error: QWeb2: Template 'my_custom_button' not found

Sudhir Arya (ERP Harbor Consulting Services) India
3/2/18, 12:07 PM

Make sure you have added XML file in __manifest__.py

Carlo Alva Peru
3/2/18, 12:15 PM

Heres is a copy of my __manifest__.py:

{'name': 'Makuku Application',

'data': [

# 'security/ir.model.access.csv',

# 'security/makuku_access_rules.xml',

'views/makuku_head.xml',

'views/makuku_menu.xml',

'views/makuku_forms.xml',

],

'depends': ['base','web'],

'qweb': ['static/src/xml/*.xml'],

'application': True}

Sudhir Arya (ERP Harbor Consulting Services) India
3/4/18, 2:44 AM

Should be working fine as it is already working for me.

Try to remove following description from the JS file:

# Following route / method will be called when button is clicked

0
Avatar

Niyas Raphy India

--Niyas Raphy--
27056
| 7 7 11
Wayanad, Kerala, India
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

Twitter:https://twitter.com/niyasraphy
LinkedIn: https://www.linkedin.com/in/niyasraphy/
FB:https://www.facebook.com/niyasraphy123
Whatsapp : +917736136763
Happy to help :)

Niyas Raphy India
3/1/18, 10:27 PM

Hi,

You can add a new button near the Create and Import button like this,



Thanks

2 Comments
LaoThai Vietnam
12/7/18, 12:48 AM

How can you put function for this button? Please help me

LaoThai Vietnam
12/7/18, 12:48 AM

How can you put function for this button? Please help me

Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now