75 lines
2.7 KiB
JavaScript
75 lines
2.7 KiB
JavaScript
/** @odoo-module */
|
|
|
|
import { patch } from "@web/core/utils/patch";
|
|
import { PosStore } from "@point_of_sale/app/services/pos_store";
|
|
import { TicketScreen } from "@point_of_sale/app/screens/ticket_screen/ticket_screen";
|
|
|
|
patch(TicketScreen.prototype, {
|
|
async onClickReprintAll(order) {
|
|
// Feature disabled as per user request
|
|
},
|
|
});
|
|
|
|
patch(PosStore.prototype, {
|
|
createPrinter(config) {
|
|
if (config.printer_type === "network_escpos") {
|
|
return {
|
|
config: config,
|
|
printReceipt: async (receipt, actionId) => {
|
|
// This dummy promise ensures the printer interface is fulfilled.
|
|
// The actual sending to backend is hooked in `printOrderChanges`.
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
return super.createPrinter(...arguments);
|
|
},
|
|
|
|
async printOrderChanges(data, printer) {
|
|
if (printer.config && printer.config.printer_type === "network_escpos") {
|
|
const changesData = data.changes?.data || [];
|
|
|
|
// Build the data object to send to backend
|
|
const lines = changesData.map(c => ({
|
|
name: c.name,
|
|
qty: c.quantity || c.qty || 1,
|
|
note: c.note || ''
|
|
}));
|
|
|
|
const receipt_data = {
|
|
order_name: data.name || '',
|
|
order_time: data.time?.raw || new Date().toISOString(),
|
|
waiter: data.cashier || '',
|
|
table: data.table_name || '',
|
|
lines: lines
|
|
};
|
|
|
|
try {
|
|
const result = await this.env.services.orm.call(
|
|
'pos.printer',
|
|
'print_network_kitchen_receipt',
|
|
[printer.config.id, receipt_data]
|
|
);
|
|
|
|
if (!result.successful) {
|
|
this.env.services.notification.add(
|
|
result.message || "Network printer error",
|
|
{ type: "danger" }
|
|
);
|
|
return { successful: false, message: { body: result.message || "Network printer error" } };
|
|
}
|
|
return { successful: true };
|
|
} catch (error) {
|
|
console.error("Error printing to network printer", error);
|
|
this.env.services.notification.add(
|
|
"Error printing to network printer",
|
|
{ type: "danger" }
|
|
);
|
|
return { successful: false, message: { body: error.message || "Error printing to network printer" } };
|
|
}
|
|
}
|
|
|
|
return super.printOrderChanges(data, printer);
|
|
}
|
|
});
|