콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
8632 화면

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

아바타
취소
베스트 답변

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

아바타
취소
작성자

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;

작성자

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

베스트 답변
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);
},
});
})​
아바타
취소
작성자

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

관련 게시물 답글 화면 활동
1
5월 21
3068
2
5월 20
9699
1
1월 20
4952
0
3월 19
3317
0
10월 18
6065