From bfe6f3e9b0315424713633581a658be516af7dda Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Thu, 23 Feb 2023 13:23:16 +0000 Subject: [PATCH] [FIX] point_of_sale: correct starting balance for rescue session Current behavior: The rescue session are created with a starting balance of 0.00. When the starting balance should be the end balance of the previous session. Steps to reproduce: - Open a POS session on 2 different browsers - Make an order on the first browser, and close the session - Make an order on the second browser, and close the session - The second browser's session will be in rescue mode and the starting balance will be 0.00 when it should be the end balance of the first session. opw-3136236 closes odoo/odoo#115258 X-original-commit: 265817f7d7d096be4a84a7dd710c1dabb93fe402 Signed-off-by: Trinh Jacky (trj) Signed-off-by: Engels Robin (roen) --- addons/point_of_sale/models/pos_order.py | 3 +++ addons/point_of_sale/tests/test_point_of_sale_flow.py | 1 + 2 files changed, 4 insertions(+) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 061e381438e..40b6cbbfa34 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -105,6 +105,9 @@ class PosOrder(models.Model): }) # bypass opening_control (necessary when using cash control) new_session.action_pos_session_open() + if new_session.config_id.cash_control and new_session.rescue: + last_session = self.env['pos.session'].search([('config_id', '=', new_session.config_id.id), ('id', '!=', new_session.id)], limit=1) + new_session.cash_register_balance_start = last_session.cash_register_balance_end_real return new_session diff --git a/addons/point_of_sale/tests/test_point_of_sale_flow.py b/addons/point_of_sale/tests/test_point_of_sale_flow.py index 17842c592f2..cfde83c9eaf 100644 --- a/addons/point_of_sale/tests/test_point_of_sale_flow.py +++ b/addons/point_of_sale/tests/test_point_of_sale_flow.py @@ -688,6 +688,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): rescue_session.post_closing_cash_details(total_cash_payment) rescue_session.close_session_from_ui() self.assertEqual(rescue_session.state, 'closed', "Rescue session was not properly closed") + self.assertEqual(rescue_session.cash_register_balance_start, current_session.cash_register_balance_end_real, "Rescue session does not start with the same amount as the previous session") def test_order_to_payment_currency(self): """