Skip to Content
Menu
This question has been flagged

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
Discard
Best Answer

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
Discard
Author

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?

Related Posts Replies Views Activity
0
Jul 17
3025
0
Aug 23
1256
1
Mar 22
5466
1
Jul 21
13837
13
May 19
21537