[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
This commit is contained in:
committed by
Pierre Masereel
parent
4e16218848
commit
21c1ed5b3a
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user