Skip to content

Commit

Permalink
[FIX] bug canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
felipezago committed Jun 8, 2023
1 parent 0eb9385 commit 5a9b168
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ odoo.define("l10n_br_pos_cfe.OrderFooterReceipt", function (require) {

async _generateQRCode() {
const qrCode = document.getElementById("footer__qrcode");
//this.observeElement(qrCode, this.dispatchEventAfterQrCodeDisplayed);
this.observeElement(qrCode, this.dispatchEventAfterQrCodeDisplayed);

// eslint-disable-next-line
await new QRCode(qrCode, {
return await new QRCode(qrCode, {
text: this.getTextForQRCode(),
// eslint-disable-next-line
correctLevel: QRCode.CorrectLevel.L,
useSVG: true
});

window.dispatchEvent(this.footerMountedEvent);
}

getFormattedDocumentKey() {
Expand Down Expand Up @@ -92,17 +90,15 @@ odoo.define("l10n_br_pos_cfe.OrderFooterReceipt", function (require) {

async _generateQRCodeCancel() {
const qrCodeCancel = document.getElementById("footer__qrcode-cancel");
//this.observeElement(qrCodeCancel, this.dispatchEventAfterQrCodeDisplayed);
this.observeElement(qrCodeCancel, this.dispatchEventAfterQrCodeDisplayed);

// eslint-disable-next-line
await new QRCode(qrCodeCancel, {
return await new QRCode(qrCodeCancel, {
text: this.getTextForQRCodeCancel(),
// eslint-disable-next-line
correctLevel: QRCode.CorrectLevel.L,
useSVG: true
});

window.dispatchEvent(this.footerMountedEvent);
}

getTextForQRCodeCancel() {
Expand Down
36 changes: 29 additions & 7 deletions l10n_br_pos_cfe/static/src/js/printers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,37 @@ odoo.define("l10n_br_pos_cfe.Printer", function (require) {
var Printer = require("point_of_sale.Printer").Printer;

Printer = Printer.include({
print_receipt: async function(receipt) {
if (receipt) {
this.receipt_queue.push(receipt);
}
let image, sendPrintResult;
while (this.receipt_queue.length > 0) {
receipt = this.receipt_queue.shift();
image = await this.htmlToImg(receipt);
try {
sendPrintResult = await this.send_printing_job(image);
} catch (error) {
// Error in communicating to the IoT box.
this.receipt_queue.length = 0;
return this.printResultGenerator.IoTActionError();
}
// rpc call is okay but printing failed because
// IoT box can't find a printer.
if (!sendPrintResult || sendPrintResult.result === false) {
this.receipt_queue.length = 0;
return this.printResultGenerator.IoTResultError();
}
}
return this.printResultGenerator.Successful();
},

htmlToImg: function (receipt) {
const self = this;
$('.pos-receipt-print').html(receipt);
return new Promise(function (resolve, reject) {
self.receipt = $('.pos-receipt-print>.pos-receipt');
html2canvas(self.receipt[0]).then(canvas => {
$('.pos-receipt-print').empty();
resolve(self.process_canvas(canvas));
});
this.receipt = $('.pos-receipt-print>.pos-receipt');
return html2canvas(this.receipt[0]).then(canvas => {
$('.pos-receipt-print').empty();
return this.process_canvas(canvas);
});
},
});
Expand Down

0 comments on commit 5a9b168

Please sign in to comment.