[REF] point_of_sale: get rid of useless util functions

The getFileAsText function can be replaced with the now well supported
Blob.text() function, the nextFrame function is used in precisely one
place and is needlessly complicated.

Part-of: odoo/odoo#108891
This commit is contained in:
Samuel Degueldre
2023-01-05 14:32:48 +01:00
parent 6a7459c1c0
commit ca7b48ea89
3 changed files with 3 additions and 37 deletions
@@ -1,6 +1,5 @@
/** @odoo-module */
import { getFileAsText } from "@point_of_sale/js/utils";
import { parse } from "web.field_utils";
import NumberBuffer from "@point_of_sale/js/Misc/NumberBuffer";
import PosComponent from "@point_of_sale/js/PosComponent";
@@ -124,6 +123,7 @@ class DebugWidget extends PosComponent {
var URL = window.URL || window.webkitURL;
return URL.createObjectURL(this.paidOrdersBlob);
}
// FIXME POSREF why is this two steps?
prepareUnpaidOrders() {
try {
this.unpaidOrdersBlob = this._createBlob(this.env.pos.export_unpaid_orders());
@@ -142,7 +142,7 @@ class DebugWidget extends PosComponent {
async importOrders(event) {
const file = event.target.files[0];
if (file) {
const report = this.env.pos.import_orders(await getFileAsText(file));
const report = this.env.pos.import_orders(await file.text());
await this.showPopup("OrderImportPopup", { report });
}
}
@@ -1,6 +1,5 @@
/** @odoo-module */
import { nextFrame } from "@point_of_sale/js/utils";
import PosComponent from "@point_of_sale/js/PosComponent";
import Registries from "@point_of_sale/js/Registries";
@@ -32,7 +31,7 @@ class AbstractReceiptScreen extends PosComponent {
if (confirmed) {
// We want to call the _printWeb when the popup is fully gone
// from the screen which happens after the next animation frame.
await nextFrame();
await new Promise(requestAnimationFrame);
return await this._printWeb();
}
return false;
@@ -1,37 +1,4 @@
/** @odoo-module */
export function getFileAsText(file) {
return new Promise((resolve, reject) => {
if (!file) {
reject();
} else {
const reader = new FileReader();
reader.addEventListener("load", function () {
resolve(reader.result);
});
reader.addEventListener("abort", reject);
reader.addEventListener("error", reject);
reader.readAsText(file);
}
});
}
/**
* This global variable is used by nextFrame to store the timer and
* be able to cancel it before another request for animation frame.
*/
let timer = null;
/**
* Wait for the next animation frame to finish.
*/
export const nextFrame = () => {
return new Promise((resolve) => {
cancelAnimationFrame(timer);
timer = requestAnimationFrame(() => {
resolve();
});
});
};
/**
* Creates a batched version of a callback so that all calls to it in the same