最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to inherit or override js file in odoo? - Stack Overflow

programmeradmin1浏览0评论

I want to change a function in js file. How to do it? Is there any ways to override the function?

addons/web/static/src/js/views/form_mon.js,

i want to change the function-get_search_result: function(search_val){}

dataset.name_search(search_val, self.build_domain(), 'ilike', 160).done(function(_data) {self._search_create_popup("search", _data);}

need to change the value 160 to something else

Thanks in advance

I want to change a function in js file. How to do it? Is there any ways to override the function?

addons/web/static/src/js/views/form_mon.js,

i want to change the function-get_search_result: function(search_val){}

dataset.name_search(search_val, self.build_domain(), 'ilike', 160).done(function(_data) {self._search_create_popup("search", _data);}

need to change the value 160 to something else

Thanks in advance

Share Improve this question edited May 5, 2018 at 9:22 Jignasha Royala 1,03011 silver badges27 bronze badges asked May 5, 2018 at 6:23 HVHHVH 2471 gold badge6 silver badges15 bronze badges 2
  • Just inherit base file in your custom module and then override function. You get reference from web modules only how to inherit file. You can get reference from form_relation_widget.js After that call your function without super. Now it is overridden. – Keval Mehta Commented May 5, 2018 at 8:51
  • I have some issues in POS, could you please help? my questions are here on StackOverflow: 1.stackoverflow./questions/60280924/…, 2. stackoverflow./questions/60349247/… – GD- Ganesh Deshmukh Commented Feb 22, 2020 at 7:12
Add a ment  | 

2 Answers 2

Reset to default 3

There is a good answer/example on this question, which gives a pretty good overview. That example is actually a bit more in depth than necessary for a global JavaScript change.

If you identify the function you want to override, then it's mostly just a matter of mirroring core and making the override(s) you want. Here's an example overview of how to change the name_search JavaScript behavior:

your_module/manifest.py

...
'data': [
    ...
    'views/assets.xml',
    ...
],
...

your_module/views/assets.xml

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

your_module/static/src/js/custom.js

odoo.define('your_module.custom_feature', function(require) {
"use strict";

Class = require('web.Class');
mixins = require('web.mixins');

var DataSet = Class.extend(mixins.PropertiesMixin, {
    name_search: function (name, domain, operator, limit) {
        /* Custom code to override/extend core */
    },
});

return {
    DataSet: DataSet,
};

});

You can do it like they did in google_calendar:

odoo.define('youmodule.yourmodule', function (require) {
   "use strict";
   var CompletionFieldMixin = require('web.CompletionFieldMixin');

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

   CompletionFieldMixin.include({
       // You need to redefine the function here
});
发布评论

评论列表(0)

  1. 暂无评论