4.8 KiB
4.8 KiB
Amount Calculation Fix Guide
Problem Description
Some payments with deductions may show incorrect amounts in the UI due to synchronization issues between the payment record and the journal entry. This typically happens when:
- A payment is created with deductions
- The payment is posted (journal entry created)
- Odoo's synchronization mechanism tries to update the payment amount based on the journal entry
- The amount gets incorrectly set to the final payment amount instead of the original amount
Symptoms
- Amount field shows the final payment amount (after deductions) instead of the original amount
- Final Payment Amount field shows an incorrect value
- The journal entry is correct, but the payment record shows wrong amounts
Example
Expected:
- Amount: 8,557,500.00 (original amount)
- Total Deductions: 92,000.00
- Final Payment Amount: 8,465,500.00 (8,557,500 - 92,000)
Actual (incorrect):
- Amount: 6,465,500.00 (wrong - this is some other calculation)
- Final Payment Amount: 8,373,500.00 (wrong)
Solutions
Solution 1: Use the Fix Button (Recommended)
- Open the payment with incorrect amounts
- Look for the "Fix Amount" button next to the Final Payment Amount field
- Click the button to automatically fix the calculation
- The amounts should now be correct
Solution 2: Use the Fix Wizard
- Go to Accounting > Configuration > Fix Payment Amounts
- The wizard will automatically detect payments with incorrect amounts
- Review the list of payments to fix
- Click "Fix Amounts" to correct all selected payments
Solution 3: Manual Fix via Code
If you have access to Odoo shell, you can run the fix script:
# Open Odoo shell
python odoo-bin shell -d your_database
# Run the fix for all payments
env['account.payment'].fix_all_payment_amounts()
# Or fix a specific payment
payment = env['account.payment'].search([('name', '=', 'PBCA5858/2025/00061')])
payment.action_fix_amount_calculation()
Solution 4: Use the Python Script
Run the provided fix script:
# Copy the fix script to your Odoo directory
cp customaddons/vendor_payment_diff_amount/fix_amount_issue.py /path/to/odoo/
# Open Odoo shell
python odoo-bin shell -d your_database
# Run the script
exec(open('fix_amount_issue.py').read())
# Check a specific payment
check_specific_payment('PBCA5858/2025/00061')
# Fix all payments
fix_payment_amounts()
How the Fix Works
The fix works by:
- Finding the correct amount from the journal entry's counterpart line (payable/expense line with debit)
- Updating the payment amount to match the journal entry
- Recalculating the final payment amount using the formula:
final_payment_amount = amount - amount_substract
Prevention
To prevent this issue in the future, the module has been updated with:
- Improved synchronization logic that prevents incorrect amount updates
- Write method override that blocks amount changes for posted payments with deductions
- Better error handling for synchronization edge cases
Verification
After applying the fix, verify that:
- Amount field shows the original payment amount (before deductions)
- Total Deductions field shows the sum of all deduction lines
- Final Payment Amount field shows
Amount - Total Deductions - Journal entry remains unchanged and balanced
- Bank account is credited with the Final Payment Amount
- Payable/Expense account is debited with the original Amount
- Deduction accounts are credited with their respective amounts
Example Verification
For payment PBCA5858/2025/00061:
Payment Record:
- Amount: 8,557,500.00 ✓
- Total Deductions: 92,000.00 ✓
- Final Payment Amount: 8,465,500.00 ✓
Journal Entry:
- Payable/Expense (Debit): 8,557,500.00 ✓
- Deduction accounts (Credit): 92,000.00 total ✓
- Bank (Credit): 8,465,500.00 ✓
- Total: Debit 8,557,500.00 = Credit 8,557,500.00 ✓
Support
If you continue to experience issues:
- Check the Odoo logs for any error messages
- Verify that the deduction accounts are not payable/receivable accounts
- Ensure the payment has a valid partner and journal
- Contact support with the payment name/ID and error details
Technical Details
The issue occurs because Odoo's _synchronize_from_moves method tries to keep the payment amount in sync with the journal entry. However, when we have deductions:
- The journal entry has the original amount on the payable/expense line
- The bank line has the reduced amount (final payment amount)
- Odoo's sync logic sometimes picks the wrong line to sync from
The fix ensures that:
- The payment amount always reflects the original amount (from payable/expense line)
- The final payment amount is always calculated as
amount - deductions - Synchronization doesn't overwrite correct amounts for posted payments