Help

3

How to override / extend js module in odoo 10?

I need to extend part of point_of_sale js module (/point_of_sale/static/src/js/models.js) in odoo 10 in order to force it to load more fields from res.company model.

In base variant it looks like this:

odoo.define('point_of_sale.models', function (require) {
"use strict";
...
exports.PosModel = Backbone.Model.extend({
...
models: [
    {
    model: 'res.company',
     fields: [ 'currency_id', 'email', 'website', 'company_registry', 'vat', 'name', 'phone', 'partner_id' , 'country_id', 'tax_calculation_rounding_method'],
     ids: function(self){ return [self.user.company_id[0]]; },
     loaded: function(self,companies){ self.company = companies[0]; },
    }
    ]
})
})

While I need to add fields 'logo', 'city' the array fields.
I have tried lots of variants, the best result I got was with this solution:

odoo.define('my_module.models', function(require){
"use strict";

var core = require('web.core');
var modules = require('point_of_sale.models');

var _t = core._t;
modules.PosModel.include({    
        models: [
            {
                model:  'res.company',
                fields: [ 'currency_id', 'email', 'website', 'company_registry', 'vat', 'name', 'phone', 'partner_id' , 'country_id', 'tax_calculation_rounding_method', 'logo', 'city'],
                ids:    function(self){ return [self.user.company_id[0]]; },
                loaded: function(self,companies){ self.company = companies[0]; },
            }
         ]
});
});

And everything I get for this is:


warning: Some modules could not be started
Missing dependencies:    Array [ "point_of_sale.models" ]
Non loaded modules:      Array [ "custom_receipt.models" ]
Debug:                   Object { custom_receipt.models: Object }


message in browser console. Can someone explain how to fix it, how to properly override JS in odoo 10 and why it doesn't see point_of_sale.models?

1 Comment
Avatar
Discard
Avatar
Kabeer KB
-

Did you get solution. I am facing same problem.

2 Answers
0
Avatar
juan
Best Answer

To add new field in POS modules necessary in models.js override PosModel in the parent models which we take from “point_of_sale.models”. For example:

var models = require('point_of_sale.models');
var _super_posmodel = models.PosModel.prototype;

models.PosModel = models.PosModel.extend({
    initialize: function (session, attributes) {
        // New code
        var partner_model = _.find(this.models, function(model){
            return model.model === 'product.product';
        });
        partner_model.fields.push('qty_available');

        // Inheritance
        return _super_posmodel.initialize.call(this, session, attributes);
    },
});


Ref: http://odoo-development.readthedocs.io/en/latest/dev/pos/add_field.html

Avatar
Discard
0
Avatar
Mark DC
Best Answer

I am also facing this exact same problem. Have you found anything? I've tried many different ways but so far I haven't struck gold.

Avatar
Discard