'Customer filter in Odoo 13 POS

I need to filter the Customer list in Odoo 13 POS customer button. I have written code in js and added it in XML file also but it's not working. The code is mentioned below. Can anybody figure out where I'm wrong?

odoo.define('customer_filter_pos.customer_filter_pos', function (require) {

var models = require('point_of_sale.models');
var rpc = require('web.rpc');
models.load_fields('res.partner','parent_id');

var _super_posmodel = models.PosModel.prototype;

models.PosModel = models.PosModel.extend({
initialize: function (session, attributes) {
var partner_model = _.find(this.models, function(model){
return model.model === 'res.partner';
});
partner_model.domain.push(['parent_id','=',false]);
return _super_posmodel.initialize.call(this, session, attributes);
},
});

models.PosModel = models.PosModel.extend({

load_new_partners: function(load_new_partners){
var self = this;
var def = new $.Deferred();
var fields = _.find(this.models,function(model){ return model.model === 'res.partner'; }).fields;
var domain = [['customer','=',true],['write_date','>',this.db.get_partner_write_date()],['parent_id','=',false]];
rpc.query({
model: 'res.partner',
method: 'search_read',
args: [domain, fields],
}, {
timeout: 3000,
shadow: true,
})
.then(function(partners){
if (self.db.add_partners(partners)) { // check if the partners we got were real updates
def.resolve();
} else {
def.reject();
}
}, function(type,err){ def.reject(); });
return def;
}
});
});


Solution 1:[1]

You can try this code.You can change domain as you wish.Thanks @kenly that is he told me and it works for me.

var _super_pos_model = models.PosModel.prototype;
var _models = models.PosModel.prototype.models;

var _domain = [['id', '<=', 3]];
// partner model is the fifth element in models (index==4)
_models[4]['domain']  = function(self){ return _domain; };

models.PosModel = models.PosModel.extend({
     prepare_new_partners_domain: function(){
        var domain = _super_pos_model.prepare_new_partners_domain.apply(this, arguments);
        domain.push(..._domain);
        console.log("domain", domain);
        return domain;
    },
});

console.log("models", models.PosModel.prototype.models);

Solution 2:[2]

This one should work for odoo 13,14 as the customer filter is called customer_rank and for the vendors it is called supplier_rank which should be a value greater than 0

var models = require('point_of_sale.models');
models.load_fields('res.partner','parent_id');

var _super_pos_model = models.PosModel.prototype;

models.PosModel = models.PosModel.extend({
    initialize: function (session, attributes) {
        var partner_model = _.find(this.models, function(model){
            return model.model === 'res.partner';
        });

    partner_model['domain']=[['customer_rank','>',0]];
    return _super_pos_model.initialize.call(this, session, attributes);
    },
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Neural
Solution 2 Mina Samy