fix: prevent duplicate deduction accounting entries and update documentation to reStructuredText format

This commit is contained in:
Suherdy Yacob 2026-05-06 11:32:43 +07:00
parent 7e2c132f1b
commit 4034d66cdc
3 changed files with 153 additions and 123 deletions

123
README.md
View File

@ -1,123 +0,0 @@
# Vendor Payment Diff Amount - Version 2.0
## Overview
This module extends Odoo 17's vendor payment functionality to support **multiple payment deductions** such as withholding tax, payment fees, and other charges.
## Version 2.0 Changes
### Major Update: One2Many Deduction Lines
Version 2.0 introduces a significant architectural change:
**Before (v1.x):**
- Single deduction amount field (`amount_substract`)
- Single deduction account field (`substract_account_id`)
- One payment could have only one deduction
**After (v2.0):**
- Multiple deduction lines (`deduction_line_ids`)
- Each deduction line has its own amount and account
- One payment can have multiple deductions with different accounts
- Total deductions computed automatically
### Migration Notes
**Important:** This is a breaking change. Existing payments with deductions will need to be migrated.
If you have existing payments with `amount_substract` and `substract_account_id` values, you should:
1. Backup your database before upgrading
2. After upgrade, existing single deductions will need to be manually converted to deduction lines
3. The old fields (`amount_substract`, `substract_account_id`) are now computed/removed
### New Features
1. **Multiple Deduction Lines**: Add as many deduction lines as needed to a single payment
2. **Individual Descriptions**: Each deduction can have its own description
3. **Flexible Sequencing**: Reorder deduction lines using drag-and-drop
4. **Automatic Totals**: Total deductions calculated automatically
5. **Batch Payment Support**: Deduction lines work seamlessly with batch payments
## Usage
### ⚠️ IMPORTANT: Expense Account Required
**When using payment deductions, you MUST set the Expense Account field first.**
### Creating a Payment with Deductions
1. Go to Accounting > Vendors > Payments
2. Create a new outbound payment
3. **⚠️ CRITICAL: Set the Expense Account field** (e.g., "Telepon & Internet")
4. Enter the payment amount
5. In the "Deductions" section, add one or more deduction lines:
- Select the deduction account (e.g., PPh 21 - Withholding Tax)
- Enter the deduction amount
- Optionally add a description
6. The "Total Deductions" and "Final Payment Amount" are calculated automatically
7. Post the payment
**Note:** If you try to add deductions without setting the Expense Account, you will get a validation error.
### Journal Entry Structure
For a payment of 2000 with two deductions (100 for tax, 50 for fees):
```
Expense/Payable Account Debit: 2000 (original amount)
Tax Account (PPh 21) Credit: 100 (first deduction)
Fee Account (PPh 29) Credit: 50 (second deduction)
Bank Account Credit: 1850 (final payment amount)
---
Total: Debit 2000 = Credit 2000 (balanced)
```
### Batch Payments
When using with `vendor_batch_payment_merge`:
1. Create a batch payment
2. Add payment lines
3. For each line, add deduction lines in the form view
4. Generate payments - deductions are automatically transferred
## Technical Details
### New Models
- `payment.deduction.line`: Stores individual deduction lines
### Modified Models
- `account.payment`: Added `deduction_line_ids` (One2many)
- `account.batch.payment.line`: Added `deduction_line_ids` (One2many)
### Fields
**Payment Deduction Line:**
- `sequence`: Order of deduction lines
- `substract_account_id`: Account for this deduction (required)
- `amount_substract`: Deduction amount (required)
- `name`: Optional description
- `payment_id`: Link to payment
- `batch_payment_line_id`: Link to batch payment line
**Account Payment:**
- `deduction_line_ids`: One2many to deduction lines
- `amount_substract`: Computed total of all deductions
- `final_payment_amount`: Computed (amount - total deductions)
## Requirements
- Odoo 17.0
- `account` module
- `vendor_batch_payment_merge` module
## License
LGPL-3
## Author
Suherdy Yacob

143
README.rst Normal file
View File

@ -0,0 +1,143 @@
==========================================
Vendor Payment Diff Amount - Version 2.0
==========================================
Overview
========
This module extends Odoo's vendor payment functionality to support **multiple payment deductions**
such as withholding tax, payment fees, and other charges.
Version 2.0 Changes
===================
Major Update: One2Many Deduction Lines
--------------------------------------
Version 2.0 introduces a significant architectural change:
**Before (v1.x):**
* Single deduction amount field (`amount_substract`)
* Single deduction account field (`substract_account_id`)
* One payment could have only one deduction
**After (v2.0):**
* Multiple deduction lines (`deduction_line_ids`)
* Each deduction line has its own amount and account
* One payment can have multiple deductions with different accounts
* Total deductions computed automatically
Migration Notes
---------------
**Important:** This is a breaking change. Existing payments with deductions will need to be migrated.
If you have existing payments with `amount_substract` and `substract_account_id` values, you should:
1. Backup your database before upgrading
2. After upgrade, existing single deductions will need to be manually converted to deduction lines
3. The old fields (`amount_substract`, `substract_account_id`) are now computed/removed
New Features
------------
1. **Multiple Deduction Lines**: Add as many deduction lines as needed to a single payment
2. **Individual Descriptions**: Each deduction can have its own description
3. **Flexible Sequencing**: Reorder deduction lines using drag-and-drop
4. **Automatic Totals**: Total deductions calculated automatically
5. **Batch Payment Support**: Deduction lines work seamlessly with batch payments
Usage
=====
⚠️ IMPORTANT: Expense Account Required
--------------------------------------
**When using payment deductions, you MUST set the Expense Account field first.**
Creating a Payment with Deductions
----------------------------------
1. Go to Accounting > Vendors > Payments
2. Create a new outbound payment
3. **⚠️ CRITICAL: Set the Expense Account field** (e.g., "Telepon & Internet")
4. Enter the payment amount
5. In the "Deductions" section, add one or more deduction lines:
* Select the deduction account (e.g., PPh 21 - Withholding Tax)
* Enter the deduction amount
* Optionally add a description
6. The "Total Deductions" and "Final Payment Amount" are calculated automatically
7. Post the payment
**Note:** If you try to add deductions without setting the Expense Account, you will get a validation error.
Journal Entry Structure
-----------------------
For a payment of 2000 with two deductions (100 for tax, 50 for fees):
::
Expense/Payable Account Debit: 2000 (original amount)
Tax Account (PPh 21) Credit: 100 (first deduction)
Fee Account (PPh 29) Credit: 50 (second deduction)
Bank Account Credit: 1850 (final payment amount)
---
Total: Debit 2000 = Credit 2000 (balanced)
Batch Payments
--------------
When using with `vendor_batch_payment_merge`:
1. Create a batch payment
2. Add payment lines
3. For each line, add deduction lines in the form view
4. Generate payments - deductions are automatically transferred
Technical Details
=================
New Models
----------
* `payment.deduction.line`: Stores individual deduction lines
Modified Models
---------------
* `account.payment`: Added `deduction_line_ids` (One2many)
* `account.batch.payment.line`: Added `deduction_line_ids` (One2many)
Fields
------
**Payment Deduction Line:**
* `sequence`: Order of deduction lines
* `substract_account_id`: Account for this deduction (required)
* `amount_substract`: Deduction amount (required)
* `name`: Optional description
* `payment_id`: Link to payment
* `batch_payment_line_id`: Link to batch payment line
**Account Payment:**
* `deduction_line_ids`: One2many to deduction lines
* `amount_substract`: Computed total of all deductions
* `final_payment_amount`: Computed (amount - total deductions)
Requirements
============
* Odoo 17.0+
* `account` module
* `vendor_batch_payment_merge` module
License
=======
LGPL-3
Author
======
Suherdy Yacob

View File

@ -243,6 +243,16 @@ class AccountPayment(models.Model):
- Bank: credit 1850 (final_payment_amount)
Total: debit 2000 = credit 2000 (balanced)
"""
# Filter out existing deductions from write_off_line_vals to prevent double counting
# by Odoo's native balancing logic.
if write_off_line_vals and self.deduction_line_ids:
deduction_account_ids = self.deduction_line_ids.mapped('substract_account_id').ids
filtered_write_offs = []
for w in write_off_line_vals:
if w.get('account_id') not in deduction_account_ids:
filtered_write_offs.append(w)
write_off_line_vals = filtered_write_offs
# Get standard line values from parent
line_vals_list = super()._prepare_move_line_default_vals(write_off_line_vals, force_balance)