[REF] pos*: simplify receipt printing
pos*: l10n_co_pos, l10n_fr_pos_cert, l10n_gcc_pos,
l10n_in_pos, l10n_sa_pos, point_of_sale,
pos_epson_printer, pos_loyalty, pos_mercury,
pos_online_payment, pos_restaurant, pos_sale
There is a need to print pos receipts in new environments,
such as the kiosk. In this commit we simplify the steps to
generate the receipt data and introduce a portable mechanism
for printing.
Changes:
- removed the `getOrderReceiptEnv` method; this method
was returning a lot of data that the receipt was not
actually using; we now simply use the data from
`Order.export_for_printing`. This means that it will be much
easier to recreate this data in other environments, such
as in the kiosk.
- removed the error prone `generate_wrapped_product_name` method.
It's aim was to split the orderline name, but this task is much
better accomplished by declarative css.
- removed the `Orderline.export_for_printing` method; instead,
we simply use the existing `Orderline.getDisplayData`;
- removed the `AbstractReceiptScreen` component and replaced
it's functionality with the new `printer` service;
- using this service means that we were free to remove
the `pos-receipt-print` div from the root of the pos app;
- made the receipt be a standalone component. It thus benefits
from all the advantages of components, such as prop validation
and usage of slots;
- replaced the `OrderLinesReceipt` template with the generic
`OrderWidget` component'; this greatly simplifies the code;
- created the `renderer` service. It's goal is to do for components
what `renderToElement` does for templates; we use this service to
render the receipt component for printing;
- removed jquery from the EpsonPrinter class, such that it can be
imported into projects that do not rely on jquery;
- created the `ReceiptHeader` component. This unifies the header
between all the different receipts; ( before, each receipt was
implementing it's own header )
Task: 3547597
Part-of: odoo/odoo#137397
This commit is contained in:
@@ -61,15 +61,17 @@ export class EpsonPrinter extends BasePrinter {
|
||||
* @override
|
||||
*/
|
||||
async sendPrintingJob(img) {
|
||||
const res = await $.ajax({
|
||||
url: this.address,
|
||||
const res = await fetch(this.address, {
|
||||
method: "POST",
|
||||
data: img,
|
||||
body: img,
|
||||
});
|
||||
const response = $(res).find("response");
|
||||
const body = await res.text();
|
||||
const parser = new DOMParser();
|
||||
const parsedBody = parser.parseFromString(body, "application/xml");
|
||||
const response = parsedBody.querySelector("response");
|
||||
return {
|
||||
result: response.attr("success") === "true",
|
||||
printerErrorCode: response.attr("code"),
|
||||
result: response.getAttribute("success") === "true",
|
||||
printerErrorCode: response.getAttribute("code"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -152,21 +154,10 @@ export class EpsonPrinter extends BasePrinter {
|
||||
* @override
|
||||
*/
|
||||
getActionError() {
|
||||
const printRes = {
|
||||
successful: false,
|
||||
message: {
|
||||
title: _t("Connection to the printer failed"),
|
||||
body: _t(
|
||||
"Please check if the printer is still connected. \n" +
|
||||
"Some browsers don't allow HTTP calls from websites to devices in the network (for security reasons). " +
|
||||
"If it is the case, you will need to follow Odoo's documentation for " +
|
||||
"'Self-signed certificate for ePOS printers' and 'Secure connection (HTTPS)' to solve the issue"
|
||||
),
|
||||
},
|
||||
};
|
||||
const printRes = super.getResultsError();
|
||||
if (window.location.protocol === "https:") {
|
||||
printRes.message.body += _t(
|
||||
"If you are on a secure server (HTTPS) please make sure you manually accepted the certificate by accessing %s",
|
||||
"If you are on a secure server (HTTPS) please make sure you manually accepted the certificate by accessing %s. ",
|
||||
this.url
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user