Skip to Content
Menu
This question has been flagged
3029 Views

In odoo11 I was able to find a way so that when I change location/start date/end date it will function the same as search in odoo, it will search and reload the list view according to the values specified on the fields provided.
(Odoo 11)

But now, in Odoo 13 I wasn't able to accomplish this anymore. It seems that web.SearchView was removed in v13.


This is how I do it in Odoo 11.

odoo.define('lend_return.filter_option'function(require){
    'use strict';

    var core = require('web.core');
    var ListController = require('web.ListController');
    var ListView = require('web.ListView');
    var SearchView = require('web.SearchView');
    var Mixins = require('web.mixins');
    var rpc = require('web.rpc');
    var _t = core._t;
    SearchView.include({
        build_search_data: function () {
            var res = this._super();
            res.domains = res.domains.concat(this.start_option || []);
            res.domains = res.domains.concat(this.end_option || []);
            res.domains = res.domains.concat(this.list_location || []);
            return res;
        },
    });

    ListController.include({
        init: function(parent,model,renderer,params){
            this._super.apply(this,arguments);
            var self = this;
            var searchView = this.getParent().searchview;
            setTimeout(()=>{
                var modelName = Object.keys(this.model.localData)[0]
                if(modelName.includes('my.model.name')){
                    $('#location').on("change"function(){
                        var value = $('#location').val();
                        searchView.list_location = [];
                        if (value == 'All'){
                            searchView.list_location = [[]];
                        }else{
                            searchView.list_location = [[['location''='value]]];
                        }
                        searchView.query.trigger('reset');
                    });
                    rpc.query({
                        model: 'my.model.name',
                        method: 'method_to_call',
                        args:[[]]
                    }).then(function (data){
                        $('#location').val(data).change();
                    });
                    $('#start').datepicker({"dateFormat" : "yy/mm/dd"}).keyup(function(e) {
                        if(e.keyCode == 8 || e.keyCode == 46) {
                            $.datepicker._clearDate(this);
                            $('#start').datepicker"show" );
                        }
                    });
                    $('#end').datepicker({"dateFormat" : "yy/mm/dd" }).keyup(function(e) {
                        if(e.keyCode == 8 || e.keyCode == 46) {
                            $.datepicker._clearDate(this);
                            $('#end').datepicker"show" );
                        }
                    });
                    $('#start').on("change"function () {
                        var start = $('#start').val();
                        var end = $('#end').val();
                        searchView.start_option = [];
                        if(start){
                            if(end){
                                if(start > end){
                                    self.do_warn('Error',_t('Start Date is after End Date'))
                                    document.getElementById('start').value = start;
                                }else{
                                    searchView.end_option = [[['end','<=',end]]];
                                    searchView.start_option = [[['start','>=',start]]];
                                }
                            }else{
                                searchView.start_option = [[['start','>=',start]]];
                            }
                        }else{
                            searchView.start_option = [[]];
                        }
                        searchView.query.trigger('reset');
                    });
                    $('#end').on("change"function () {
                        var start = $('#start').val();
                        var end = $('#end').val();
                        searchView.end_option = [];
                        if(end){
                            if(start){
                                if(end < start){
                                    self.do_warn('Error',_t('End Date is before Start Date'));
                                    document.getElementById('end').value = end;
                                }else{
                                    searchView.end_option = [[['end','<=',end]]];
                                    searchView.start_option = [[['start','>=',start]]];
                                }
                            }else{
                                searchView.end_option = [[['end','<=',end]]];
                            }
                        }else{
                            searchView.end_option = [[]];
                        }
                        searchView.query.trigger('reset');
                    });
                }
            },10);
        }
    })
})
Avatar
Discard
Related Posts Replies Views Activity
2
Sep 23
2100
1
Dec 22
1079
3
Nov 22
2881
1
Nov 22
2930
1
May 22
2649