From 21c1ed5b3a5e77889eb83a5b6060ff1f6b193d43 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Tue, 7 Sep 2021 12:01:50 +0000 Subject: [PATCH] [FIX] point_of_sale: improve refunding order with single item For simplicity, when the order has single item (refundable quantity of 1) and has single line, we just assume that it's fully refundable. No need to ask the user how much they want to refund. Part-of: odoo/odoo#77903 --- .../js/Screens/TicketScreen/TicketScreen.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/addons/point_of_sale/static/src/js/Screens/TicketScreen/TicketScreen.js b/addons/point_of_sale/static/src/js/Screens/TicketScreen/TicketScreen.js index 801b3601187..ab84bc7c8b5 100644 --- a/addons/point_of_sale/static/src/js/Screens/TicketScreen/TicketScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/TicketScreen/TicketScreen.js @@ -193,6 +193,10 @@ odoo.define('point_of_sale.TicketScreen', function (require) { return this.render(); } + if (this._doesOrderHaveSoleItem(order)) { + this._prepareAutoRefundOnOrder(order); + } + const customer = order.get_client(); // Select the lines from toRefundLines (can come from different orders) @@ -356,6 +360,7 @@ odoo.define('point_of_sale.TicketScreen', function (require) { getHasItemsToRefund() { const order = this.getSelectedSyncedOrder(); if (!order) return false; + if (this._doesOrderHaveSoleItem(order)) return true; const total = Object.values(this.env.pos.toRefundLines) .filter( (toRefundDetail) => @@ -367,6 +372,24 @@ odoo.define('point_of_sale.TicketScreen', function (require) { } //#endregion //#region PRIVATE METHODS + _doesOrderHaveSoleItem(order) { + const orderlines = order.get_orderlines(); + if (orderlines.length !== 1) return false; + const theOrderline = orderlines[0]; + const refundableQty = theOrderline.get_quantity() - theOrderline.refunded_qty; + return this.env.pos.isProductQtyZero(refundableQty - 1); + } + _prepareAutoRefundOnOrder(order) { + const selectedOrderlineId = this.getSelectedOrderlineId(); + const orderline = order.orderlines.models.find((line) => line.id == selectedOrderlineId); + if (!orderline) return; + + const toRefundDetail = this._getToRefundDetail(orderline); + const refundableQty = orderline.get_quantity() - orderline.refunded_qty; + if (this.env.pos.isProductQtyZero(refundableQty - 1)) { + toRefundDetail.qty = 1; + } + } /** * Returns the corresponding toRefundDetail of the given orderline. * SIDE-EFFECT: Automatically creates a toRefundDetail object for