From 7a00e93ca9942e5720baa1f6fc7a50675c1f4b12 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Wed, 25 Sep 2024 15:04:43 +0200 Subject: [PATCH] [IMP] l10n_it_riba: Pay multiple lines at once Also allow to set a date during payment and past due process --- l10n_it_ricevute_bancarie/README.rst | 14 ++-- l10n_it_ricevute_bancarie/__manifest__.py | 1 + l10n_it_ricevute_bancarie/models/riba.py | 51 ++++++++++-- l10n_it_ricevute_bancarie/readme/USAGE.rst | 12 ++- .../security/ir.model.access.csv | 1 + .../static/description/index.html | 13 +++- .../tests/riba_common.py | 1 + l10n_it_ricevute_bancarie/tests/test_riba.py | 76 ++++++++++++++++++ l10n_it_ricevute_bancarie/views/riba_view.xml | 4 +- .../views/wizard_due_date_settlement.xml | 2 + .../views/wizard_unsolved.xml | 1 + l10n_it_ricevute_bancarie/wizard/__init__.py | 1 + .../wizard/wizard_due_date_settlement.py | 10 ++- .../wizard/wizard_riba_multiple_payment.py | 78 +++++++++++++++++++ .../wizard_riba_multiple_payment_views.xml | 46 +++++++++++ .../wizard/wizard_unsolved.py | 10 ++- 16 files changed, 294 insertions(+), 27 deletions(-) create mode 100644 l10n_it_ricevute_bancarie/wizard/wizard_riba_multiple_payment.py create mode 100644 l10n_it_ricevute_bancarie/wizard/wizard_riba_multiple_payment_views.xml diff --git a/l10n_it_ricevute_bancarie/README.rst b/l10n_it_ricevute_bancarie/README.rst index 8322221610eb..4e7c159085c4 100644 --- a/l10n_it_ricevute_bancarie/README.rst +++ b/l10n_it_ricevute_bancarie/README.rst @@ -7,7 +7,7 @@ ITA - Ricevute bancarie !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:100f1b7d1eb019a23cf3734dd6851726c6bb228961c00615be14977e5c7d470f + !! source digest: sha256:8e70b2caa85bc9320745588e56ff493847d8f8f11304c626249a3544e36cf536 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -108,10 +108,14 @@ esposizione, cioè l'importo dovuto dal cliente a fronte dell'emissione della RiBa non ancora scaduta. In maniera predefinita la data delle registrazioni dei pagamenti viene -impostata con la data di scadenza della RiBa, ma è possibile modificarla -successivamente a pagamento effettivamente avvenuto selezionando la -registrazione dalla vista ed elenco ed eseguendo l'azione "Imposta data -di pagamento RiBa". +impostata con la data di scadenza della RiBa, ma è possibile modificarla in due momenti: +- durante la creazione del pagamento, + cliccando su "Segna righe come pagate" o su "Segna coma pagata" + o usando l'azione "Registrazione Riba a data di scadenza" + e indicando una data nel campo `Data pagamento`, +- successivamente a pagamento effettivamente avvenuto selezionando la selezionando la + registrazione dalla vista ed elenco ed eseguendo l'azione "Imposta data + di pagamento RiBa". Known issues / Roadmap ====================== diff --git a/l10n_it_ricevute_bancarie/__manifest__.py b/l10n_it_ricevute_bancarie/__manifest__.py index a0974bdad241..7ae2aaf3434a 100644 --- a/l10n_it_ricevute_bancarie/__manifest__.py +++ b/l10n_it_ricevute_bancarie/__manifest__.py @@ -43,6 +43,7 @@ "views/riba_detail_view.xml", "views/wizard_presentation.xml", "views/wizard_due_date_settlement.xml", + "wizard/wizard_riba_multiple_payment_views.xml", ], "demo": ["demo/riba_demo.xml"], "installable": True, diff --git a/l10n_it_ricevute_bancarie/models/riba.py b/l10n_it_ricevute_bancarie/models/riba.py index 20c6df79a8a7..c29767be5508 100644 --- a/l10n_it_ricevute_bancarie/models/riba.py +++ b/l10n_it_ricevute_bancarie/models/riba.py @@ -95,7 +95,16 @@ def _compute_total_amount(self): ) date_accepted = fields.Date("Acceptance Date") date_accreditation = fields.Date("Credit Date") - date_paid = fields.Date("Payment Date", readonly=True) + date_paid = fields.Date( + string="Payment Date", + help="Default date for payments.", + readonly=True, + states={ + "credited": [ + ("readonly", False), + ], + }, + ) date_unsolved = fields.Date("Past Due Date", readonly=True) company_id = fields.Many2one( "res.company", @@ -187,10 +196,18 @@ def riba_cancel(self): distinta.state = "cancel" def settle_all_line(self): - for riba_list in self: - for line in riba_list.line_ids: - if line.state == "accredited": - line.riba_line_settlement() + payment_wizard_action = ( + self.env["riba.payment.multiple"] + .with_context( + active_ids=self.ids, + ) + .get_formview_action() + ) + payment_wizard_action.update( + name=_("Settle lines"), + target="new", + ) + return payment_wizard_action @api.onchange("date_accepted", "date_accreditation") def _onchange_date(self): @@ -475,7 +492,26 @@ def confirm(self): if not line.distinta_id.date_accepted: line.distinta_id.date_accepted = fields.Date.context_today(self) - def riba_line_settlement(self): + def button_settle(self): + payment_wizard_action = ( + self.env["riba.payment.multiple"] + .with_context( + active_ids=self.slip_id.ids, + default_riba_line_ids=self.ids, + ) + .get_formview_action() + ) + payment_wizard_action.update( + name=_("Settle line"), + target="new", + ) + return payment_wizard_action + + def riba_line_settlement(self, date=None): + """Create payment the acceptance move of each line in `self`. + + :param date: The created payment's date. + """ for riba_line in self: if not riba_line.distinta_id.config_id.settlement_journal_id: raise UserError(_("Please define a Settlement Journal.")) @@ -498,12 +534,13 @@ def riba_line_settlement(self): riba_line.distinta_id.name, riba_line.partner_id.name, ) + move_date = date or riba_line.due_date.strftime("%Y-%m-%d") settlement_move = move_model.create( { "journal_id": ( riba_line.distinta_id.config_id.settlement_journal_id.id ), - "date": riba_line.due_date.strftime("%Y-%m-%d"), + "date": move_date, "ref": move_ref, } ) diff --git a/l10n_it_ricevute_bancarie/readme/USAGE.rst b/l10n_it_ricevute_bancarie/readme/USAGE.rst index 2f49be5d4780..ae6d04a5a880 100644 --- a/l10n_it_ricevute_bancarie/readme/USAGE.rst +++ b/l10n_it_ricevute_bancarie/readme/USAGE.rst @@ -27,7 +27,11 @@ esposizione, cioè l'importo dovuto dal cliente a fronte dell'emissione della RiBa non ancora scaduta. In maniera predefinita la data delle registrazioni dei pagamenti viene -impostata con la data di scadenza della RiBa, ma è possibile modificarla -successivamente a pagamento effettivamente avvenuto selezionando la -registrazione dalla vista ed elenco ed eseguendo l'azione "Imposta data -di pagamento RiBa". +impostata con la data di scadenza della RiBa, ma è possibile modificarla in due momenti: +- durante la creazione del pagamento, + cliccando su "Segna righe come pagate" o su "Segna coma pagata" + o usando l'azione "Registrazione Riba a data di scadenza" + e indicando una data nel campo `Data pagamento`, +- successivamente a pagamento effettivamente avvenuto selezionando la selezionando la + registrazione dalla vista ed elenco ed eseguendo l'azione "Imposta data + di pagamento RiBa". diff --git a/l10n_it_ricevute_bancarie/security/ir.model.access.csv b/l10n_it_ricevute_bancarie/security/ir.model.access.csv index 1541f9c851ff..ef68d1d86c78 100644 --- a/l10n_it_ricevute_bancarie/security/ir.model.access.csv +++ b/l10n_it_ricevute_bancarie/security/ir.model.access.csv @@ -20,3 +20,4 @@ access_riba_file_export,riba_file_export,model_riba_file_export,account.group_ac access_presentation_riba_issue,access_presentation_riba_issue,model_presentation_riba_issue,account.group_account_invoice,1,1,1,1 access_riba_due_date_settlement,riba_due_date_settlement,model_riba_due_date_settlement,account.group_account_invoice,1,1,1,1 access_riba_payment_date,riba_payment_date,model_riba_payment_date,account.group_account_invoice,1,1,1,1 +access_riba_multiple_payment_date,Full access to Pay multiple RiBa lines,model_riba_payment_multiple,account.group_account_invoice,1,1,1,1 diff --git a/l10n_it_ricevute_bancarie/static/description/index.html b/l10n_it_ricevute_bancarie/static/description/index.html index 8949ec3ba7fd..d7d543fb2e45 100644 --- a/l10n_it_ricevute_bancarie/static/description/index.html +++ b/l10n_it_ricevute_bancarie/static/description/index.html @@ -448,9 +448,16 @@

Usage

della RiBa non ancora scaduta.

In maniera predefinita la data delle registrazioni dei pagamenti viene impostata con la data di scadenza della RiBa, ma è possibile modificarla -successivamente a pagamento effettivamente avvenuto selezionando la -registrazione dalla vista ed elenco ed eseguendo l’azione “Imposta data -di pagamento RiBa”.

+in due momenti:

+

Known issues / Roadmap

diff --git a/l10n_it_ricevute_bancarie/tests/riba_common.py b/l10n_it_ricevute_bancarie/tests/riba_common.py index 1b508977a5fb..dbe796f8d7b9 100644 --- a/l10n_it_ricevute_bancarie/tests/riba_common.py +++ b/l10n_it_ricevute_bancarie/tests/riba_common.py @@ -249,6 +249,7 @@ def create_config_incasso(self): "bank_id": self.company_bank.id, "acceptance_journal_id": self.bank_journal.id, "acceptance_account_id": self.sbf_effects.id, + "settlement_journal_id": self.bank_journal.id, } ) diff --git a/l10n_it_ricevute_bancarie/tests/test_riba.py b/l10n_it_ricevute_bancarie/tests/test_riba.py index 2cb610b1d190..5b8bb0639518 100644 --- a/l10n_it_ricevute_bancarie/tests/test_riba.py +++ b/l10n_it_ricevute_bancarie/tests/test_riba.py @@ -4,9 +4,11 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import base64 +import datetime import os from odoo.exceptions import UserError +from odoo.fields import first from odoo.tests import Form from odoo.tools import config, safe_eval @@ -668,3 +670,77 @@ def test_riba_inv_no_bank(self): self.assertIn("Cannot post invoices", err_msg) self.assertIn(self.invoice.partner_id.display_name, err_msg) self.assertIn(str(self.invoice.amount_total), err_msg) + + def test_riba_payment_date_multiple_lines(self): + """A specific date can be set to pay multiple RiBa lines.""" + # Arrange + company = self.env.company + payment_date = datetime.date(2020, month=1, day=1) + payment_term = self.payment_term2 + riba_configuration = self.riba_config_sbf_immediate + product = self.product1 + partner = self.partner + company.due_cost_service_id = self.service_due_cost + + invoice_form = Form( + self.env["account.move"].with_context( + default_move_type="out_invoice", + default_name="Test invoice", + ) + ) + invoice_form.partner_id = partner + invoice_form.invoice_payment_term_id = payment_term + invoice_form.riba_partner_bank_id = first(partner.bank_ids) + with invoice_form.invoice_line_ids.new() as line: + line.product_id = product + invoice = invoice_form.save() + invoice.action_post() + + to_issue_action = self.env.ref("l10n_it_riba.action_riba_to_issue") + to_issue_records = self.env[to_issue_action.res_model].search( + safe_eval.safe_eval(to_issue_action.domain) + ) + invoice_to_issue_records = to_issue_records & invoice.line_ids + self.assertTrue(invoice_to_issue_records) + + issue_wizard_model = self.env["riba.issue"].with_context( + active_model=invoice_to_issue_records._name, + active_ids=invoice_to_issue_records.ids, + ) + issue_wizard_form = Form(issue_wizard_model) + issue_wizard_form.configuration_id = riba_configuration + issue_wizard = issue_wizard_form.save() + issue_result = issue_wizard.create_list() + slip = self.env[issue_result["res_model"]].browse(issue_result["res_id"]) + + slip.confirm() + self.assertEqual(slip.state, "accepted") + + credit_wizard_action = self.env.ref("l10n_it_riba.riba_credit_action") + credit_wizard = ( + self.env[credit_wizard_action["res_model"]] + .with_context(active_id=slip.id) + .create( + { + "bank_amount": invoice.amount_total, + } + ) + ) + credit_wizard.create_move() + self.assertEqual(slip.state, "credited") + + # Act + payment_wizard_action = slip.settle_all_line() + payment_wizard_form = Form( + self.env[payment_wizard_action["res_model"]].with_context( + **payment_wizard_action["context"] + ) + ) + payment_wizard_form.payment_date = payment_date + payment_wizard = payment_wizard_form.save() + payment_wizard.pay() + + # Assert + self.assertEqual(slip.state, "paid") + payment_move = slip.payment_ids.move_id + self.assertEqual(payment_move.date, payment_date) diff --git a/l10n_it_ricevute_bancarie/views/riba_view.xml b/l10n_it_ricevute_bancarie/views/riba_view.xml index 99f301404190..5f0f5b044b99 100644 --- a/l10n_it_ricevute_bancarie/views/riba_view.xml +++ b/l10n_it_ricevute_bancarie/views/riba_view.xml @@ -158,7 +158,7 @@