From 8f56f1ead0fcf2d10afc9a2b7fee8949db730188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 21 Apr 2021 15:08:52 +0000 Subject: [PATCH] [FW][FIX] sale: correctly redirect customers in "Pay Now" template Mail holds a "Pay Now" notification template holding notably customized links to portal for records like sale orders or invoices. It allow to give a more personalized button than a plain simple "View document" link. Currently frontend / backend links are not always correctly computed in this template. This commit fixes that behavior. Task ID-2513724 COM PR #69607 ENT PR odoo/enterprise#17849 closes odoo/odoo#69714 closes odoo/odoo#69744 closes odoo/odoo#69774 X-original-commit: c417ea6243cb968d17f5db0919ec8cd034f4cb5f Related: odoo/enterprise#17889 Related: odoo/enterprise#17902 Related: odoo/enterprise#17916 Signed-off-by: Thibault Delavallee (tde) --- addons/mail/data/mail_templates.xml | 2 +- addons/mail/models/mail_thread.py | 2 ++ addons/portal/models/portal_mixin.py | 5 +++-- addons/sale/models/sale.py | 13 ------------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/addons/mail/data/mail_templates.xml b/addons/mail/data/mail_templates.xml index 034be994eda..494ad12fa5d 100644 --- a/addons/mail/data/mail_templates.xml +++ b/addons/mail/data/mail_templates.xml @@ -195,7 +195,7 @@ - + View diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index b8661a70be6..19271082b7d 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -2503,6 +2503,8 @@ class MailThread(models.AbstractModel): # fill group_data with default_values if they are not complete for group_name, group_func, group_data in groups: + group_data.setdefault('notification_group_name', group_name) + group_data.setdefault('notification_is_customer', False) group_data.setdefault('has_button_access', True) group_button_access = group_data.setdefault('button_access', {}) group_button_access.setdefault('url', access_link) diff --git a/addons/portal/models/portal_mixin.py b/addons/portal/models/portal_mixin.py index d2e9e83f094..bbd9576c094 100644 --- a/addons/portal/models/portal_mixin.py +++ b/addons/portal/models/portal_mixin.py @@ -32,7 +32,7 @@ class PortalMixin(models.AbstractModel): self.sudo().write({'access_token': str(uuid.uuid4())}) return self.access_token - def _get_share_url(self, redirect=False, signup_partner=False, pid=None): + def _get_share_url(self, redirect=False, signup_partner=False, pid=None, share_token=True): """ Build the url of the record that will be sent by mail and adds additional parameters such as access_token to bypass the recipient's rights, @@ -50,7 +50,7 @@ class PortalMixin(models.AbstractModel): 'model': self._name, 'res_id': self.id, } - if hasattr(self, 'access_token'): + if share_token and hasattr(self, 'access_token'): params['access_token'] = self._portal_ensure_token() if pid: params['pid'] = pid @@ -77,6 +77,7 @@ class PortalMixin(models.AbstractModel): 'button_access': { 'url': access_link, }, + 'notification_is_customer': True, }) ] else: diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 4822ee159e2..dd4c4aab90a 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -1028,19 +1028,6 @@ Reason(s) of this behavior could be: self.ensure_one() return '%s %s' % (self.type_name, self.name) - def _get_share_url(self, redirect=False, signup_partner=False, pid=None): - """Override for sales order. - - If the SO is in a state where an action is required from the partner, - return the URL with a login token. Otherwise, return the URL with a - generic access token (no login). - """ - self.ensure_one() - if self.state not in ['sale', 'done']: - auth_param = url_encode(self.partner_id.signup_get_auth_param()[self.partner_id.id]) - return self.get_portal_url(query_string='&%s' % auth_param) - return super(SaleOrder, self)._get_share_url(redirect, signup_partner, pid) - def _get_portal_return_action(self): """ Return the action used to display orders when returning from customer portal. """ self.ensure_one()