[FIX] account: allow sending invoice to partner other than the customer
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) <bib@odoo.com> Signed-off-by: Nshimiyimana Serge Séna (sesn) <sesn@odoo.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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='
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user