I want to add custom button at POS product screen which confirm order and render the related QWEB and download it as pdf file into certain folder. However when i try to click the button an error message show "TypeError: order.has_changes_to_print is not a function onClick@https://167.172.87.114/web/assets/504-1c680be/point_of_sale.assets.min.js:5345:63". enter image description here Can anyone help me what does the error mean ? And how to solve it ? Thanks
Here is my code for the custom button.
odoo.define('pos_enhancement.ConfirmOrderButton', function(require) {
'use strict';
const PosComponent = require('point_of_sale.PosComponent');
const ProductScreen = require('point_of_sale.ProductScreen');
const { useListener } = require('web.custom_hooks');
const Registries = require('point_of_sale.Registries');
class ConfirmOrderButton extends PosComponent {
constructor() {
super(...arguments);
useListener('click', this.onClick);
this._currentOrder = this.env.pos.get_order();
this._currentOrder.orderlines.on('change', this.render, this);
this.env.pos.on('change:selectedOrder', this._updateCurrentOrder, this);
}
willUnmount() {
this._currentOrder.orderlines.off('change', null, this);
this.env.pos.off('change:selectedOrder', null, this);
}
async onClick() {
const order = this.env.pos.get_order();
if (order.has_changes_to_print()) {
const isPrintSuccessful = await order.print_changes();
if (isPrintSuccessful) {
order.saveChanges();
} else {
await this.showPopup('ErrorPopup', {
title: this.env._t('Printing failed'),
body: this.env._t('Failed in printing the changes in the order'),
});
}
}
}
get addedClasses() {
if (!this._currentOrder) return {};
const changes = this._currentOrder.has_changes_to_print();
return {
highlight: changes,
};
}
_updateCurrentOrder(pos, newSelectedOrder) {
this._currentOrder.orderlines.off('change', null, this);
if (newSelectedOrder) {
this._currentOrder = newSelectedOrder;
this._currentOrder.orderlines.on('change', this.render, this);
}
}
}
ConfirmOrderButton.template = 'ConfirmOrderButton';
ProductScreen.addControlButton({
component: ConfirmOrderButton,
condition: function() {
return this.env.pos.config.iface_confirmorder;
},
});
Registries.Component.add(ConfirmOrderButton);
return ConfirmOrderButton;
});
Here is my pos.js file where i define the function
odoo.define('pos_enhancement.pos', function(require) {
"use strict";
var models = require('point_of_sale.models');
var QWeb = core.qweb;
// var _super_order = models.Order.prototype;
models.PosModel = models.PosModel.extend({
get_table_url: async function () {
var table_url = this.rpc({
model: 'restaurant.table',
method: 'get_table_url',
args: [this.table.id],
});
return table_url;
}
});
var _super_order = models.Order.prototype;
models.Order = models.Order.extend({
export_for_printing: function() {
var result = _super_order.export_for_printing.apply(this,arguments);
const codeWriter = new window.ZXing.BrowserQRCodeSvgWriter();
var url = this.qr_url || 'undefined';
let table_qr_code_svg = new XMLSerializer().serializeToString(codeWriter.write(url, 150, 150));
result.table_qr_code = "data:image/svg+xml;base64," + window.btoa(table_qr_code_svg);
return result;
},
print_changes: async function() {
let isPrintSuccessful = true;
var changes = this.computeChanges(this.iface_available_categ_ids);
if ( changes['new'].length > 0 || changes['cancelled'].length > 0){
var receipt = QWeb.render('OrderChangeReceipt',{changes:changes, widget:this});
// const result = await printers[i].print_receipt(receipt);
// if (!result.successful) {
// isPrintSuccessful = false;
// }
}
return isPrintSuccessful;
},
has_changes_to_print: function() {
var changes = this.computeChanges(this.iface_available_categ_ids);
if ( changes['new'].length > 0 || changes['cancelled'].length > 0){
return true;
}
return false;
},
});
});
I tried the same method for submit button which is provided in odoo already, doing exactly the same way but with different function code. However the function that i added did not work.