how to write events for formview inside header buttons? odoo 10

為{幸葍}努か 提交于 2019-12-12 14:32:13

问题


I have tried this code in odoo10 community but not working, what is my fault?

Or Can anyone guide me how to do it?

    openerp.module_name= function (instance) {

            var _t = instance.web._t, QWeb = instance.web.qweb;

                instance.web.FormView = instance.web.FormView.include({
                init: function() {
                        this._super.apply(this, arguments);
                        console.log("test"+this.getParent().dataset.model); 
                    },
                    events: {
                       'click #target': 'button_clicked',
                    },
                    button_clicked : function(ev) { 
                        console.log("test333555555");
                        ev.preventDefault();
                        ev.stopPropagation();
                        console.log("test 333333333333");
                    });         

                 },

            });
};

回答1:


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();
    },
});
});

Add this JS to XML

<?xml version="1.0" encoding="utf-8"?>
<odoo>
        <template id="assets" inherit_id="web.assets_backend">
          <xpath expr="." position="inside">
              <script type="text/javascript" src="/YOURMODULE/static/js/FILENAME.js"></script>
          </xpath>
        </template>
</odoo>

Add that xml in __manifest__.py

{
...
...
'data': [
        ...
        'views/above_xml_filename.xml',
    ],
....
}

I hope this will work for you.



来源:https://stackoverflow.com/questions/45350936/how-to-write-events-for-formview-inside-header-buttons-odoo-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!