From 15ef1ba0819bfd2f34cea886c5369e5a53bb423d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nshimiyimana=20S=C3=A9na?= Date: Fri, 19 May 2023 08:36:32 +0000 Subject: [PATCH] [FIX] account: allow sending invoice to partner other than the customer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When sending an invoice to a recipient who is not the customer, they are unable to view the invoice in the customer portal and are prompted to log in. 1. Create and validate an invoice 2. Click on the Send & Print button, then add a recipient who is not the customer associated with the invoice. 3. Proceed to send the invoice. 4. Access the email that was sent to the added recipient (who is not the customer) 5. Using an incognito or private browsing window, open the link `View Invoice` => you should see that you are asked to log in, instead of being directed to the customer portal. opw-3114579 closes odoo/odoo#121954 X-original-commit: aabb2e624ef55661549381cea63e6460faa285c9 Signed-off-by: Brice Bartoletti (bib) Signed-off-by: Nshimiyimana Serge Séna (sesn) --- addons/account/models/account_move.py | 19 ++++++++++++ .../account/tests/test_account_move_send.py | 31 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index c1d98380c35..082d5656edc 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3830,6 +3830,25 @@ class AccountMove(models.Model): else 'account.email_template_edi_invoice' ) + def _notify_get_recipients_groups(self, message, model_description, msg_vals=None): + groups = super()._notify_get_recipients_groups( + message, model_description, msg_vals=msg_vals) + local_msg_vals = dict(msg_vals or {}) + if self.move_type != 'entry': + # This allows partners added to the email list in the sending wizard to access this document. + for group_name, _group_method, group_data in groups: + if group_name == 'customer' and self._portal_ensure_token(): + access_link = self._notify_get_action_link( + 'view', **local_msg_vals, access_token=self.access_token) + group_data.update({ + 'has_button_access': True, + 'button_access': { + 'url': access_link, + }, + }) + + return groups + def _get_report_base_filename(self): return self._get_move_display_name() diff --git a/addons/account/tests/test_account_move_send.py b/addons/account/tests/test_account_move_send.py index 459d582a8b7..c65c66566fd 100644 --- a/addons/account/tests/test_account_move_send.py +++ b/addons/account/tests/test_account_move_send.py @@ -413,3 +413,34 @@ class TestAccountComposerPerformance(AccountMoveSendBase): # invoice update self.assertTrue(test_move.is_move_sent) + + def test_invoice_sent_to_additional_partner(self): + """ + Make sure that when an invoice is sent to a partner who is not + the invoiced customer, they receive a link containing an access token, + allowing them to view the invoice without needing to log in. + """ + test_move = self.test_account_moves[1].with_env(self.env) + + additional_partner = self.env['res.partner'].create({ + 'name': "Additional Partner", + 'email': "additional@example.com", + }) + + default_ctx = test_move.action_send_and_print()['context'] + composer_form = Form( + self.env['account.move.send'].with_context(default_ctx) + ) + composer_form.mail_partner_ids.add(additional_partner) + composer_form.checkbox_ubl_cii_xml = False + composer = composer_form.save() + + with self.mock_mail_gateway(mail_unlink_sent=False): + composer.action_send_and_print() + + self.assertMailMail( + additional_partner, + 'sent', + author=self.user_account_other.partner_id, + content='access_token=' + )