fix the journal entry for opening cash

This commit is contained in:
admin.suherdy 2025-11-07 17:08:24 +07:00
parent 20a99ff92d
commit 7fb38ceb8b
4 changed files with 43 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
import logging
from odoo import api, fields, models
_logger = logging.getLogger(__name__)
class PosSession(models.Model):
_inherit = "pos.session"
@ -48,11 +52,25 @@ 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,
@ -63,6 +81,31 @@ class PosSession(models.Model):
session._post_cash_details_message("Opening", difference, notes)
return True
def _get_opening_float_amount(self):
self.ensure_one()
if not self.config_id.cash_control:
return 0.0
opening_amount = self.opening_cash_counted
if self.currency_id.is_zero(opening_amount or 0.0):
opening_amount = self.opening_cash_expected
return opening_amount or 0.0
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,
)
continue
super(PosSession, session)._post_statement_difference(session_amount, is_opening)
@api.depends("payment_method_ids", "order_ids", "cash_register_balance_start", "cash_real_transaction", "statement_line_ids")
def _compute_cash_balance(self):
for session in self: