From 4df87cf10f3d03d3b17d1c13ff55e7d16983a893 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Wed, 22 Feb 2023 15:49:19 +0000 Subject: [PATCH] [FIX] point_of_sale: correctly round total due in payment screen Current behavior: When you make a purchase that should be rounded down, for example 1.97 rounded down to 1.95. On the payment screen if you select a payment method and pay with a greater amount than the base amount. The total due would be rounded incorrectly to 2.00 instead of 1.95. Steps to reproduce: - Create a product with a price of 1.97 - Set a rouding down method of 0.05 - Open a pos session - Add the product to the order - Select a payment method, for example cash and enter an amount greater than the base amount, for example 5.00 - The total due will be 2.00 instead of 1.95 opw-3175726 closes odoo/odoo#114427 X-original-commit: 45994a5f8b3f87c46e39c260183663023d51e080 Signed-off-by: Heinz Robin (rhe) Signed-off-by: Engels Robin (roen) --- addons/point_of_sale/static/src/js/models.js | 2 +- .../static/tests/tours/PaymentScreen.tour.js | 16 ++++++++++++++++ .../tours/helpers/PaymentScreenTourMethods.js | 9 +++++++++ addons/point_of_sale/tests/test_frontend.py | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index fc239199a80..bea0c4c0f5f 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -3711,7 +3711,7 @@ export class Order extends PosModel { (this.get_total_with_tax() < 0 && remaining > 0) || (this.get_total_with_tax() > 0 && remaining < 0) ) { - rounding_method = rounding_method.endsWith("UP") ? "DOWN" : rounding_method; + rounding_method = rounding_method.endsWith("UP") ? "DOWN" : "UP"; } remaining *= sign; diff --git a/addons/point_of_sale/static/tests/tours/PaymentScreen.tour.js b/addons/point_of_sale/static/tests/tours/PaymentScreen.tour.js index 03585fc5e1a..5d44bcd09d6 100644 --- a/addons/point_of_sale/static/tests/tours/PaymentScreen.tour.js +++ b/addons/point_of_sale/static/tests/tours/PaymentScreen.tour.js @@ -172,3 +172,19 @@ PaymentScreen.check.remainingIs('0.0'); PaymentScreen.check.changeIs('0.0'); registry.category("web_tour.tours").add('PaymentScreenRoundingHalfUp', { test: true, url: '/pos/ui', steps: getSteps() }); + +startSteps(); + +ProductScreen.do.clickHomeCategory(); +ProductScreen.exec.addOrderline('Product Test', '1'); +ProductScreen.do.clickPayButton(); + +PaymentScreen.check.totalIs('1.95'); +PaymentScreen.exec.pay('Cash', '5'); + +PaymentScreen.check.remainingIs('0.0'); +PaymentScreen.check.changeIs('3.05'); +PaymentScreen.check.totalDueIs('1.95'); +Chrome.do.clickTicketButton(); + +registry.category("web_tour.tours").add('PaymentScreenTotalDueWithOverPayment', { test: true, url: '/pos/ui', steps: getSteps() }); diff --git a/addons/point_of_sale/static/tests/tours/helpers/PaymentScreenTourMethods.js b/addons/point_of_sale/static/tests/tours/helpers/PaymentScreenTourMethods.js index 81934b97d76..cdc9a635068 100644 --- a/addons/point_of_sale/static/tests/tours/helpers/PaymentScreenTourMethods.js +++ b/addons/point_of_sale/static/tests/tours/helpers/PaymentScreenTourMethods.js @@ -194,6 +194,15 @@ class Check { }, ]; } + totalDueIs(amount) { + return [ + { + content: `total due is ${amount}`, + trigger: `.payment-status-total-due:contains("${amount}")`, + run: () => {}, + }, + ]; + } } class Execute { diff --git a/addons/point_of_sale/tests/test_frontend.py b/addons/point_of_sale/tests/test_frontend.py index b8fb220c469..d7e40ca0b27 100644 --- a/addons/point_of_sale/tests/test_frontend.py +++ b/addons/point_of_sale/tests/test_frontend.py @@ -633,6 +633,7 @@ class TestUi(TestPointOfSaleHttpCommon): self.main_pos_config.open_ui() self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PaymentScreenRoundingDown', login="accountman") + self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PaymentScreenTotalDueWithOverPayment', login="accountman") def test_rounding_half_up(self): rouding_method = self.env['account.cash.rounding'].create({