Odoo Help

Welcome!

This community 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.

0

How to override correctly this search.js file?

By
Pascal Tremblay
on 7/13/15, 1:40 PM 1,382 views

Hello there,

We are trying to override the start function in openerp/addons/web/static/src/js/search.js.



We have this in a XML file of our custom module and it seems to work well :

        <template id="override_js_search_view" name="override_js_search_view" inherit_id="web.assets_backend" >

                <xpath expr="." position="inside">

                        <script type="text/javascript" src="/website_lapagept/static/src/js/search.js"></script>

                </xpath>

        </template>



We have this in our custom js file /website_lapagept/static/src/js/search.js :

        openerp.website_lapagept = function(instance){

                instance.web.SearchView.include ({

                    start: function() {

                        var self = this;

                        var p = this._super();

                        this.$view_manager_header = this.$el.parents(".oe_view_manager_header").first();

                        this.setup_global_completion();

                        this.query = new my.SearchQuery()

                        .on('add change reset remove', this.proxy('do_search'))

                        .on('change', this.proxy('renderChangedFacets'))

                        .on('add reset remove', this.proxy('renderFacets'));

                        if (this.options.hidden) {

                            this.$el.hide();

                        }

                        if (this.headless) {

                            this.ready.resolve();

                        } else {

                            var load_view = instance.web.fields_view_get({

                            model: this.dataset._model,

                            view_id: this.view_id,

                            view_type: 'search',

                            context: this.dataset.get_context(),

                        });

                        this.alive($.when(load_view)).then(function (r) {

                        self.fields_view_get.resolve(r);

                        return self.search_view_loaded(r);

                   }).fail(function () {

                    self.ready.reject.apply(null, arguments);

                });

            }

                                var view_manager = this.getParent();

                                while (!(view_manager instanceof instance.web.ViewManager) &&

                                view_manager && view_manager.getParent) {

                                view_manager = view_manager.getParent();

                        }

                        if (view_manager) {

                            this.view_manager = view_manager;

                            view_manager.on('switch_mode', this, function (e) {

                            self.drawer.toggle(e !== 'form');

                        });

                    }

                    return $.when(p, this.ready);

                },

            })

        };



But we get this error (we have a problem with the my variable) :

        Uncaught ReferenceError: my is not defined

            http://localhost:8070/website_lapagept/static/src/js/search.js:13


Somebody could help please?


2

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 7/13/15, 3:46 PM

As var my is defined in Odoo 8 as:

var my = instance.web.search = {}; 

Try redeclaring in your .js the var my as:

var my = instance.web.search; 


Thanks a lot for your answer. It works correctly.

Pascal Tremblay
on 7/14/15, 7:08 AM
0

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 7/14/15, 7:09 AM

The code is :

......

    openerp.website_lapagept = function(instance){

        var my = instance.web.search;

        instance.web.SearchView.include ({


......

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 7/13/15, 1:40 PM
Seen: 1382 times
Last updated: 7/14/15, 7:09 AM