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=' + )