2

Is it possible create my own button and this button click call javascript function? Like simple onclick javascript method?

If the answer is yes, how can I do that?

I want to use "Add an item" button or create my own button that calls the same function like I click on "Add an item" button.

1 Answer 1

3

First Create button where ever you want to create with some modifications.

<button string="Click" custom="click"/>

Then create one JS file that will contain following code.

odoo.define('YOUR_MODULE.FILENAME', function (require) {
"use strict";

var form_widget = require('web.form_widgets');
var core = require('web.core');
var _t = core._t;
var QWeb = core.qweb;

form_widget.WidgetButton.include({
    on_click: function() {
         if(this.node.attrs.custom === "click"){

            // YOUR CODE

            return;
         }
         this._super();
    },
});
});

i have posed this type of question, i got this solution this answer working partially. please refer this link how to write events for formview inside header buttons? odoo 10

Sign up to request clarification or add additional context in comments.

2 Comments

I was trying your example. Create button and put ir in my tree view but get an error: TypeError: field is undefined 0.0.0.0:8069/web/content/99692-19ff2ec/… Traceback: init/this.$current<@0.0.0.0:8069/web/content/99692-19ff2ec/… dispatch@0.0.0.0:8069/web/content/98187-309e876/… add/elemData.handle@0.0.0.0:8069/web/content/98187-309e876/… I am using Odoo9. Can't find what is wrong.
I installed Point Of Sale. Tried to add button in Purchases -> after Fiscal Position. And then get another error: Odoo Server Error ..... TypeError: exec_workflow() takes exactly 4 arguments (3 given)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.