Skip to Content
Menu
This question has been flagged
4 Replies
7586 Views

Hi.

I want to inherit function "get_due" of "Models.Order".

Here is the code in original function in a file point_of_sale/static/src/js/models.js:

get_due: function(paymentline) {
if (!paymentline) {
var due = this.get_total_with_tax() - this.get_total_paid();
} else {
var due = this.get_total_with_tax();
var lines = this.paymentlines.models;
for (var i = 0; i < lines.length; i++) {
if (lines[i] === paymentline) {
break;
} else {
due -= lines[i].get_amount();
}
}
}
return round_pr(due, this.pos.currency.rounding);
},

i want to customize that function and add some code like this: 

odoo.define('pos_mi_module.mi_module', function (require) {
"use strict";

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

Models.Order = Models.Order.extend({
get_due: function (paymentline) {
if (!paymentline) {
var due = this.get_total_with_tax() - this.get_total_paid();
} else {
var due = this.get_total_with_tax();
var lines = this.paymentlines.models;
for (var i = 0; i < lines.length; i++) {
if (lines[i] === paymentline) {
break;
} else {
due -= lines[i].get_amount();
}
}
}
return round_pr(due, this.pos.currency.rounding);
},
});
})

and after updating the module when i enter the session of the POS it remains black, without showing anything, and no error appears in the browser console. Both codes of "get_due" are the same because use copy and paste. What happen with this?.

Thanks in advance

Avatar
Discard
Best Answer

POS model is actually the backbone model. it's not the same as odoo class(widget) which is used in the rest of the backend code.

For the backend class javascript prototype inheritance handle implicitly by odoo class(widget) but for the backbone model, you have to handle it manually.

here is an example of how to override the backbone model method

Avatar
Discard
Author

Ravi Gadhia, i read your answer and the difference lies in "var _super_order = models.Order.prototype;"; but in my case add the variable and the result is the same. I think that is rather used when you need to call the parent class methods just as you do with "this._super();". Please correct me if I am wrong. Thank you.

There must be console error if pos screen black after loading model. please check again your console window again

quick copy-paste your code in my editor for syntax/linting check it seems 'round_pr' is not defined.

have you imported relative asset/function?

try

var utils = require('web.utils');

var round_pr = utils.round_precision;

Author

Ravi Gadhia, thank you very much, it seems that that was my problem, "round_pr"

Best Answer
Hi Raudel, Try like below :

odoo.define('pos_mi_module.mi_module', function (require) {
"use strict";

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


var _super_order = models.Order.prototype;
Models.Order = Models.Order.extend({


initialize: function() {
_super_order.initialize.apply(this,arguments);

},

get_due: function (paymentline) {
if (!paymentline) {
var due = this.get_total_with_tax() - this.get_total_paid();
} else {
var due = this.get_total_with_tax();
var lines = this.paymentlines.models;
for (var i = 0; i < lines.length; i++) {
if (lines[i] === paymentline) {
break;
} else {
due -= lines[i].get_amount();
}
}
}
return round_pr(due, this.pos.currency.rounding);
},
});
})​
Avatar
Discard
Author

Jithin, thank you very much, but I also tried that and it didn't solve the problem. The solution was in the comment of Ravi Gadhia

Related Posts Replies Views Activity
1
May 21
2238
2
May 20
8531
1
Jan 20
4026
0
Mar 19
2486
0
Oct 18
5080