From dbc106a070021d39301eaf034240484c3004c89c Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Tue, 31 Mar 2026 12:07:41 +0700 Subject: [PATCH] refactor: update cash adjustment logic to suppress shortages instead of surpluses during POS session closing --- README.md | 6 ++++-- models/pos_session.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3de6109..e57670f 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,15 @@ **License:** LGPL-3 ## Summary -Prevents unwanted journal entries by handling zero-amount payments and automatically adjusting negative cash differences during POS session closing. +Prevents unwanted journal entries by handling zero-amount payments and automatically adjusting negative cash differences (shortages) during POS session closing. ## Features - **Phantom Difference Prevention:** Relies on standard Odoo mechanisms to ensure no journal items are created when the expected cash mathematically matches the inputted cash (e.g. opening with 150k and closing with 150k, or opening with 200k, selling 100k, and closing with 300k). +- **Shortage Suppression:** Automatically adjusts the real balance to match the expected balance when a shortage is detected, avoiding loss/expense journal entries. +- **Surplus Recording:** Allows standard Odoo behavior to record a surplus as a profit journal entry. ## Technical Details ### Validation Override The module overrides `_validate_session` in `pos.session`: -1. **Auto-Adjustment:** Detects if `cash_register_balance_end_real` is greater than `cash_register_balance_end`. If so, it overrides the real balance to match the expected balance *before* standard accounting lines are generated, avoiding the creation of profit lines. +1. **Auto-Adjustment:** If `cash_register_balance_end_real` is greater than `cash_register_balance_end` (Cash Surplus), it records the difference using standard Odoo accounting. If `cash_register_balance_end_real` is lower than `cash_register_balance_end` (Cash Shortage), it overrides the real balance to match the expected balance *before* standard accounting lines are generated, avoiding the creation of cash diff (loss) journal entries. 2. **Zero-Amount Fix:** Iterates through all orders in the session and unlinks any payment lines where the amount is considered zero by the session's currency. diff --git a/models/pos_session.py b/models/pos_session.py index bc02a0d..5bd2cc4 100755 --- a/models/pos_session.py +++ b/models/pos_session.py @@ -124,8 +124,8 @@ class PosSession(models.Model): for session in self: if session.config_id.cash_control: difference = session.cash_register_balance_end_real - session.cash_register_balance_end - if session.currency_id.compare_amounts(difference, 0.0) > 0: - session.message_post(body="Auto-adjustment: Cashier input %s overridden to expected %s to suppress positive difference of %s." % ( + if session.currency_id.compare_amounts(difference, 0.0) < 0: + session.message_post(body="Auto-adjustment: Cashier input %s overridden to expected %s to suppress negative difference (shortage) of %s." % ( session.currency_id.format(session.cash_register_balance_end_real), session.currency_id.format(session.cash_register_balance_end), session.currency_id.format(difference)