Skip to content

Commit

Permalink
[FIX] qr code bug
Browse files Browse the repository at this point in the history
  • Loading branch information
felipezago committed Jun 8, 2023
1 parent 89499d5 commit 4ef54eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
34 changes: 14 additions & 20 deletions l10n_br_pos_cfe/static/src/js/ReceiptScreen/OrderFooterReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,16 @@ odoo.define("l10n_br_pos_cfe.OrderFooterReceipt", function (require) {

async _generateQRCode() {
const qrCode = document.getElementById("footer__qrcode");
new MutationObserver(this.observerCallback.bind(this)).observe(qrCode, {
attributes: true,
subtree: true,
attributeFilter: ["style"]
});

const start = Date.now();
this.observeElement(qrCode, this.dispatchEventAfterQrCodeDisplayed);

// eslint-disable-next-line
await new QRCode(document.getElementById("footer__qrcode"), {
return await new QRCode(document.getElementById("footer__qrcode"), {
text: this.getTextForQRCode(),
width: 275,
height: 275,
colorDark: "#000000",
colorLight: "#ffffff",
// eslint-disable-next-line
correctLevel: QRCode.CorrectLevel.L,
});
const end = Date.now();

console.log(`Gerar QR Code - Tempo de Execução: ${end - start} ms`);
}

getFormattedDocumentKey() {
Expand Down Expand Up @@ -102,11 +91,7 @@ odoo.define("l10n_br_pos_cfe.OrderFooterReceipt", function (require) {

async _generateQRCodeCancel() {
const qrCodeCancel = document.getElementById("footer__qrcode-cancel");
new MutationObserver(this.observerCallback.bind(this)).observe(qrCodeCancel, {
attributes: true,
subtree: true,
attributeFilter: ["style"]
});
this.observeElement(qrCodeCancel, this.dispatchEventAfterQrCodeDisplayed);

// eslint-disable-next-line
return await new QRCode(qrCodeCancel, {
Expand Down Expand Up @@ -143,11 +128,20 @@ odoo.define("l10n_br_pos_cfe.OrderFooterReceipt", function (require) {
);
}

observerCallback(mutationList, observer) {
observeElement(element, callback) {
return new MutationObserver(callback.bind(this)).observe(element, {
attributes: true,
subtree: true,
attributeFilter: ["style"]
});
}

dispatchEventAfterQrCodeDisplayed(mutationList, observer) {
const self = this;
_.each(mutationList, (mutation) => {
const currEl = mutation.target;
if (mutation.type == "attributes" &&
if (
mutation.type == "attributes" &&
currEl.tagName === "IMG" &&
currEl.style.display === "block"
) {
Expand Down
4 changes: 3 additions & 1 deletion l10n_br_pos_cfe/static/src/js/ReceiptScreen/ReceiptScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ odoo.define("l10n_br_pos_cfe.ReceiptScreen", function (require) {
}

async _printReceipt() {
console.log("🚀 ~ file: ReceiptScreen.js:33 ~ extends ~ _printReceipt ~ this.orderReceipt.el.outerHTML: ", this.orderReceipt.el.outerHTML)
console.log("🚀 ~ file: ReceiptScreen.js:45 ~ extends ~ _printReceipt ~ this.orderReceipt.el.outerHTML: ", this.orderReceipt.el.outerHTML)
console.log("🚀 ~ file: ReceiptScreen.js:46 ~ extends ~ _printReceipt ~ receipt jquery: ", $(".pos-receipt").outerHTML);
console.log("🚀 ~ file: ReceiptScreen.js:47 ~ extends ~ _printReceipt ~ user agent: ", window.navigator.userAgent);
return await ReceiptScreen.prototype._printReceipt.call(this);
}
};
Expand Down
8 changes: 1 addition & 7 deletions l10n_br_pos_cfe/static/src/js/fiscal_cfe.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,9 @@ odoo.define("l10n_br_pos_cfe.FiscalDocumentCFe", function (require) {
},

send_order_job: function (order_json) {

const start = Date.now();
const res = this.connection.rpc("/hw_proxy/enviar_cfe_sat", {
return this.connection.rpc("/hw_proxy/enviar_cfe_sat", {
json: order_json,
});
const end = Date.now();
console.log(`Enviar Cfe Sat - Tempo de Execução: ${end - start} ms`);

return res
},

cancel_order_job: function (order_json) {
Expand Down

0 comments on commit 4ef54eb

Please sign in to comment.