This question has been flagged

My JS code:


odoo.define('pos_custom.pos_custom', function (require) {
"use strict";
var core = require('web.core');
var screens = require('point_of_sale.screens');
var gui = require('point_of_sale.gui');
var models = require('point_of_sale.models')
var _super_orderline = models.Orderline.prototype;
models.Orderline = models.Orderline.extend({
_super_orderline.get_display_price.call(this);
});
});

My XML code to call this function and show data


<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="PosTicket">
<t t-jquery=".pos-right-align" t-operation="replace">
<t t-esc="orderline.get_display_price()"/>
</t>
</t>

</templates>

My t-esc will call to oderline.get_display_price function that is defined in JS code. But when i run POS, ít gave me an error like this: "Uncaught SyntaxError: Unexpected token ."

How can i do that? and what i did wrong? thanks a lot and i am very grateful to hear your solution


Avatar
Discard
Best Answer

You have some errors in the code, check this

odoo.define('pos_custom.pos_custom', function (require) {
"use strict";
var models = require('point_of_sale.models');
var _super_orderline = models.Orderline.prototype;
models.Orderline = models.Orderline.extend({
get_display_price: function () {
var price = _super_orderline.get_display_price.call(this);//old_price
return price*2;//custom price
}
});
});
Avatar
Discard
Author

When i run, it still give me the error: Uncaught TypeError: Cannot read property 'get_display_price' of undefined. How can i defined this function?

check first that the var models that you are importing is not undefined,

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

console.log(models);

Author

when i run this ( like you say ), on my console log have this: {PosModel: ƒ, load_fields: ƒ, load_models: ƒ, Product: ƒ, Orderline: ƒ, …}, I think that Oderline is defined, but the function into Orderline is not

and the var _super_orderline is defined?

Author

yes, absolutely it is defined. console log js show me that. It doesn't make sense how XML file can't call this

It seems that the css selector is matching some element outside of an orderline.

Try this

<?xml version="1.0" encoding="UTF-8"?>

<templates id="template" xml:space="preserve">

<t t-extend="PosTicket">

<t t-jquery=".receipt-orderlines > tr > td:nth-child(3)" t-operation="replace">

<td class="pos-right-align" ><span t-esc="orderline.get_display_price()"></span></td>

</t>

</t>

</templates>

Author

woa, you are my hero. you make my day perfect. Thank you so much

Author

Can I ask you something? It have a lot of field price I need to fix like this, Subtotal, total,etc... So I just dont understand this code <t t-jquery=".receipt-orderlines > tr > td:nth-child(3)", can you spend a little time to explan it for me :( thank you

Author

ah ah, I got it, thank you so much, wish you have a good day