From 358e1d8537aa866269500da18efde818a67674f7 Mon Sep 17 00:00:00 2001 From: Anjeel Haria Date: Fri, 27 Sep 2024 11:39:53 +0530 Subject: [PATCH] [IMP] Show paid amount on move lines for the selected statement line --- .../models/account_bank_statement_line.py | 10 ++++++ .../models/account_move_line.py | 33 ++++++++++++++++++- .../views/account_bank_statement_line.xml | 10 ++++++ .../views/account_move_line.xml | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/account_reconcile_oca/models/account_bank_statement_line.py b/account_reconcile_oca/models/account_bank_statement_line.py index 545bae82d8..6c52bb9cf4 100644 --- a/account_reconcile_oca/models/account_bank_statement_line.py +++ b/account_reconcile_oca/models/account_bank_statement_line.py @@ -16,6 +16,9 @@ class AccountBankStatementLine(models.Model): _inherit = ["account.bank.statement.line", "account.reconcile.abstract"] reconcile_data_info = fields.Serialized(inverse="_inverse_reconcile_data_info") + reconciled_move_line_ids = fields.Many2many( + "account.move.line", compute="_compute_reconciled_move_line_ids" + ) reconcile_mode = fields.Selection( selection=lambda self: self.env["account.journal"] ._fields["reconcile_mode"] @@ -128,6 +131,13 @@ class AccountBankStatementLine(models.Model): aggregate_id = fields.Integer(compute="_compute_reconcile_aggregate") aggregate_name = fields.Char(compute="_compute_reconcile_aggregate") + @api.depends("reconcile_data_info") + def _compute_reconciled_move_line_ids(self): + for rec in self: + rec.reconciled_move_line_ids = rec.reconcile_data_info.get( + "counterparts", [] + ) + @api.model def _reconcile_aggregate_map(self): lang = self.env["res.lang"]._lang_get(self.env.user.lang) diff --git a/account_reconcile_oca/models/account_move_line.py b/account_reconcile_oca/models/account_move_line.py index 7362a983a7..39dbd14b70 100644 --- a/account_reconcile_oca/models/account_move_line.py +++ b/account_reconcile_oca/models/account_move_line.py @@ -1,7 +1,7 @@ # Copyright 2023 Dixmit # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import _, models +from odoo import _, fields, models from odoo.exceptions import ValidationError @@ -9,6 +9,37 @@ class AccountMoveLine(models.Model): _inherit = "account.move.line" + paid_amount = fields.Monetary( + compute="_compute_paid_amount", + currency_field="company_currency_id", + ) + + def _compute_paid_amount(self): + account_bank_statement_line_obj = self.env["account.bank.statement.line"] + for rec in self: + paid_amount = 0.0 + st_line = account_bank_statement_line_obj.browse( + self._context.get("bank_statement_line_id") + ) + if st_line.is_reconciled: + ( + _liquidity_lines, + suspense_lines, + _other_lines, + ) = st_line._seek_for_lines() + if _other_lines: + paid_amount += sum( + _other_lines.mapped("matched_debit_ids") + .filtered(lambda mdi: mdi.debit_move_id == rec) + .mapped("amount") + ) + paid_amount += sum( + _other_lines.mapped("matched_credit_ids") + .filtered(lambda mdi: mdi.credit_move_id == rec) + .mapped("amount") + ) + rec.paid_amount = paid_amount + def action_reconcile_manually(self): if not self: return {} diff --git a/account_reconcile_oca/views/account_bank_statement_line.xml b/account_reconcile_oca/views/account_bank_statement_line.xml index 88e72ce51b..31fd044925 100644 --- a/account_reconcile_oca/views/account_bank_statement_line.xml +++ b/account_reconcile_oca/views/account_bank_statement_line.xml @@ -240,6 +240,16 @@ context="{'search_default_partner_id': partner_id, 'tree_view_ref': 'account_reconcile_oca.account_move_line_tree_reconcile_view', 'search_view_ref': 'account_reconcile_oca.account_move_line_search_reconcile_view'}" /> + + + diff --git a/account_reconcile_oca/views/account_move_line.xml b/account_reconcile_oca/views/account_move_line.xml index e1cb29017e..57d71ad6f6 100644 --- a/account_reconcile_oca/views/account_move_line.xml +++ b/account_reconcile_oca/views/account_move_line.xml @@ -19,6 +19,7 @@ +