From 46f21183c9f9fef8958dfbbd46c77671ca3764a0 Mon Sep 17 00:00:00 2001 From: pedrambiria Date: Tue, 6 Jun 2023 10:35:48 +0000 Subject: [PATCH] [FIX] point_of_sale: correctly compute the cash_register_balance_end Before this commit, 'last_session' inaccurately returned the newest session, which was incorrect as the first session technically has no preceding session. This update ensures that `last_session` does not return any session when it is the first instance. Also, the computation for the `cash_register_total_entry_encoding` when the session is closed was incorrect, and it did sum the cash difference which led to incorrect computation. opw-3302489 closes odoo/odoo#127572 X-original-commit: cbda861f3c2a2b39490b7148bcbba28f42f66285 Signed-off-by: Joseph Caburnay (jcb) Signed-off-by: Pedram Bi Ria (pebr) --- addons/point_of_sale/models/pos_session.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 75d14c290b5..b548119633a 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -78,6 +78,8 @@ class PosSession(models.Model): string='Before Closing Difference', help="Difference between the theoretical closing balance and the real closing balance.", readonly=True) + + # Total Cash In/Out cash_real_transaction = fields.Monetary(string='Transaction', readonly=True) order_ids = fields.One2many('pos.order', 'session_id', string='Orders') @@ -113,9 +115,11 @@ class PosSession(models.Model): last_session = session.search([('config_id', '=', session.config_id.id), ('id', '!=', session.id)], limit=1) result = self.env['pos.payment']._read_group([('session_id', '=', session.id), ('payment_method_id', '=', cash_payment_method.id)], aggregates=['amount:sum']) total_cash_payment = result[0][0] or 0.0 - session.cash_register_total_entry_encoding = sum(session.statement_line_ids.mapped('amount')) + ( - 0.0 if session.state == 'closed' else total_cash_payment - ) + if session.state == 'closed': + session.cash_register_total_entry_encoding = session.cash_real_transaction + total_cash_payment + else: + session.cash_register_total_entry_encoding = sum(session.statement_line_ids.mapped('amount')) + total_cash_payment + session.cash_register_balance_end = last_session.cash_register_balance_end_real + session.cash_register_total_entry_encoding session.cash_register_difference = session.cash_register_balance_end_real - session.cash_register_balance_end else: