Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
14309 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ

Did you get solution. I am facing same problem.

Câu trả lời hay nhất
models.load_fields('res.company', ['logo', 'city']);


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 21
3493
1
thg 6 20
3684
2
thg 7 17
4505
0
thg 5 24
2004
1
thg 8 23
11145