diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index bc00797a467..755f0d1190c 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -4067,21 +4067,26 @@ class AccountMove(models.Model): ) 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 {}) + groups = super()._notify_get_recipients_groups(message, model_description, msg_vals=msg_vals) + self.ensure_one() + 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, - }, - }) + local_msg_vals = dict(msg_vals or {}) + self._portal_ensure_token() + access_link = self._notify_get_action_link('view', **local_msg_vals, access_token=self.access_token) + + # Create a new group for partners that have been manually added as recipients. + # Those partners should have access to the invoice. + button_access = {'url': access_link} if access_link else {} + recipient_group = ( + 'additional_intended_recipient', + lambda pdata: pdata['id'] in local_msg_vals.get('partner_ids', []) and pdata['id'] != self.partner_id.id, + { + 'has_button_access': True, + 'button_access': button_access, + } + ) + groups.insert(0, recipient_group) return groups diff --git a/addons/account/tests/test_account_move_send.py b/addons/account/tests/test_account_move_send.py index 8214ba4c383..3da19fe3707 100644 --- a/addons/account/tests/test_account_move_send.py +++ b/addons/account/tests/test_account_move_send.py @@ -404,6 +404,10 @@ class TestAccountComposerPerformance(AccountTestInvoicingCommon, MailCommon): test_move = self.test_account_moves[1].with_env(self.env) move_template = self.move_template.with_env(self.env) + # add a follower to the invoice + self.partner_b.email = 'partner_b@example.com' + test_move.message_subscribe(self.partner_b.ids) + additional_partner = self.env['res.partner'].create({ 'name': "Additional Partner", 'email': "additional@example.com", @@ -429,6 +433,15 @@ class TestAccountComposerPerformance(AccountTestInvoicingCommon, MailCommon): content='access_token=' ) + follower_mail = self.assertMailMail( + self.partner_b, + 'sent', + author=self.user_account_other.partner_id, + ) + + self.assertNotIn('access_token=', follower_mail.body_html, + "The followers should not bet sent the access token by default") + @tagged('post_install_l10n', 'post_install', '-at_install') class TestAccountMoveSendCommon(AccountTestInvoicingCommon):