[FIX] pos_loyalty: update rewards even if disallowLineQuantityChange

Before this commit, if you update the quantity of a line that it's
`disallowLineQuantityChange` it will call `_showDecreaseQuantityPopup`
to update the quantity and it will call the `set_quantity` to modify
the quantity. Calling 'set_quantity' won't call the `_updateRewards`
and it causes us to not update the rewards.

Steps to reproduce:
- In a French company, install the module "France - VAT Anti-Fraud
Certification for Point of Sale"
- Create a Loyalty program that gives you 1 point for each euro spent.
- Add items to the cart, and the points sum up.
- Remove items from the cart, the points don't subtract.
+ If points reward is added to the cart and then removed, the points
are still considered as used.

The solution is to override the `_showDecreaseQuantityPopup` function
in the pos_loyalty to call the `_updateRewards`.

opw-3430349

closes odoo/odoo#130794

X-original-commit: 1bbeaefe0f750fceba19cc9199cd7a0681fd1f7a
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
This commit is contained in:
Pedram (PEBR)
2023-08-04 10:59:26 +02:00
parent e61e600bfd
commit 1dda5b84d1
2 changed files with 10 additions and 2 deletions
@@ -255,14 +255,14 @@ export class ProductScreen extends ControlButtonsMixin(Component) {
const currentQuantity = selectedLine.get_quantity();
if (newQuantity >= currentQuantity) {
selectedLine.set_quantity(newQuantity);
return;
return true;
}
if (newQuantity >= selectedLine.saved_quantity) {
if (newQuantity == 0) {
order.remove_orderline(selectedLine);
}
selectedLine.set_quantity(newQuantity);
return;
return true;
}
const newLine = selectedLine.clone();
const decreasedQuantity = selectedLine.saved_quantity - newQuantity;
@@ -270,7 +270,9 @@ export class ProductScreen extends ControlButtonsMixin(Component) {
newLine.set_quantity(-decreasedQuantity, true);
selectedLine.set_quantity(selectedLine.saved_quantity);
order.add_orderline(newLine);
return true;
}
return false;
}
get selectedOrderlineQuantity() {
return this.currentOrder.get_selected_orderline()?.get_quantity_str();
@@ -110,4 +110,10 @@ patch(ProductScreen.prototype, {
await super._barcodeProductAction(code);
this.currentOrder._updateRewards();
},
async _showDecreaseQuantityPopup() {
const result = await this._super();
if (result){
this.currentOrder._updateRewards();
}
}
});