[IMP] point_of_sale: make _onDoRefund overrideable
closes odoo/odoo#89001 X-original-commit: e30ad97449793fc200784b7c70bce271060264de Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
committed by
Pierre Masereel
parent
167a973be4
commit
1235cd404b
@@ -193,18 +193,7 @@ odoo.define('point_of_sale.TicketScreen', function (require) {
|
||||
|
||||
const partner = order.get_partner();
|
||||
|
||||
// Select the lines from toRefundLines (can come from different orders)
|
||||
// such that:
|
||||
// - the quantity to refund is not zero
|
||||
// - if there is partner in the selected paid order, select the items
|
||||
// with the same orderPartnerId
|
||||
// - it is not yet linked to an active order (no destinationOrderUid)
|
||||
const allToRefundDetails = Object.values(this.env.pos.toRefundLines).filter(
|
||||
({ qty, orderline, destinationOrderUid }) =>
|
||||
!this.env.pos.isProductQtyZero(qty) &&
|
||||
(partner ? orderline.orderPartnerId == partner.id : true) &&
|
||||
!destinationOrderUid
|
||||
);
|
||||
const allToRefundDetails = this._getRefundableDetails(partner);
|
||||
if (allToRefundDetails.length == 0) {
|
||||
this._state.ui.highlightHeaderNote = !this._state.ui.highlightHeaderNote;
|
||||
return;
|
||||
@@ -220,16 +209,9 @@ odoo.define('point_of_sale.TicketScreen', function (require) {
|
||||
|
||||
// Add orderline for each toRefundDetail to the destinationOrder.
|
||||
for (const refundDetail of allToRefundDetails) {
|
||||
const { qty, orderline } = refundDetail;
|
||||
await destinationOrder.add_product(this.env.pos.db.get_product_by_id(orderline.productId), {
|
||||
quantity: -qty,
|
||||
price: orderline.price,
|
||||
extras: { price_manually_set: true },
|
||||
merge: false,
|
||||
refunded_orderline_id: orderline.id,
|
||||
tax_ids: orderline.tax_ids,
|
||||
discount: orderline.discount,
|
||||
});
|
||||
const product = this.env.pos.db.get_product_by_id(refundDetail.orderline.productId);
|
||||
const options = this._prepareRefundOrderlineOptions(refundDetail);
|
||||
await destinationOrder.add_product(product, options);
|
||||
refundDetail.destinationOrderUid = destinationOrder.uid;
|
||||
}
|
||||
|
||||
@@ -418,6 +400,42 @@ odoo.define('point_of_sale.TicketScreen', function (require) {
|
||||
return newToRefundDetail;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Select the lines from toRefundLines, as they can come from different orders.
|
||||
* Returns only details that:
|
||||
* - The quantity to refund is not zero
|
||||
* - Filtered by partner (optional)
|
||||
* - It's not yet linked to an active order (no destinationOrderUid)
|
||||
*
|
||||
* @param {Object} partner (optional)
|
||||
* @returns {Array} refundableDetails
|
||||
*/
|
||||
_getRefundableDetails(partner) {
|
||||
return Object.values(this.env.pos.toRefundLines).filter(
|
||||
({ qty, orderline, destinationOrderUid }) =>
|
||||
!this.env.pos.isProductQtyZero(qty) &&
|
||||
(partner ? orderline.orderPartnerId == partner.id : true) &&
|
||||
!destinationOrderUid
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Prepares the options to add a refund orderline.
|
||||
*
|
||||
* @param {Object} toRefundDetail
|
||||
* @returns {Object}
|
||||
*/
|
||||
_prepareRefundOrderlineOptions(toRefundDetail) {
|
||||
const { qty, orderline } = toRefundDetail;
|
||||
return {
|
||||
quantity: -qty,
|
||||
price: orderline.price,
|
||||
extras: { price_manually_set: true },
|
||||
merge: false,
|
||||
refunded_orderline_id: orderline.id,
|
||||
tax_ids: orderline.tax_ids,
|
||||
discount: orderline.discount,
|
||||
}
|
||||
}
|
||||
_setOrder(order) {
|
||||
this.env.pos.set_order(order);
|
||||
this.close();
|
||||
|
||||
Reference in New Issue
Block a user