From bb9677d6732438a2c6eb85dfc0e990ca3c534ca2 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Thu, 5 Oct 2023 09:25:55 +0200 Subject: [PATCH] [FIX] pos_self_order: show take away price Steps to reproduce: - Activate "Eat in / Take away" (`pos_self_ordering_takeaway`) setting. - Set the alternative fiscal position. - ISSUE: When selecting take away in the app, the take away price is not shown. FIX: The issue is because during the loading of the products, only the default price is computed. In this PR, we are now computing the take away price as well. And in the ui, depending on the choice, we are showing the correct price. closes odoo/odoo#137653 Signed-off-by: Robin Heinz (rhe) --- .../pos_self_order/models/product_product.py | 28 +++++++++++++++---- .../components/product_card/product_card.xml | 2 +- .../static/src/app/models/product.js | 4 --- .../app/pages/product_page/product_page.xml | 2 +- .../static/src/app/self_order_service.js | 8 ++++++ 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/addons/pos_self_order/models/product_product.py b/addons/pos_self_order/models/product_product.py index 7bdd490a7a1..fe5a6b043ad 100644 --- a/addons/pos_self_order/models/product_product.py +++ b/addons/pos_self_order/models/product_product.py @@ -97,16 +97,34 @@ class ProductProduct(models.Model): self, qty, currency=pos_config.currency_id ) - price_info = pos_config.default_fiscal_position_id.map_tax(self.taxes_id).compute_all( + # Declare variables, will be the return values. + display_price_default = price + display_price_alternative = price + + taxes_default = pos_config.default_fiscal_position_id.map_tax(self.taxes_id) + taxes_alternative = pos_config.self_ordering_alternative_fp_id.map_tax(self.taxes_id) + + all_prices_default = taxes_default.compute_all( + price, pos_config.currency_id, qty, product=self + ) + all_prices_alternative = taxes_alternative.compute_all( price, pos_config.currency_id, qty, product=self ) - display_price = price_info["total_included"] if pos_config.iface_tax_included == "total" else price_info["total_excluded"] - display_price = self.lst_price if self.combo_ids else display_price + if self.combo_ids: + display_price_default = self.lst_price + display_price_alternative = self.lst_price + else: + if pos_config.iface_tax_included == 'total': + display_price_default = all_prices_default["total_included"] + display_price_alternative = all_prices_alternative["total_included"] + else: + display_price_default = all_prices_default["total_excluded"] + display_price_alternative = all_prices_alternative["total_excluded"] return { - "display_price": display_price, - "lst_price": self.lst_price + 'display_price_default': display_price_default, + 'display_price_alternative': display_price_alternative, } def _get_product_for_ui(self, pos_config): diff --git a/addons/pos_self_order/static/src/app/components/product_card/product_card.xml b/addons/pos_self_order/static/src/app/components/product_card/product_card.xml index 9e540b82f45..6cce6883348 100644 --- a/addons/pos_self_order/static/src/app/components/product_card/product_card.xml +++ b/addons/pos_self_order/static/src/app/components/product_card/product_card.xml @@ -14,7 +14,7 @@
- +
Out of stock
diff --git a/addons/pos_self_order/static/src/app/models/product.js b/addons/pos_self_order/static/src/app/models/product.js index 0fe76657e44..a82f3dd2341 100644 --- a/addons/pos_self_order/static/src/app/models/product.js +++ b/addons/pos_self_order/static/src/app/models/product.js @@ -40,10 +40,6 @@ export class Product extends Reactive { this.showPriceTaxIncluded = showPriceTaxIncluded; } - get prices() { - return this.price_info.display_price; - } - get isCombo() { return this.pos_combo_ids; } diff --git a/addons/pos_self_order/static/src/app/pages/product_page/product_page.xml b/addons/pos_self_order/static/src/app/pages/product_page/product_page.xml index 46c14696636..1c1cf8e6cde 100644 --- a/addons/pos_self_order/static/src/app/pages/product_page/product_page.xml +++ b/addons/pos_self_order/static/src/app/pages/product_page/product_page.xml @@ -16,7 +16,7 @@ class="o_self_order_main_desc flex-grow-1 pb-3 mb-3 bg-view text-muted " t-esc="product.description_sale" /> - +
diff --git a/addons/pos_self_order/static/src/app/self_order_service.js b/addons/pos_self_order/static/src/app/self_order_service.js index 79d2f1704b5..6d9203d3e12 100644 --- a/addons/pos_self_order/static/src/app/self_order_service.js +++ b/addons/pos_self_order/static/src/app/self_order_service.js @@ -434,6 +434,14 @@ export class SelfOrder extends Reactive { return result; } + + getProductDisplayPrice(product) { + if (this.currentOrder.take_away) { + return product.price_info.display_price_alternative; + } else { + return product.price_info.display_price_default; + } + } } export const selfOrderService = {