Invoice Credit Allocation Wizard Documentation¶
Overview¶
The Invoice Credit Allocation Wizard model (account.credit.wizard) provides an interface for applying available credits to an invoice. It finds credit notes, prepayments, and overpayments for the same contact and creates allocation journal entries.
Model Information¶
Model Name: account.credit.wizard
Display Name: Credit Wizard
Transient: Yes
Key Fields: None (transient model)
Features¶
- ✅ Transient model (temporary data)
- ❌ Audit logging enabled (
_audit_log) - ❌ Multi-company support (via company context)
- ✅ Auto-populates available credits
- ✅ Creates allocation journal entries
- ✅ Handles multi-currency allocations
- ✅ Currency gain/loss handling
Key Fields Reference¶
Header Fields¶
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id |
Many2One | ✅ | Invoice receiving credits |
type |
Char | ❌ | Invoice type (in/out) |
lines |
One2Many | ❌ | Credit lines available |
date |
Date | ❌ | Allocation date |
Computed Fields¶
| Field | Type | Description |
|---|---|---|
amount_due |
Decimal | Amount due on invoice |
amount_alloc |
Decimal | Total credits being applied |
amount_remain |
Decimal | Remaining due after allocation |
Default Values¶
API Methods¶
1. Default Get¶
Method: default_get(field_names={}, context={}, **kw)
Populates wizard with available credits for the contact.
Context:
- invoice_id: Invoice ID to apply credits to
Behavior: 1. Gets invoice details 2. Finds unreconciled credit lines for same contact 3. Handles multi-currency amounts 4. Calculates outstanding credit balances
2. Allocate¶
Method: allocate(ids, context={})
Creates allocation entries and reconciles lines.
Process: 1. Validates invoice type (not credit notes) 2. Validates no deferred recognition 3. For each credit line with amount: - Creates journal entry - Handles currency conversion - Posts entry - Creates currency gain/loss lines if needed - Reconciles invoice and credit lines 4. Updates invoice function store
Returns: Navigation to invoice view with flash message
Raises:
- Exception("Wrong invoice type")
- Exception("Can not allocate credit to deferred recognition invoices")
- Exception("Missing currency loss account")
3. Update Amounts¶
Method: update_amounts(context={})
Recalculates totals when line amounts change.
Related Models¶
| Model | Relationship | Description |
|---|---|---|
account.invoice |
Many2One (invoice_id) | Target invoice |
account.credit.wizard.line |
One2Many (lines) | Credit lines |
account.move |
Created | Allocation entries |
Common Use Cases¶
Use Case 1: Apply Credit to Invoice¶
# Open wizard with invoice
context = {"invoice_id": invoice_id}
vals = get_model("account.credit.wizard").default_get(context=context)
# Create wizard
wiz_id = get_model("account.credit.wizard").create(vals)
# Set allocation amounts
# (amounts set on lines through UI)
# Apply credits
result = get_model("account.credit.wizard").allocate([wiz_id])
Credit Allocation Flow¶
1. Open credit wizard for invoice
│
2. System finds available credits for contact:
│ - Credit notes
│ - Prepayments
│ - Overpayments
│
3. User enters amounts to apply
│
4. System validates total <= invoice due
│
5. Creates allocation journal entries
│ - Handles currency conversion
│ - Creates gain/loss entries
│
6. Reconciles credit and invoice lines
│
7. Invoice due amount reduced
Multi-Currency Handling¶
When currencies differ: 1. Calculates ratio for invoice and credit 2. Converts amounts using original rates 3. Creates currency gain/loss line for difference 4. Posts to currency_loss account from Settings
Version History¶
Last Updated: December 2024 Model Version: account_credit_wizard.py Framework: Netforce
This documentation is generated for developer onboarding and reference purposes.