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

I would like to add a line of information about each product that is added to the selected products in the Odoo POS app.

The data I would like to get comes from a few fields in a custom module. I already figured out how to add the .js, .xml and .css files to the module. However I can not figure out how to load the data from the fields in my custom module.

The Odoo documentation and tutorial on this are very vague and not clear on how to extend an existing javascript module like the POS module to your own specifications. 

I think the hardest part is the .js part so this is what I got. Anyone got any pointers for me? The module I designed is 'discount.my_module' and the field I would like to import is 'discount_price'.

odoo.define('xxxx.discount', function (require){
"use strict";
var models = require('point_of_sale.models');
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 === 'product.product'; });
partner_model.fields.push('discount_price');
console.log(String(partner_model));
return _super_posmodel.initialize.call(this, session, attributes);
},
});
});

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

If you just want to load One field from any model which is pre-loaded in POS for 'example product.product', then you can do it like this:

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

models.load_fields('product.product','wk_point_for_loyalty');

For loading a completly new model with fields:

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

models.load_models([

{

model: 'custom.model',

condition: function(self){ return true; },

fields: ['field1','field2','field3'],

domain: function(self){ return [['active','=',true]]; },

loaded: function(self,result){

if(result.length){

# do operation as you like, here setting the value in a variable

self.set('variable',result[0].field1);

}

},

}],{'after': 'product.product'});

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

is it possible to give limit in domain? just like we give search limit..

Câu trả lời hay nhất

Pieter Paulussen, can you post your complete js file? i´m having the same issue

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

Thank you @shyamkishore. The answer works for getting the data from the custom module with a few minor modifications...

Ả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 24
1603
4
thg 10 24
4014
0
thg 10 22
5278
0
thg 9 22
38
2
thg 4 21
2450