Odoo Help

2

2
5 答案
5
Lithin T 阿拉伯联合酋长国
2015/6/6 下午1:52

Here is the easy way to inherit PosModel to load new fields quick and fast

function pos_product_avialble(instance,module){ //where module=instance.point_of_sale
var models = module.PosModel.prototype.models;
for(var i=0; i<models.length; i++){
var model=models[i];
if(model.model === 'product.product'){
model.fields.push('new_field1','new_field2');
}
}
}

1
EasyPME 玻里尼西亚(法属)
2016/3/9 上午4:36

Lithin T 's answer works

In Odoo v9 it is : 

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

"use strict";

var module = require('point_of_sale.models');

var models = module.PosModel.prototype.models;

for(var i=0; i<models.length; i++){

var model=models[i];

if(model.model === 'product.product'){

model.fields.push('new_field1','new_field2');

}

}

});

1 备注
OpusVL, Peter Alabaster 英国
2017/9/12 上午9:39

This works in Odoo 10 too. Thanks

1
头像

Ivan Elizaryev 俄罗斯联邦

--Ivan Elizaryev--
805
| 4 3 9
Ufa, 俄罗斯联邦
--Ivan Elizaryev--

I tried odoo at the end of 2013. I fell in love in it and have been working with odoo as a freelancer for almost two years. In September 2015 I began operate as a Company and have 5 developers for now.

Ivan, March 2016.

Ivan Elizaryev 俄罗斯联邦
2014/9/22 上午7:04

I think, right way is extend load_server_data function and then update product list by adding new fields:

function pos_product_available(instance, module){

    var PosModelSuper = module.PosModel
    module.PosModel = module.PosModel.extend({
        load_server_data: function(){
            var self = this;
            var loaded = PosModelSuper.prototype.load_server_data.call(this);

            loaded = loaded.then(function(){
                return self.fetch(
                    'product.product',
                    ['qty_available'], //new field
                    [['sale_ok','=',true],['available_in_pos','=',true]],
                    {}
                );

            }).then(function(products){
                $.each(products, function(){
                    $.extend(self.db.get_product_by_id(this.id) || {}, this)
                });
                return $.when()
            })
            return loaded;
        },
    })
}

(function(){
    var _super = window.openerp.point_of_sale;
    window.openerp.point_of_sale = function(instance){
        _super(instance);
        var module = instance.point_of_sale;

        pos_product_available(instance, module);

    }
})()

 

From here: https://github.com/yelizariev/pos-addons/blob/8.0/pos_product_available/static/src/js/pos.js

2 注释
Harold 喀麦隆
2014/9/24 上午1:50

Thanks for your answer

Nirav Jani 印度
2015/7/2 上午10:40

Is it working properly ?

提问
Writer
标签
Keep Informed
3 关注者(s)
About This Community

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

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now