From 78213a2ae5f875b26d35efdbdc76c0e5f5758c15 Mon Sep 17 00:00:00 2001 From: Alessandro Uffreduzzi Date: Tue, 30 Jul 2024 15:21:02 +0200 Subject: [PATCH 1/3] [IMP] l10n_it_ricevute_bancarie: readability of payment term and bank Adds a dash "-" between the name of the payment term and the name of the bank on the invoice, in case the payment term is a RiBa. Previously, the name of the payment term and the bank were contiguous, without even a space in between. --- l10n_it_ricevute_bancarie/views/account_view.xml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/l10n_it_ricevute_bancarie/views/account_view.xml b/l10n_it_ricevute_bancarie/views/account_view.xml index 95fb35a7c5e8..bf342280da31 100644 --- a/l10n_it_ricevute_bancarie/views/account_view.xml +++ b/l10n_it_ricevute_bancarie/views/account_view.xml @@ -140,11 +140,16 @@ - +
+  - + +
Date: Tue, 30 Jul 2024 15:46:54 +0200 Subject: [PATCH 2/3] [IMP] l10n_it_ricevute_bancarie: stop invoice confirmation without bank Cannot confirm an invoice with C/O (RiBa) payment if the bank has not been set on the invoice. --- l10n_it_ricevute_bancarie/models/account.py | 25 ++++++++++++++++++++ l10n_it_ricevute_bancarie/tests/test_riba.py | 14 +++++++++++ 2 files changed, 39 insertions(+) diff --git a/l10n_it_ricevute_bancarie/models/account.py b/l10n_it_ricevute_bancarie/models/account.py index f09d87d8e994..540d51d6b34a 100644 --- a/l10n_it_ricevute_bancarie/models/account.py +++ b/l10n_it_ricevute_bancarie/models/account.py @@ -121,6 +121,31 @@ def month_check(self, invoice_date_due, all_date_due): return True return False + def _post(self, soft=True): + inv_riba_no_bank = self.filtered( + lambda x: x.is_riba_payment + and x.move_type == "out_invoice" + and not x.riba_partner_bank_id + ) + if inv_riba_no_bank: + inv_details = ( + _( + 'Invoice %(name)s for customer "%(customer_name)s", total %(amount)s', + name=inv.display_name, + customer_name=inv.partner_id.display_name, + amount=inv.amount_total, + ) + for inv in inv_riba_no_bank + ) + raise UserError( + _( + "Cannot post invoices with C/O payments without bank. " + "Please check the following invoices:\n\n- " + + "\n- ".join(inv_details) + ) + ) + return super()._post(soft=soft) + def action_post(self): for invoice in self: # ---- Add a line with collection fees for each due date only for first due diff --git a/l10n_it_ricevute_bancarie/tests/test_riba.py b/l10n_it_ricevute_bancarie/tests/test_riba.py index 6ae38f6edea2..c6c62d3ff4e6 100644 --- a/l10n_it_ricevute_bancarie/tests/test_riba.py +++ b/l10n_it_ricevute_bancarie/tests/test_riba.py @@ -550,3 +550,17 @@ def test_riba_bank_multicompany(self): exc_message = ue.exception.args[0] self.assertIn(self.env.company.name, exc_message) self.assertIn(self.company2_bank.acc_number, exc_message) + + def test_riba_inv_no_bank(self): + """ + Test that a riba invoice without a bank defined + cannot be confirmed (e.g. via the list view) + """ + self.invoice.company_id.due_cost_service_id = self.service_due_cost.id + self.invoice.riba_partner_bank_id = False + with self.assertRaises(UserError) as err: + self.invoice.action_post() + err_msg = err.exception.args[0] + 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) From 3a6a86509648e6da2c2ba70d92e21bd5ada4d3a3 Mon Sep 17 00:00:00 2001 From: Alessandro Uffreduzzi Date: Tue, 30 Jul 2024 16:36:59 +0200 Subject: [PATCH 3/3] [IMP] l10n_it_ricevute_bancarie: fall back on commercial partner's bank If creating an invoice with C/O for a contact without a bank, fall back on the commercial partner's bank. --- l10n_it_ricevute_bancarie/models/account.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/l10n_it_ricevute_bancarie/models/account.py b/l10n_it_ricevute_bancarie/models/account.py index 540d51d6b34a..d42bea83c418 100644 --- a/l10n_it_ricevute_bancarie/models/account.py +++ b/l10n_it_ricevute_bancarie/models/account.py @@ -97,17 +97,20 @@ def create(self, vals): @api.onchange("partner_id", "invoice_payment_term_id", "move_type") def _onchange_riba_partner_bank_id(self): + allowed_banks = ( + self.partner_id.bank_ids or self.partner_id.commercial_partner_id.bank_ids + ) if ( not self.riba_partner_bank_id - or self.riba_partner_bank_id not in self.partner_id.bank_ids + or self.riba_partner_bank_id not in allowed_banks ): bank_ids = self.env["res.partner.bank"] if ( self.partner_id - and self.invoice_payment_term_id.riba + and self.is_riba_payment and self.move_type in ["out_invoice", "out_refund"] ): - bank_ids = self.partner_id.bank_ids + bank_ids = allowed_banks self.riba_partner_bank_id = bank_ids[0] if bank_ids else None def month_check(self, invoice_date_due, all_date_due):