Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
10338 Visualizações

I am trying to inherit and modify the existing js function of point_of_sale module. Here is the function i need to inherit,
models.js

exports.Orderline = Backbone.Model.extend({

set_quantity: function(quantity){

console.log('quantity',quantity);

this.order.assert_editable();

if(quantity === 'remove'){

this.order.remove_orderline(this);

return;

}else{

var quant = parseFloat(quantity) || 0;

var unit = this.get_unit();

if(unit){

if (unit.rounding) {

this.quantity = round_pr(quant, unit.rounding);

var decimals = this.pos.dp['Product Unit of Measure'];

this.quantityStr = formats.format_value(round_di(this.quantity, decimals), { type: 'float', digits: [69, decimals]});

} else {

this.quantity = round_pr(quant, 1);

this.quantityStr = this.quantity.toFixed(0);

}

}else{

this.quantity = quant;

this.quantityStr = '' + this.quantity;

}

}

this.trigger('change',this);

},

});


Here is my code,

pos_models.js

odoo.define('point_of_sale.models_inherit', function (require) {

"use strict";

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

module.include({

set_quantity: function(quantity){

console.log('initialize');

}

});

});

Now i am getting an error in console like,

`module.include is not a function`

How can i inherit this?





Avatar
Cancelar
Melhor resposta

You can follow below JS code.

odoo.define('custom_pos_module.any_name_for_this_js', function (require) {

"use strict";

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

var _super_orderline = models.Orderline.prototype;

models.Orderline = models.Orderline.extend({

_super_orderline.set_quantity.call(this, quantity);

console.log('initialize');

}

});

});

Avatar
Cancelar
Autor

Thanks Emipro, your solution worked. But still need some clarity. In another example i used `.include` to inherit a function, in your solution used `.extend`. How can i know which method i need to use next time. Could you explain?

Publicações relacionadas Respostas Visualizações Atividade
0
jul. 17
3525
0
ago. 23
2408
1
mar. 22
6372
1
jul. 21
14957
13
mai. 19
22525