[FIX] point_of_sale: reuse empty order when refunding
X-original-commit: 2a633ee1035810f64a85360ff7559d9a219a8e52 Part-of: odoo/odoo#100891
This commit is contained in:
@@ -213,7 +213,7 @@ odoo.define('point_of_sale.TicketScreen', function (require) {
|
||||
const destinationOrder =
|
||||
this.props.destinationOrder && partner === this.props.destinationOrder.get_partner()
|
||||
? this.props.destinationOrder
|
||||
: this.env.pos.add_new_order();
|
||||
: this._getEmptyOrder(partner);
|
||||
|
||||
// Add orderline for each toRefundDetail to the destinationOrder.
|
||||
for (const refundDetail of allToRefundDetails) {
|
||||
@@ -229,6 +229,10 @@ odoo.define('point_of_sale.TicketScreen', function (require) {
|
||||
destinationOrder.updatePricelist(partner);
|
||||
}
|
||||
|
||||
if (this.env.pos.get_order().cid !== destinationOrder.cid) {
|
||||
this.env.pos.set_order(destinationOrder);
|
||||
}
|
||||
|
||||
this._onCloseScreen();
|
||||
}
|
||||
//#endregion
|
||||
@@ -377,6 +381,30 @@ odoo.define('point_of_sale.TicketScreen', function (require) {
|
||||
}
|
||||
//#endregion
|
||||
//#region PRIVATE METHODS
|
||||
/**
|
||||
* Find the empty order with the following priority:
|
||||
* - The empty order with the same parter as the provided.
|
||||
* - The first empty order without a partner.
|
||||
* - If no empty order, create a new one.
|
||||
* @param {Object | null} partner
|
||||
* @returns {boolean}
|
||||
*/
|
||||
_getEmptyOrder(partner) {
|
||||
let emptyOrderForPartner = null;
|
||||
let emptyOrder = null;
|
||||
for (const order of this.env.pos.orders) {
|
||||
if (order.get_orderlines().length === 0 && order.get_paymentlines().length === 0) {
|
||||
if (order.get_partner() === partner) {
|
||||
emptyOrderForPartner = order;
|
||||
break;
|
||||
} else if (!order.get_partner() && emptyOrder === null) {
|
||||
// If emptyOrderForPartner is not found, we will use the first empty order.
|
||||
emptyOrder = order;
|
||||
}
|
||||
}
|
||||
}
|
||||
return emptyOrderForPartner || emptyOrder || this.env.pos.add_new_order();
|
||||
}
|
||||
_doesOrderHaveSoleItem(order) {
|
||||
const orderlines = order.get_orderlines();
|
||||
if (orderlines.length !== 1) return false;
|
||||
|
||||
Reference in New Issue
Block a user