From 33dd4214eeb2550cf06efb7d8a812183707098f6 Mon Sep 17 00:00:00 2001 From: Alaguraj0361 Date: Sat, 13 Jun 2026 17:35:26 +0530 Subject: [PATCH] update order handling in EqualSplitScreen for improved split functionality --- .../static/src/js/equal_split.js | 79 ++++++++++++++++--- 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/addons/dine360_restaurant/static/src/js/equal_split.js b/addons/dine360_restaurant/static/src/js/equal_split.js index 0222857..5e55d3e 100644 --- a/addons/dine360_restaurant/static/src/js/equal_split.js +++ b/addons/dine360_restaurant/static/src/js/equal_split.js @@ -3,6 +3,7 @@ import { registry } from "@web/core/registry"; import { usePos } from "@point_of_sale/app/store/pos_hook"; import { Component, useState } from "@odoo/owl"; +import { Order } from "@point_of_sale/app/store/models"; export class EqualSplitScreen extends Component { static template = "dine360_restaurant.EqualSplitScreen"; @@ -18,13 +19,13 @@ export class EqualSplitScreen extends Component { get formattedTotal() { const order = this.order; - return this.env.utils.formatCurrency(order ? order.getTotalWithTax() : 0); + return this.env.utils.formatCurrency(order ? order.get_total_with_tax() : 0); } get formattedEqualAmount() { const order = this.order; if (!order || this.state.numPeople < 1) return this.env.utils.formatCurrency(0); - return this.env.utils.formatCurrency(order.getTotalWithTax() / this.state.numPeople); + return this.env.utils.formatCurrency(order.get_total_with_tax() / this.state.numPeople); } decreasePeople() { @@ -44,7 +45,7 @@ export class EqualSplitScreen extends Component { if (!order) return; const N = this.state.numPeople; - const total = order.getTotalWithTax(); + const total = order.get_total_with_tax(); const target = Math.round((total / N) * 100) / 100; const lines = order.get_orderlines(); const splitlines = {}; @@ -54,32 +55,92 @@ export class EqualSplitScreen extends Component { if (accumulated >= target - 0.005) break; const lineTotal = this._getLineTotal(line); - const perUnit = line.qty > 0 ? lineTotal / line.qty : 0; + const qty = line.get_quantity(); + const perUnit = qty > 0 ? lineTotal / qty : 0; if (perUnit <= 0) continue; const needed = target - accumulated; if (lineTotal <= needed + 0.005) { - splitlines[line.uid] = line.qty; + splitlines[line.id] = qty; accumulated += lineTotal; } else { const qtyToTake = Math.round((needed / perUnit) * 1000) / 1000; if (qtyToTake > 0.001) { - splitlines[line.uid] = qtyToTake; + splitlines[line.id] = qtyToTake; accumulated += qtyToTake * perUnit; } } } - if (typeof this.pos.splitOrder === "function") { - await this.pos.splitOrder(order, splitlines); + const splitKeys = Object.keys(splitlines); + if (splitKeys.length === 0) { + return; } + + const newOrder = new Order( + { env: this.env }, + { + pos: this.pos, + } + ); + + for (const id of splitKeys) { + const splitQty = splitlines[id]; + const line = order.get_orderline(parseInt(id)); + if (!line) continue; + + const orderline = line.clone(); + newOrder.add_orderline(orderline); + orderline.set_quantity(splitQty, "do not recompute unit price"); + + if (!this.pos.disallowLineQuantityChange()) { + line.set_quantity( + line.get_quantity() - splitQty, + "do not recompute unit price" + ); + } else { + const decreaseLine = line.clone(); + decreaseLine.order = order; + decreaseLine.noDecrease = true; + decreaseLine.set_quantity(-splitQty); + order.add_orderline(decreaseLine); + } + } + + if (!this.pos.disallowLineQuantityChange()) { + for (const id of splitKeys) { + const line = order.get_orderline(parseInt(id)); + if (line && Math.abs(line.get_quantity()) < 0.00001) { + order.removeOrderline(line); + } + } + } + + newOrder.set_screen_data({ name: "PaymentScreen" }); + + if (this.pos.orderPreparationCategories.size) { + order.updateLastOrderChange(); + newOrder.updateLastOrderChange(); + } + + newOrder.setCustomerCount(1); + newOrder.originalSplittedOrder = order; + + const newCustomerCount = order.getCustomerCount() - 1; + order.setCustomerCount(newCustomerCount || 1); + order.set_screen_data({ name: "ProductScreen" }); + + const reactiveNewOrder = this.pos.makeOrderReactive(newOrder); + this.pos.orders.add(reactiveNewOrder); + this.pos.selectedOrder = reactiveNewOrder; + this.pos.showScreen("PaymentScreen"); } _getLineTotal(line) { if (typeof line.get_price_with_tax === "function") return line.get_price_with_tax(); - return (line.price || 0) * (line.qty || 1); + return (line.get_unit_price() || 0) * (line.get_quantity() || 1); } }