fix the calculation of opening cash and closing cash when there are some difference

This commit is contained in:
admin.suherdy 2025-11-07 19:34:27 +07:00
parent 7fb38ceb8b
commit fdad209a02
2 changed files with 5 additions and 28 deletions

View File

@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-
import logging
from odoo import api, fields, models
_logger = logging.getLogger(__name__)
class PosSession(models.Model):
_inherit = "pos.session"
@ -52,25 +48,11 @@ class PosSession(models.Model):
return res
def set_cashbox_pos(self, cashbox_value: int, notes: str):
_logger.debug(
"POS cash opening adjustment: set_cashbox_pos called for session_ids=%s, cashbox_value=%s, notes=%s",
self.ids,
cashbox_value,
notes,
)
for session in self:
expected = session.opening_cash_expected if session.config_id.cash_control else 0.0
if not session.config_id.cash_control:
expected = session.cash_register_balance_start or 0.0
difference = cashbox_value - (expected or 0.0)
_logger.debug(
"POS cash opening adjustment: session=%s expected=%s counted=%s difference=%s cash_control=%s",
session.id,
expected,
cashbox_value,
difference,
session.config_id.cash_control,
)
session.write({
"state": "opened",
"opening_notes": notes,
@ -93,16 +75,11 @@ class PosSession(models.Model):
def _post_statement_difference(self, amount, is_opening):
for session in self:
session_amount = amount
if not is_opening and session.config_id.cash_control:
opening_float = session._get_opening_float_amount()
if opening_float and session.currency_id.is_zero(session_amount + opening_float):
_logger.debug(
"POS cash opening adjustment: skipping difference posting for session %s "
"because it solely matches the opening float (amount=%s, opening_float=%s).",
session.id,
session_amount,
opening_float,
)
opening_float = session._get_opening_float_amount() if session.config_id.cash_control else 0.0
if not is_opening and opening_float:
if session.currency_id.compare_amounts(session.cash_register_balance_end_real, opening_float) <= 0:
session_amount += opening_float
if session.currency_id.is_zero(session_amount):
continue
super(PosSession, session)._post_statement_difference(session_amount, is_opening)