Skip to content

Commit

Permalink
[IMP] pos: allow changing quantity of combo product
Browse files Browse the repository at this point in the history
This commit updates the logic to enable the modification of quantities for combo products in the cart.
  • Loading branch information
nesma-neha committed Apr 23, 2024
1 parent 2132f89 commit 4b54504
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ export class OrderSummary extends Component {
}
return;
}
if (this.pos.numpadMode === "quantity" && selectedLine?.isPartOfCombo()) {
if (key === "Backspace") {
this._setValue("remove");
} else {
this.dialog.add(AlertDialog, {
title: _t("Invalid action"),
body: _t(
"The quantity of a combo item cannot be changed. A combo can only be deleted."
),
});
}
return;
}
if (
selectedLine &&
this.pos.numpadMode === "quantity" &&
Expand Down Expand Up @@ -120,14 +107,22 @@ export class OrderSummary extends Component {

_setValue(val) {
const { numpadMode } = this.pos;
const selectedLine = this.currentOrder.get_selected_orderline();
let selectedLine = this.currentOrder.get_selected_orderline();
if (selectedLine) {
if (numpadMode === "quantity") {
if (selectedLine.combo_parent_id) {
selectedLine = selectedLine.combo_parent_id;
}
if (val === "remove") {
this.currentOrder.removeOrderline(selectedLine);
} else {
const result = selectedLine.set_quantity(val);

const result = selectedLine.set_quantity(
val,
Boolean(selectedLine.combo_line_ids?.length)
);
for (const line of selectedLine.combo_line_ids) {
line.set_quantity(val, true);
}
if (result !== true) {
this.dialog.add(AlertDialog, result);
this.numberBuffer.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ export class TicketScreen extends Component {

destinationOrder.takeaway = order.takeaway;
// Add orderline for each toRefundDetail to the destinationOrder.
const lines = [];
const lineRefs = {};
for (const refundDetail of allToRefundDetails) {
const refundLine = refundDetail.line;
const line = this.pos.models["pos.order.line"].create({
Expand All @@ -290,8 +292,20 @@ export class TicketScreen extends Component {
line.setOptions({
uiState: { price_type: "automatic" },
});
lines.push(line);
lineRefs[refundLine.id] = line;
refundDetail.destination_order_uuid = destinationOrder.uuid;
}
//add combo relations to lines
for (const line of lines) {
const refundLine = line.refunded_orderline_id;
if (refundLine.combo_parent_id && lineRefs[refundLine.combo_parent_id.id]) {
line.combo_parent_id = lineRefs[refundLine.combo_parent_id.id];
}
if (refundLine.combo_line_ids && refundLine.combo_line_ids.length > 0) {
line.combo_line_ids = refundLine.combo_line_ids.map((line) => lineRefs[line.id]);
}
}

//Add a check too see if the fiscal position exist in the pos
if (order.fiscal_position_not_found) {
Expand Down
10 changes: 8 additions & 2 deletions addons/point_of_sale/static/tests/tours/pos_combo_tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ registry.category("web_tour.tours").add("PosComboPriceTaxIncludedTour", {
...ProductScreen.clickPartnerButton(),
...ProductScreen.clickCustomer("Partner Test 1"),

// check that you cannot change the quantity of a combo product
// check that you can change the quantity of a combo product
...ProductScreen.clickNumpad("2"),
Dialog.confirm(),
...ProductScreen.clickOrderline("Combo Product 3", "2.0"),
...ProductScreen.selectedOrderlineHas("Combo Product 3", "2.0", "26.86"),
...ProductScreen.clickOrderline("Combo Product 5", "2.0"),
...ProductScreen.selectedOrderlineHas("Combo Product 5", "2.0", "37.34"),
...ProductScreen.clickOrderline("Combo Product 8", "2.0"),
...ProductScreen.selectedOrderlineHas("Combo Product 8", "2.0", "60.00"),

// check that removing a combo product removes all the combo products
...ProductScreen.clickNumpad("⌫"),
...ProductScreen.clickNumpad("⌫"),
...ProductScreen.orderIsEmpty(),

...ProductScreen.clickDisplayedProduct("Office Combo"),
Expand Down

0 comments on commit 4b54504

Please sign in to comment.