[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) <jcb@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
This commit is contained in:
pedrambiria
2023-07-06 19:46:35 +02:00
committed by Pedram (PEBR)
parent c5e6ed536b
commit 46f21183c9
+7 -3
View File
@@ -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: