174 lines
5.4 KiB
Markdown
174 lines
5.4 KiB
Markdown
# Fix Summary: "Missing required account on accountable line" Error
|
|
|
|
## Problem
|
|
|
|
When creating a vendor payment with deductions, the system threw the error:
|
|
```
|
|
The operation cannot be completed: Missing required account on accountable line.
|
|
```
|
|
|
|
This occurred because Odoo validates that lines with payable/receivable accounts must have a `partner_id` set.
|
|
|
|
## Root Cause
|
|
|
|
The issue had two parts:
|
|
|
|
1. **Deduction lines were incorrectly getting `partner_id`**: All deduction lines were being created with `partner_id`, but deduction accounts (like tax accounts) are typically NOT payable/receivable accounts and should NOT have a partner.
|
|
|
|
2. **Odoo's validation**: When a line has a payable/receivable account type, Odoo requires the `partner_id` field. When a line has other account types (expense, liability, etc.), the `partner_id` should be optional or omitted.
|
|
|
|
## Solution
|
|
|
|
Modified the `_prepare_move_line_default_vals` method to:
|
|
|
|
1. **Ensure counterpart line has partner**: The payable/expense line (counterpart) always gets `partner_id` set
|
|
2. **Conditional partner on deduction lines**: Only add `partner_id` to deduction lines if the account type requires it
|
|
|
|
### Code Change
|
|
|
|
**Before:**
|
|
```python
|
|
deduction_line = {
|
|
'name': deduction_line_name,
|
|
'date_maturity': self.date,
|
|
'amount_currency': -deduction.amount_substract,
|
|
'currency_id': self.currency_id.id,
|
|
'debit': 0.0,
|
|
'credit': deduction_balance,
|
|
'partner_id': self.partner_id.id, # ❌ Always added
|
|
'account_id': deduction.substract_account_id.id,
|
|
}
|
|
```
|
|
|
|
**After:**
|
|
```python
|
|
deduction_line = {
|
|
'name': deduction_line_name,
|
|
'date_maturity': self.date,
|
|
'amount_currency': -deduction.amount_substract,
|
|
'currency_id': self.currency_id.id,
|
|
'debit': 0.0,
|
|
'credit': deduction_balance,
|
|
'account_id': deduction.substract_account_id.id,
|
|
}
|
|
|
|
# Only add partner_id if the account requires it
|
|
if deduction.substract_account_id.account_type in ('asset_receivable', 'liability_payable'):
|
|
deduction_line['partner_id'] = self.partner_id.id # ✅ Conditionally added
|
|
```
|
|
|
|
## Account Types
|
|
|
|
### Accounts that REQUIRE partner_id:
|
|
- `asset_receivable` (Customer accounts)
|
|
- `liability_payable` (Vendor accounts)
|
|
|
|
### Accounts that DON'T need partner_id:
|
|
- `liability_current` (Tax payable accounts like PPh 21, PPh 29)
|
|
- `expense` (Expense accounts)
|
|
- `income` (Income accounts)
|
|
- `asset_cash` (Bank accounts)
|
|
- All other account types
|
|
|
|
## Result
|
|
|
|
Now the journal entry is created correctly:
|
|
|
|
### Example: Payment Rp 2,000,000 with PPh 21 (Rp 100,000) and PPh 29 (Rp 50,000)
|
|
|
|
```
|
|
Account | Debit | Credit | Partner
|
|
-------------------------------------|-----------------|-----------------|------------------
|
|
Accounts Payable | Rp 2,000,000.00 | | PT Telkom ✅
|
|
PPh 21 (Tax Payable) | | Rp 100,000.00 | (none) ✅
|
|
PPh 29 (Tax Payable) | | Rp 50,000.00 | (none) ✅
|
|
Bank Account | | Rp 1,850,000.00 | (none) ✅
|
|
-------------------------------------|-----------------|-----------------|------------------
|
|
TOTAL | Rp 2,000,000.00 | Rp 2,000,000.00 |
|
|
```
|
|
|
|
### Key Points:
|
|
- ✅ Payable account has partner (required)
|
|
- ✅ Tax accounts don't have partner (correct)
|
|
- ✅ Bank account doesn't have partner (correct)
|
|
- ✅ Entry is balanced
|
|
- ✅ No validation errors
|
|
|
|
## Testing
|
|
|
|
To test the fix:
|
|
|
|
1. **Create a payment without expense account:**
|
|
```
|
|
- Partner: Any vendor
|
|
- Amount: 1000
|
|
- Deduction: PPh 21 - 100 (use a tax account)
|
|
- Result: Should post successfully
|
|
```
|
|
|
|
2. **Create a payment with expense account:**
|
|
```
|
|
- Partner: Any vendor
|
|
- Amount: 2000
|
|
- Expense Account: Telepon & Internet
|
|
- Deduction 1: PPh 21 - 100
|
|
- Deduction 2: PPh 29 - 50
|
|
- Result: Should post successfully
|
|
```
|
|
|
|
3. **Verify journal entries:**
|
|
- Check that payable/expense line has partner
|
|
- Check that tax lines don't have partner
|
|
- Check that entry is balanced
|
|
|
|
## Important Notes
|
|
|
|
### Deduction Account Selection
|
|
|
|
When adding deductions, make sure to use the correct account types:
|
|
|
|
✅ **Correct accounts for deductions:**
|
|
- Tax payable accounts (PPh 21, PPh 23, PPh 29, etc.)
|
|
- Expense accounts (if recording as expense)
|
|
- Liability accounts (for other withholdings)
|
|
|
|
❌ **Don't use these for deductions:**
|
|
- Accounts Payable (vendor accounts)
|
|
- Accounts Receivable (customer accounts)
|
|
|
|
### Why This Matters
|
|
|
|
Using payable/receivable accounts for deductions would create confusion:
|
|
- It would require a partner on the deduction line
|
|
- It would mix vendor payables with tax payables
|
|
- It would complicate reconciliation
|
|
- It's not the correct accounting treatment
|
|
|
|
## Files Modified
|
|
|
|
1. **`models/account_payment.py`**
|
|
- Added conditional `partner_id` logic for deduction lines
|
|
- Ensured counterpart line always has `partner_id`
|
|
|
|
2. **`SCENARIOS.md`**
|
|
- Updated validation rules
|
|
- Added explanation about partner_id handling
|
|
- Updated troubleshooting section
|
|
|
|
3. **`FIX_SUMMARY.md`** (this file)
|
|
- Documented the fix and reasoning
|
|
|
|
## Version
|
|
|
|
This fix is included in version 2.0.0 of the module.
|
|
|
|
## Related Issues
|
|
|
|
- "Missing required account on accountable line" error
|
|
- Partner validation on journal entry lines
|
|
- Deduction account configuration
|
|
|
|
## Credits
|
|
|
|
Fixed based on user feedback and testing with real-world scenarios.
|