From 9ba75d9098330a8b411bff8c9051a588a86ca65b Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 23 Feb 2026 10:44:34 +0700 Subject: [PATCH] fix: Invert POS cash auto-adjustment to suppress positive differences and update documentation accordingly. --- README.md | 4 +--- models/pos_session.py | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cccf21b..3de6109 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,10 @@ Prevents unwanted journal entries by handling zero-amount payments and automatically adjusting negative cash differences during POS session closing. ## Features -- **Negative Cash Closing Adjustment:** Automatically overrides the cashier's inputted cash amount to match the expected closing balance if a cash shortage (negative difference) is detected. This silently prevents Odoo from generating a Cash Difference Loss journal entry, and logs the auto-adjustment in the session's chatter instead. -- **Zero-Amount Payment Cleanup:** Automatically removes `pos.payment` lines with `0.00` amount during session verification. This prevents the creation of "Difference at closing PoS session" journal items triggered by empty payments (e.g., from 100% discount or external payment edge cases). - **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). ## Technical Details ### Validation Override The module overrides `_validate_session` in `pos.session`: -1. **Auto-Adjustment:** Detects if `cash_register_balance_end_real` is less 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 loss lines. +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. 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 c62b3e6..bc02a0d 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 negative 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 positive difference 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)