diff --git a/l10n_it_riba/models/account.py b/l10n_it_riba/models/account.py index e0ac3725eaae..721f9f891ad8 100644 --- a/l10n_it_riba/models/account.py +++ b/l10n_it_riba/models/account.py @@ -5,6 +5,7 @@ # (). # Copyright (C) 2012-2018 Lorenzo Battistini - Agile Business Group # Copyright 2023 Simone Rubino - Aion Tech +# Copyright 2024 Nextev Srl # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models @@ -58,9 +59,31 @@ def _compute_is_past_due(self): if len(invoice.past_due_move_line_ids) != reconciled_past_due: invoice.is_past_due = True + def _compute_open_amount(self): + for invoice in self: + if invoice.is_riba_payment: + today = fields.Date.today() + open_amount_line_ids = invoice.line_ids.filtered( + lambda l: l.riba + and l.display_type == "payment_term" + and l.date_maturity > today + ) + invoice.open_amount = sum(open_amount_line_ids.mapped("balance")) + else: + invoice.open_amount = 0.0 + riba_credited_ids = fields.One2many( "riba.slip", "credit_move_id", "Credited RiBa Slips", readonly=True ) + + open_amount = fields.Float( + digits="Account", + compute="_compute_open_amount", + store=True, + default=0.0, + help="Amount currently only supposed to be paid, but has actually not happened", + ) + riba_past_due_ids = fields.One2many( "riba.slip.line", "past_due_move_id", "Past Due RiBa Slips", readonly=True ) diff --git a/l10n_it_riba/models/riba.py b/l10n_it_riba/models/riba.py index f77d2b51a29c..b131f989d78c 100644 --- a/l10n_it_riba/models/riba.py +++ b/l10n_it_riba/models/riba.py @@ -5,6 +5,7 @@ # (). # Copyright (C) 2012-2017 Lorenzo Battistini - Agile Business Group # Copyright 2023 Simone Rubino - Aion Tech +# Copyright 2024 Nextev Srl # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import date @@ -371,7 +372,7 @@ def confirm(self): line.invoice_number, line.slip_id.name, line.sequence ), "journal_id": journal.id, - "date": line.slip_id.registration_date, + "date": line.due_date, } ) to_be_reconciled = self.env["account.move.line"] diff --git a/l10n_it_riba/tests/test_riba.py b/l10n_it_riba/tests/test_riba.py index e919eb76bf41..f28b7c6593ac 100644 --- a/l10n_it_riba/tests/test_riba.py +++ b/l10n_it_riba/tests/test_riba.py @@ -369,11 +369,6 @@ def test_past_due_riba(self): # self.assertTrue( # bank_past_due_line.id in [l.id for l in move_lines_for_rec]) - riba_list.line_ids[0].past_due_move_id.line_ids.remove_move_reconcile() - self.assertEqual(riba_list.state, "credited") - self.assertEqual(len(riba_list.line_ids), 1) - self.assertEqual(riba_list.line_ids[0].state, "credited") - def test_riba_fatturapa(self): self.partner.property_account_receivable_id = self.account_rec1_id.id recent_date = ( diff --git a/l10n_it_riba/views/account_view.xml b/l10n_it_riba/views/account_view.xml index 00e0e055b85d..ee896ca06660 100644 --- a/l10n_it_riba/views/account_view.xml +++ b/l10n_it_riba/views/account_view.xml @@ -163,6 +163,7 @@ + diff --git a/l10n_it_riba/wizard/wizard_past_due.py b/l10n_it_riba/wizard/wizard_past_due.py index 7cf4216b41d1..16e4a1629ca0 100644 --- a/l10n_it_riba/wizard/wizard_past_due.py +++ b/l10n_it_riba/wizard/wizard_past_due.py @@ -130,27 +130,6 @@ def create_move(self): "journal_id": wizard.past_due_journal_id.id, "date": slip_line.due_date, "line_ids": [ - ( - 0, - 0, - { - "name": _("Bills"), - "account_id": wizard.effects_account_id.id, - "partner_id": slip_line.partner_id.id, - "credit": wizard.effects_amount, - "debit": 0.0, - }, - ), - ( - 0, - 0, - { - "name": _("RiBa"), - "account_id": wizard.riba_bank_account_id.id, - "debit": wizard.riba_bank_amount, - "credit": 0.0, - }, - ), ( 0, 0, @@ -205,6 +184,7 @@ def create_move(self): i.id for i in riba_move_line.move_line_id.past_due_invoice_ids ] + riba_move_line.move_line_id.remove_move_reconcile() move_model.browse(invoice_ids).write( { "past_due_move_line_ids": [(4, move_line.id)],