diff --git a/dlv_account_reconciliation_rest_amount/README.md b/dlv_account_reconciliation_rest_amount/README.md index 8898626..2060433 100644 --- a/dlv_account_reconciliation_rest_amount/README.md +++ b/dlv_account_reconciliation_rest_amount/README.md @@ -2,15 +2,15 @@ ## Overview -`dlv_account_reconciliation_rest_amount` extends the standard bank -reconciliation screen (Accounting → Reconciliation) so the still-open -("rest") amount of a line is shown in parentheses next to its total. +`dlv_account_reconciliation_rest_amount` extends the bank reconciliation +widget (Accounting → Reconciliation, model `bank.rec.widget`) so the still +outstanding ("rest") amount of a partially matched line is shown in +parentheses next to its total. -On the reconciliation screen, when a proposed line (the bank movement itself, -or an added invoice/bill) is only partially used to close the statement line, -Odoo shows the full amount struck through and the partial amount used above -it — but not what remains unmatched on that line. This addon adds that -missing number, e.g.: +On the reconciliation screen, when an added invoice/bill (a `new_aml` line) +is only partially used to close the statement line, Odoo shows the full +source amount struck through below the amount actually used — but not what +remains unmatched on that line. This addon adds that missing number, e.g.: ``` € 1.899,97 @@ -22,19 +22,27 @@ outstanding, without having to search for it elsewhere. ## How it works -- `static/src/js/reconciliation_rest_amount.js` patches - `account.ReconciliationRenderer`'s `ManualLineRenderer.update()`. Before - every render, it walks `state.reconciliation_proposition` and, for any line - where `partial_amount` differs from `amount`, computes and formats the - difference as `line.rest_amount_str`. -- `static/src/xml/reconciliation_rest_amount.xml` inherits the shared - `reconciliation.line.mv_line.amount` template (from `account_accountant`) - via xpath and prints `line.rest_amount_str` between parentheses, right - after the existing amount. +- `models/bank_rec_widget_line.py` inherits `bank.rec.widget.line` and adds + two computed `Monetary` fields, `rest_debit` and `rest_credit` + (`source_balance - balance`, split like the existing `debit`/`credit` + fields). Because `bank.rec.widget._compute_lines_widget` automatically + serializes every field of `bank.rec.widget.line` to the front-end, these + two fields become available client-side as `line.rest_debit` / + `line.rest_credit` (each with `.display`, `.value`, `.is_zero`) with no + extra plumbing needed. +- `static/src/xml/reconciliation_rest_amount.xml` extends the OWL template + `account_accountant.bank_rec_widget_form_lines_widget` + (`t-inherit-mode="extension"`) and prints the rest amount in parentheses + next to the struck-through source amount, when it is non-zero. -Because both the bank movement (liquidity line) and any added invoice/bill -proposition are rendered through the same loop and template, this single -patch covers both cases. +### Note on the bank movement itself + +Earlier iterations of this addon assumed the bank movement (liquidity) line +could also show a "rest" amount, based on the legacy (pre-16.4) reconciliation +widget where that concept existed. In the `bank.rec.widget` model actually +used on this instance, the liquidity line always reflects the full statement +line amount — there is no partial/rest concept for it, so nothing is shown +there. See ROADMAP.md. ## Dependencies @@ -42,5 +50,6 @@ patch covers both cases. ## Installation -Standard addon install/update. No configuration or data is added; the change -is purely visual on the existing reconciliation widget. +Standard addon install/update (`-u dlv_account_reconciliation_rest_amount`). +No configuration or data is added; the change is a new computed field plus a +purely visual template extension on the existing reconciliation widget. diff --git a/dlv_account_reconciliation_rest_amount/__init__.py b/dlv_account_reconciliation_rest_amount/__init__.py index e69de29..0650744 100644 --- a/dlv_account_reconciliation_rest_amount/__init__.py +++ b/dlv_account_reconciliation_rest_amount/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/dlv_account_reconciliation_rest_amount/__manifest__.py b/dlv_account_reconciliation_rest_amount/__manifest__.py index ec6637f..1c784de 100644 --- a/dlv_account_reconciliation_rest_amount/__manifest__.py +++ b/dlv_account_reconciliation_rest_amount/__manifest__.py @@ -4,11 +4,10 @@ "summary": "Toon het restbedrag tussen haakjes op het afletterscherm " "(bank reconciliatie)", "description": """ -Voegt het restbedrag (verschil tussen het oorspronkelijke bedrag en het reeds -afgeletterde/toegewezen bedrag) tussen haakjes toe aan het bank-afletterscherm, -zowel bij de regel van het bankafschrift (liquidity-line) als bij de -voorgestelde afletteringsregels (bestaande boekingen) die niet volledig -worden ingezet. +Voegt het restbedrag (verschil tussen het volledige bronbedrag en het bedrag +dat effectief wordt ingezet) tussen haakjes toe op het bank-afletterscherm +(bank.rec.widget), naast een gedeeltelijk gematchte afletteringsregel +(bv. een factuur waarvan niet het volledige bedrag wordt gebruikt). """, "author": "bv Domus La Vila", "website": "https://domuslavila.eu", @@ -19,7 +18,6 @@ worden ingezet. "data": [], "assets": { "web.assets_backend": [ - "dlv_account_reconciliation_rest_amount/static/src/js/*.js", "dlv_account_reconciliation_rest_amount/static/src/xml/*.xml", ], }, diff --git a/dlv_account_reconciliation_rest_amount/models/__init__.py b/dlv_account_reconciliation_rest_amount/models/__init__.py new file mode 100644 index 0000000..94a72b1 --- /dev/null +++ b/dlv_account_reconciliation_rest_amount/models/__init__.py @@ -0,0 +1 @@ +from . import bank_rec_widget_line diff --git a/dlv_account_reconciliation_rest_amount/models/bank_rec_widget_line.py b/dlv_account_reconciliation_rest_amount/models/bank_rec_widget_line.py new file mode 100644 index 0000000..f009758 --- /dev/null +++ b/dlv_account_reconciliation_rest_amount/models/bank_rec_widget_line.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +from odoo import api, fields, models + + +class BankRecWidgetLine(models.Model): + _inherit = "bank.rec.widget.line" + + # Restbedrag = het verschil tussen het volledige (bron)bedrag van de + # boeking en het bedrag dat effectief wordt ingezet om af te letteren. + # Enkel relevant wanneer de boeking niet volledig wordt gebruikt + # (zie display_stroked_balance / flag == 'new_aml'). + # + # Elk veld op dit model wordt automatisch geserialiseerd naar de + # 'lines_widget' data (zie bank_rec_widget._compute_lines_widget), dus + # deze twee velden komen vanzelf beschikbaar in de front-end als + # line.rest_debit / line.rest_credit (met .display, .value, .is_zero). + rest_debit = fields.Monetary( + currency_field="company_currency_id", + compute="_compute_dlv_rest_amount", + ) + rest_credit = fields.Monetary( + currency_field="company_currency_id", + compute="_compute_dlv_rest_amount", + ) + + @api.depends("balance", "source_balance") + def _compute_dlv_rest_amount(self): + for line in self: + rest = line.source_balance - line.balance + line.rest_debit = rest if rest > 0.0 else 0.0 + line.rest_credit = -rest if rest < 0.0 else 0.0 diff --git a/dlv_account_reconciliation_rest_amount/static/src/js/reconciliation_rest_amount.js b/dlv_account_reconciliation_rest_amount/static/src/js/reconciliation_rest_amount.js index ee080bd..07289be 100644 --- a/dlv_account_reconciliation_rest_amount/static/src/js/reconciliation_rest_amount.js +++ b/dlv_account_reconciliation_rest_amount/static/src/js/reconciliation_rest_amount.js @@ -1,55 +1,18 @@ -odoo.define('dlv_account_reconciliation_rest_amount.reconciliation_renderer', function (require) { -"use strict"; - /** - * Toont het restbedrag (het verschil tussen het volledige bedrag van een - * regel en het bedrag dat effectief wordt ingezet om af te letteren) tussen - * haakjes op het afletterscherm. + * DEPRECATED / unused on this Odoo instance. * - * Dit geldt zowel voor de bankbeweging zelf (de liquidity-line) als voor een - * toegevoegde boeking (bv. een aankoopfactuur) waarvan niet het volledige - * bedrag wordt gebruikt (line.partial_amount != line.amount). + * This file used to patch the legacy `account.ReconciliationRenderer` + * widget (static/src/js/reconciliation/reconciliation_renderer.js in + * account_accountant), which turned out not to be the widget actually used + * on this server. The real reconciliation screen here is the newer OWL + * `bank.rec.widget` (see views/bank_rec_widget_views.xml and + * static/src/components/bank_reconciliation/ in account_accountant). + * + * The rest-amount feature is now implemented server-side on + * models/bank_rec_widget_line.py (rest_debit / rest_credit fields) and + * rendered via static/src/xml/reconciliation_rest_amount.xml, which + * extends `account_accountant.bank_rec_widget_form_lines_widget`. + * + * Kept as an empty file (rather than deleted) because files in this + * workspace folder cannot be removed once written. */ - -var ReconciliationRenderer = require('account.ReconciliationRenderer'); -var field_utils = require('web.field_utils'); - -ReconciliationRenderer.ManualLineRenderer.include({ - - /** - * @override - */ - update: function (state) { - this._computeRestAmounts(state); - return this._super.apply(this, arguments); - }, - - /** - * Berekent, voor elke regel in de afletteringsvoorstellen die slechts - * gedeeltelijk wordt ingezet, het nog resterende (niet-afgeletterde) - * bedrag en formatteert dit als rest_amount_str. - * - * @private - * @param {Object} state - */ - _computeRestAmounts: function (state) { - var format_options = {currency_id: state.st_line.currency_id}; - _.each(state.reconciliation_proposition, function (line) { - if (!line) { - return; - } - var hasPartialAmount = line.partial_amount && Math.abs(line.partial_amount) !== Math.abs(line.amount); - if (hasPartialAmount) { - var rest = Math.abs(line.amount) - Math.abs(line.partial_amount); - line.rest_amount = rest; - line.rest_amount_str = field_utils.format.monetary(rest, {}, format_options); - } else { - delete line.rest_amount; - delete line.rest_amount_str; - } - }); - }, - -}); - -}); diff --git a/dlv_account_reconciliation_rest_amount/static/src/xml/reconciliation_rest_amount.xml b/dlv_account_reconciliation_rest_amount/static/src/xml/reconciliation_rest_amount.xml index 396e864..43340ae 100644 --- a/dlv_account_reconciliation_rest_amount/static/src/xml/reconciliation_rest_amount.xml +++ b/dlv_account_reconciliation_rest_amount/static/src/xml/reconciliation_rest_amount.xml @@ -2,23 +2,31 @@ - - - () - + + + + () + + + + () + +