[IMP] point_of_sale,pos_restaurant: cancelled order to preparation tools
Before when you deleted a order in PoS with the preparation tools enabled. The order was not cancelled on them. Now, when cancelling/deleting an order in PoS the information is sent to the preparation tools. closes odoo/odoo#120447 Taskid: 3278081 Related: odoo/enterprise#40673 Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
@@ -57,11 +57,13 @@ export class PosStore extends Reactive {
|
||||
}
|
||||
|
||||
// Now the printer should work in PoS without restaurant
|
||||
async sendOrderInPreparation(order) {
|
||||
async sendOrderInPreparation(order, cancelled = false) {
|
||||
if (this.globalState.printers_category_ids_set.size) {
|
||||
try {
|
||||
if (order.hasChangesToPrint()) {
|
||||
const isPrintSuccessful = await order.printChanges();
|
||||
const changes = order.changesToOrder(cancelled);
|
||||
|
||||
if (changes.cancelled.length > 0 || changes.new.length > 0) {
|
||||
const isPrintSuccessful = await order.printChanges(cancelled);
|
||||
if (!isPrintSuccessful) {
|
||||
this.popup.add(ErrorPopup, {
|
||||
title: _t("Printing failed"),
|
||||
|
||||
@@ -5,7 +5,7 @@ import { AbstractReceiptScreen } from "@point_of_sale/js/Misc/AbstractReceiptScr
|
||||
import { OfflineErrorPopup } from "@point_of_sale/js/Popups/OfflineErrorPopup";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { OrderReceipt } from "./OrderReceipt";
|
||||
import { onMounted, useRef, status, useState } from "@odoo/owl";
|
||||
import { onMounted, useRef, status, useState, onWillStart } from "@odoo/owl";
|
||||
import { usePos } from "@point_of_sale/app/pos_hook";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { BasePrinter } from "@point_of_sale/app/printer/base_printer";
|
||||
@@ -44,11 +44,13 @@ export class ReceiptScreen extends AbstractReceiptScreen {
|
||||
await this.handleAutoPrint();
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
|
||||
onWillStart(async () => {
|
||||
// When the order is paid, if there is still a part of the order
|
||||
// to send in preparation it is automatically sent
|
||||
if (this.pos.globalState.orderPreparationCategories.size) {
|
||||
this.pos.sendOrderInPreparation(this.currentOrder);
|
||||
await this.pos.sendOrderInPreparation(this.currentOrder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,6 +148,9 @@ export class TicketScreen extends IndependentToOrderScreen {
|
||||
}
|
||||
const { globalState } = this.pos;
|
||||
if (order && (await this._onBeforeDeleteOrder(order))) {
|
||||
if (Object.keys(order.lastOrderPrepaChange).length > 0) {
|
||||
await this.pos.sendOrderInPreparation(order, true);
|
||||
}
|
||||
if (order === globalState.get_order()) {
|
||||
this._selectNextOrder(order);
|
||||
}
|
||||
|
||||
@@ -2974,8 +2974,10 @@ export class Order extends PosModel {
|
||||
|
||||
return receipt;
|
||||
}
|
||||
async printChanges() {
|
||||
const orderChange = this.changesToOrder;
|
||||
// This function send order change to printer
|
||||
// For sending changes to preparation display see sendChanges function.
|
||||
async printChanges(cancelled) {
|
||||
const orderChange = this.changesToOrder(cancelled);
|
||||
let isPrintSuccessful = true;
|
||||
const d = new Date();
|
||||
let hours = "" + d.getHours();
|
||||
@@ -3013,8 +3015,7 @@ export class Order extends PosModel {
|
||||
|
||||
return isPrintSuccessful;
|
||||
}
|
||||
_getPrintingCategoriesChanges(categories) {
|
||||
const currentOrderChange = this.changesToOrder;
|
||||
_getPrintingCategoriesChanges(categories, currentOrderChange) {
|
||||
return {
|
||||
new: currentOrderChange["new"].filter((change) =>
|
||||
this.pos.db.is_product_in_category(categories, change["product_id"])
|
||||
@@ -3082,7 +3083,7 @@ export class Order extends PosModel {
|
||||
for (const orderlineIdx in this.orderlines) {
|
||||
const orderline = this.orderlines[orderlineIdx];
|
||||
|
||||
if (orderline.skipChange) {
|
||||
if (orderline.skipChange || orderline.refunded_orderline_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -3136,16 +3137,18 @@ export class Order extends PosModel {
|
||||
// This function transforms the data generated by getOrderChanges into the old
|
||||
// pattern used by the printer and the display preparation. This old pattern comes from
|
||||
// the time when this logic was in pos_restaurant.
|
||||
get changesToOrder() {
|
||||
changesToOrder(cancelled = false) {
|
||||
const toAdd = [];
|
||||
const toRemove = [];
|
||||
const changes = Object.values(this.getOrderChanges());
|
||||
const changes = !cancelled
|
||||
? Object.values(this.getOrderChanges())
|
||||
: Object.values(this.lastOrderPrepaChange);
|
||||
|
||||
for (const lineChange of changes) {
|
||||
if (lineChange["quantity"] > 0) {
|
||||
if (lineChange["quantity"] > 0 && !cancelled) {
|
||||
toAdd.push(lineChange);
|
||||
} else if (lineChange["quantity"] < 0) {
|
||||
lineChange["quantity"] *= -1; // we change the sign because that's how it is
|
||||
} else {
|
||||
lineChange["quantity"] = Math.abs(lineChange["quantity"]); // we need always positive values.
|
||||
toRemove.push(lineChange);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,4 +46,11 @@
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Preparation Printers"
|
||||
id="point_of_sale.menu_pos_preparation_printer"
|
||||
parent="point_of_sale.menu_point_of_sale"
|
||||
action="action_pos_printer_form"
|
||||
sequence="99" />
|
||||
</odoo>
|
||||
|
||||
@@ -83,11 +83,13 @@ patch(TicketScreen.prototype, "pos_restaurant.TicketScreen", {
|
||||
const { globalState } = this.pos;
|
||||
if (globalState.config.module_pos_restaurant) {
|
||||
globalState.setOrderToRemove(order);
|
||||
await _super(...arguments);
|
||||
if (!globalState.table) {
|
||||
await globalState._removeOrdersFromServer();
|
||||
}
|
||||
} else {
|
||||
await _super(...arguments);
|
||||
}
|
||||
await _super(...arguments);
|
||||
},
|
||||
async setTip(order, serverId, amount) {
|
||||
const { globalState } = this.pos;
|
||||
|
||||
Reference in New Issue
Block a user