Account Credit Allocation Documentation¶
Overview¶
The Account Credit Allocation model (account.credit.alloc) manages the allocation of credits (from credit notes, prepayments, or overpayments) against invoices. It tracks which credits have been applied to which invoices and maintains the journal entry relationships.
Note: This model is marked as deprecated in the codebase. The post() method is commented out, indicating that credit allocation may now be handled through other mechanisms.
Model Information¶
Model Name: account.credit.alloc
Display Name: Credit Allocation
Key Fields: None (no unique constraint defined)
Features¶
- ❌ Audit logging enabled (
_audit_log) - ❌ Multi-company support (
company_id) - ❌ Full-text content search (
_content_search) - ⚠️ DEPRECATED - Limited functionality
Key Fields Reference¶
All Fields¶
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id |
Many2One | ✅ | Invoice receiving the credit |
credit_id |
Many2One | ❌ | Credit note being applied |
credit_move_id |
Many2One | ❌ | Credit journal entry |
credit_type |
Char | ❌ | Type of credit (computed from credit_id.inv_type) |
amount |
Decimal | ❌ | Allocation amount |
move_id |
Many2One | ❌ | Allocation journal entry |
date |
Date | ✅ | Allocation date |
Default Values¶
API Methods¶
1. Create Allocation¶
Method: create(vals, **kw)
Creates a new credit allocation and updates related invoice function stores.
Behavior: 1. Creates the allocation record 2. Collects affected invoice IDs (both invoice and credit) 3. Updates function store on related invoices
Example:
alloc_id = get_model("account.credit.alloc").create({
"invoice_id": invoice_id,
"credit_id": credit_note_id,
"amount": 500.00,
"date": "2024-12-15",
})
2. Delete Allocation¶
Method: delete(ids, **kw)
Deletes credit allocations and voids/deletes related journal entries.
Behavior: 1. Collects affected invoice IDs 2. Voids and deletes allocation journal entries 3. Deletes allocation records 4. Updates function store on related invoices
Example:
3. Post Allocation (DEPRECATED)¶
Method: post(ids, context) - COMMENTED OUT
The posting functionality is deprecated. The commented code shows the previous behavior: - Created journal entries for credit allocation - Posted entries to GL - Reconciled invoice and credit note lines
Related Models¶
| Model | Relationship | Description |
|---|---|---|
account.invoice |
Many2One (invoice_id) | Invoice being paid |
account.invoice |
Many2One (credit_id) | Credit note being applied |
account.move |
Many2One (move_id) | Allocation journal entry |
account.move |
Many2One (credit_move_id) | Credit journal entry |
Credit Types¶
The credit_type field is computed from the linked credit invoice:
| Type | Code | Description |
|---|---|---|
| Credit Note | credit |
Credit for returns/corrections |
| Prepayment | prepay |
Advance payment |
| Overpayment | overpay |
Excess payment |
Common Use Cases¶
Use Case 1: Record Credit Application¶
# Apply credit note to invoice
alloc_id = get_model("account.credit.alloc").create({
"invoice_id": invoice_id,
"credit_id": credit_note_id,
"amount": 200.00,
"date": "2024-12-15",
})
Use Case 2: Track Credit Allocations¶
# Find all allocations for an invoice
allocations = get_model("account.credit.alloc").search_browse([
["invoice_id", "=", invoice_id]
])
total_credits = sum(alloc.amount for alloc in allocations)
print(f"Total credits applied: {total_credits}")
for alloc in allocations:
print(f" Credit: {alloc.credit_id.number} - {alloc.amount}")
Use Case 3: Find Credits Applied¶
# Find where a credit note was applied
allocations = get_model("account.credit.alloc").search_browse([
["credit_id", "=", credit_note_id]
])
total_used = sum(alloc.amount for alloc in allocations)
print(f"Credit note used: {total_used}")
for alloc in allocations:
print(f" Applied to: {alloc.invoice_id.number} - {alloc.amount}")
Deprecation Notes¶
This model is marked as deprecated (# XXX: deprecated). Key observations:
- Post method commented out: The
post()method that created journal entries is disabled - Limited functionality: Only create/delete operations are fully functional
- Alternative mechanisms: Credit allocation may now be handled through:
- Payment allocation (
account.payment.line) - Credit wizard (
account.credit.wizard) - Direct invoice reconciliation
Migration Guidance¶
If using this model, consider migrating to:
- Payment-based allocation: Use
account.paymentwith credit note payments - Wizard-based allocation: Use
account.credit.wizardfor user-driven allocation - Direct invoice methods: Use invoice model's built-in credit allocation methods
Best Practices¶
1. Check for Deprecated Usage¶
2. Prefer Modern Alternatives¶
# Consider using payment-based allocation instead
# get_model("account.payment") for credit application
Troubleshooting¶
"Journal entry not created"¶
Cause: Post method is deprecated/disabled Solution: Use alternative credit allocation methods
"Invoice balance not updating"¶
Cause: Function store may not trigger properly Solution: Manually call function_store on invoices
"Credit type is empty"¶
Cause: credit_id not set or invalid Solution: Ensure valid credit_id is provided
Testing Examples¶
Unit Test: Credit Allocation Record¶
def test_credit_allocation():
# Create allocation record
alloc_id = get_model("account.credit.alloc").create({
"invoice_id": invoice_id,
"credit_id": credit_note_id,
"amount": 100.00,
"date": "2024-12-15",
})
# Verify
alloc = get_model("account.credit.alloc").browse([alloc_id])[0]
assert alloc.invoice_id.id == invoice_id
assert alloc.credit_id.id == credit_note_id
assert alloc.amount == 100.00
# Cleanup
get_model("account.credit.alloc").delete([alloc_id])
Security Considerations¶
Permission Model¶
- Requires invoice and credit note access
- Journal entry permissions for posting (if enabled)
Data Access¶
- Credit allocations link sensitive financial data
- Deletion affects journal entries
Version History¶
Last Updated: December 2024 Model Version: account_credit_alloc.py Status: Deprecated Framework: Netforce
Additional Resources¶
- Invoice Documentation:
account.invoice - Payment Documentation:
account.payment - Credit Wizard Documentation:
account.credit.wizard - Journal Entry Documentation:
account.move
This documentation is generated for developer onboarding and reference purposes.