145 lines
4.8 KiB
Markdown
145 lines
4.8 KiB
Markdown
# 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:
|
|
|
|
1. A payment is created with deductions
|
|
2. The payment is posted (journal entry created)
|
|
3. Odoo's synchronization mechanism tries to update the payment amount based on the journal entry
|
|
4. 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)
|
|
|
|
1. Open the payment with incorrect amounts
|
|
2. Look for the "Fix Amount" button next to the Final Payment Amount field
|
|
3. Click the button to automatically fix the calculation
|
|
4. The amounts should now be correct
|
|
|
|
### Solution 2: Use the Fix Wizard
|
|
|
|
1. Go to **Accounting > Configuration > Fix Payment Amounts**
|
|
2. The wizard will automatically detect payments with incorrect amounts
|
|
3. Review the list of payments to fix
|
|
4. 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:
|
|
|
|
```python
|
|
# 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:
|
|
|
|
```bash
|
|
# 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:
|
|
|
|
1. **Finding the correct amount** from the journal entry's counterpart line (payable/expense line with debit)
|
|
2. **Updating the payment amount** to match the journal entry
|
|
3. **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:
|
|
|
|
1. **Improved synchronization logic** that prevents incorrect amount updates
|
|
2. **Write method override** that blocks amount changes for posted payments with deductions
|
|
3. **Better error handling** for synchronization edge cases
|
|
|
|
## Verification
|
|
|
|
After applying the fix, verify that:
|
|
|
|
1. **Amount field** shows the original payment amount (before deductions)
|
|
2. **Total Deductions field** shows the sum of all deduction lines
|
|
3. **Final Payment Amount field** shows `Amount - Total Deductions`
|
|
4. **Journal entry** remains unchanged and balanced
|
|
5. **Bank account** is credited with the Final Payment Amount
|
|
6. **Payable/Expense account** is debited with the original Amount
|
|
7. **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:
|
|
|
|
1. Check the Odoo logs for any error messages
|
|
2. Verify that the deduction accounts are not payable/receivable accounts
|
|
3. Ensure the payment has a valid partner and journal
|
|
4. 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 |