How to inherit or override js file in odoo?












1















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_common.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

























  • 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
    May 5 '18 at 8:51
















1















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_common.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

























  • 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
    May 5 '18 at 8:51














1












1








1








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_common.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
















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_common.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







javascript python-2.7 odoo-10






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 5 '18 at 9:22









Jignasha Royala

719720




719720










asked May 5 '18 at 6:23









HVHHVH

957




957













  • 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
    May 5 '18 at 8:51



















  • 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
    May 5 '18 at 8:51

















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
May 5 '18 at 8:51





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
May 5 '18 at 8:51












2 Answers
2






active

oldest

votes


















1














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





share|improve this answer































    1














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

    });





    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50186406%2fhow-to-inherit-or-override-js-file-in-odoo%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














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





      share|improve this answer




























        1














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





        share|improve this answer


























          1












          1








          1







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





          share|improve this answer













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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 6 '18 at 13:56









          WaKoWaKo

          8,13722442




          8,13722442

























              1














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

              });





              share|improve this answer






























                1














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

                });





                share|improve this answer




























                  1












                  1








                  1







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

                  });





                  share|improve this answer















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

                  });






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 19 '18 at 20:42









                  Community

                  11




                  11










                  answered May 6 '18 at 2:53









                  traviswtravisw

                  1,384922




                  1,384922






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50186406%2fhow-to-inherit-or-override-js-file-in-odoo%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Academy of Television Arts & Sciences

                      L'Équipe

                      1995 France bombings