feat: add debounced auto-sync to pending orders on note updates in POS restaurant mode

This commit is contained in:
Suherdy Yacob 2026-06-16 16:39:18 +07:00
parent f205e94c2b
commit 2f1e9d869a
2 changed files with 20 additions and 0 deletions

View File

@ -35,6 +35,7 @@ patch(NoteButton.prototype, {
} else { } else {
this.setOrderlineNote(payload); this.setOrderlineNote(payload);
} }
this.pos.addPendingOrder([selectedOrderline.order_id.id]);
} }
}); });
@ -54,8 +55,10 @@ patch(InternalNoteButton.prototype, {
const coloredNotes = payload ? this.reframeNotes(payload) : "[]"; const coloredNotes = payload ? this.reframeNotes(payload) : "[]";
if (selectedOrderline) { if (selectedOrderline) {
this.setChanges(selectedOrderline, coloredNotes); this.setChanges(selectedOrderline, coloredNotes);
this.pos.addPendingOrder([selectedOrderline.order_id.id]);
} else { } else {
this.pos.getOrder().setInternalNote(coloredNotes); this.pos.getOrder().setInternalNote(coloredNotes);
this.pos.addPendingOrder([this.pos.getOrder().id]);
} }
return { return {
confirmed: typeof payload === "string", confirmed: typeof payload === "string",

View File

@ -3,6 +3,7 @@
import { PosStore } from "@point_of_sale/app/services/pos_store"; import { PosStore } from "@point_of_sale/app/services/pos_store";
import { patch } from "@web/core/utils/patch"; import { patch } from "@web/core/utils/patch";
import { toRaw } from "@odoo/owl"; import { toRaw } from "@odoo/owl";
import { debounce } from "@web/core/utils/timing";
patch(PosStore.prototype, { patch(PosStore.prototype, {
clearProductsCache() { clearProductsCache() {
@ -18,6 +19,22 @@ patch(PosStore.prototype, {
return await super.editProduct(...arguments); return await super.editProduct(...arguments);
}, },
addPendingOrder(orderIds, remove = false) {
const result = super.addPendingOrder(...arguments);
if (this.config.module_pos_restaurant && !remove) {
if (!this._autoSyncOnEditDebounced) {
this._autoSyncOnEditDebounced = debounce(() => {
const pending = this.getPendingOrder();
if (pending.orderToUpdate.length > 0 || pending.orderToCreate.length > 0) {
this.syncAllOrdersDebounced();
}
}, 1500);
}
this._autoSyncOnEditDebounced();
}
return result;
},
get productsToDisplay() { get productsToDisplay() {
const searchWord = this.searchProductWord.trim(); const searchWord = this.searchProductWord.trim();
const categoryId = this.selectedCategory?.id || 0; const categoryId = this.selectedCategory?.id || 0;