From 1dda5b84d1986d21fe8c9f0aed3ba67a11899596 Mon Sep 17 00:00:00 2001 From: "Pedram (PEBR)" Date: Tue, 1 Aug 2023 12:47:04 +0000 Subject: [PATCH] [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) Signed-off-by: Pedram Bi Ria (pebr) --- .../static/src/app/screens/product_screen/product_screen.js | 6 ++++-- .../overrides/components/product_screen/product_screen.js | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js b/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js index a969231caf8..c99f0bd3060 100644 --- a/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js +++ b/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js @@ -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(); diff --git a/addons/pos_loyalty/static/src/overrides/components/product_screen/product_screen.js b/addons/pos_loyalty/static/src/overrides/components/product_screen/product_screen.js index b1fd3896559..fdb96b9b33c 100644 --- a/addons/pos_loyalty/static/src/overrides/components/product_screen/product_screen.js +++ b/addons/pos_loyalty/static/src/overrides/components/product_screen/product_screen.js @@ -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(); + } + } });