feat: enable store=True for residual fields and add sum aggregation to list views

This commit is contained in:
Suherdy Yacob 2026-04-29 21:01:14 +07:00
parent 5888464802
commit 947de037a1
11 changed files with 18 additions and 5 deletions

0
.gitignore vendored Normal file → Executable file
View File

0
CHANGELOG.md Normal file → Executable file
View File

12
README.md Normal file → Executable file
View File

@ -8,6 +8,7 @@ This module adds residual amount display to customer and vendor payments in Odoo
- **List View Integration**: Adds "Residual" column to payment list views (hidden by default) - **List View Integration**: Adds "Residual" column to payment list views (hidden by default)
- **Form View Integration**: Displays residual amount in payment form view - **Form View Integration**: Displays residual amount in payment form view
- **Multi-Currency Support**: Handles both company currency and payment currency residuals - **Multi-Currency Support**: Handles both company currency and payment currency residuals
- **Aggregation Support**: Enables "sum" aggregation in list views and when grouping by any field (e.g., Partner, Journal)
## How It Works ## How It Works
@ -22,15 +23,17 @@ The module extends the `account.payment` model with a computed field that:
## Fields Added ## Fields Added
### `payment_residual` ### `payment_residual`
- **Type**: Monetary (computed) - **Type**: Monetary (computed, stored)
- **Currency**: Payment currency - **Currency**: Payment currency
- **Purpose**: Shows the residual amount not yet reconciled - **Purpose**: Shows the residual amount not yet reconciled
- **Aggregation**: Supports "sum" operator for totals and grouping
- **Computation**: Based on `move_id.line_ids.amount_residual` and `amount_residual_currency` - **Computation**: Based on `move_id.line_ids.amount_residual` and `amount_residual_currency`
### `payment_residual_currency` ### `payment_residual_currency`
- **Type**: Monetary (computed) - **Type**: Monetary (computed, stored)
- **Currency**: Payment currency - **Currency**: Payment currency
- **Purpose**: Shows the residual amount in the payment's currency - **Purpose**: Shows the residual amount in the payment's currency
- **Aggregation**: Supports "sum" operator
## Usage ## Usage
@ -46,6 +49,11 @@ The module extends the `account.payment` model with a computed field that:
3. Shows 0.00 for fully reconciled payments 3. Shows 0.00 for fully reconciled payments
4. Shows the remaining amount for partially reconciled payments 4. Shows the remaining amount for partially reconciled payments
### Grouping and Aggregation
1. In the payment list view, use the **Group By** filter (e.g., by **Partner** or **Journal**)
2. The group headers will display the total sum of the residual amounts for each group
3. The bottom of the list view displays the total residual for all visible records
## Technical Details ## Technical Details
### Dependencies ### Dependencies

0
__init__.py Normal file → Executable file
View File

3
__manifest__.py Normal file → Executable file
View File

@ -1,6 +1,6 @@
{ {
'name': 'Payment Residual Display', 'name': 'Payment Residual Display',
'version': '17.0.1.0.0', 'version': '17.0.1.1.0',
'category': 'Accounting', 'category': 'Accounting',
'summary': 'Display residual amounts in customer payment lines', 'summary': 'Display residual amounts in customer payment lines',
'description': """ 'description': """
@ -11,6 +11,7 @@
- Shows residual amount in payment form view - Shows residual amount in payment form view
- Computes residual from journal items automatically - Computes residual from journal items automatically
- Helps identify partially reconciled payments - Helps identify partially reconciled payments
- Supports aggregation and grouping by residual fields
See README.md for more details. See README.md for more details.
""", """,

0
__pycache__/__init__.cpython-310.pyc Normal file → Executable file
View File

0
models/__init__.py Normal file → Executable file
View File

0
models/__pycache__/__init__.cpython-310.pyc Normal file → Executable file
View File

0
models/__pycache__/account_payment.cpython-310.pyc Normal file → Executable file
View File

6
models/account_payment.py Normal file → Executable file
View File

@ -12,7 +12,8 @@ class AccountPayment(models.Model):
compute='_compute_payment_residual', compute='_compute_payment_residual',
currency_field='currency_id', currency_field='currency_id',
help="Residual amount of this payment (amount not yet reconciled)", help="Residual amount of this payment (amount not yet reconciled)",
readonly=True readonly=True,
store=True
) )
payment_residual_currency = fields.Monetary( payment_residual_currency = fields.Monetary(
@ -20,7 +21,8 @@ class AccountPayment(models.Model):
compute='_compute_payment_residual', compute='_compute_payment_residual',
currency_field='currency_id', currency_field='currency_id',
help="Residual amount in payment currency", help="Residual amount in payment currency",
readonly=True readonly=True,
store=True
) )
@api.depends('move_id.line_ids.amount_residual', @api.depends('move_id.line_ids.amount_residual',

2
views/account_payment_views.xml Normal file → Executable file
View File

@ -12,11 +12,13 @@
widget="monetary" widget="monetary"
options="{'currency_field': 'currency_id'}" options="{'currency_field': 'currency_id'}"
string="Residual" string="Residual"
sum="Total Residual"
optional="hide"/> optional="hide"/>
<field name="payment_residual_currency" <field name="payment_residual_currency"
widget="monetary" widget="monetary"
options="{'currency_field': 'currency_id'}" options="{'currency_field': 'currency_id'}"
string="Residual Currency" string="Residual Currency"
sum="Total Residual Currency"
optional="hide"/> optional="hide"/>
</field> </field>
</field> </field>