diff options
| author | Thibault Delavallée <tde@odoo.com> | 2021-04-21 15:08:52 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2021-04-23 08:00:43 +0000 |
| commit | 1476c0f78281fb90e76db5eac193466b86e75a25 (patch) | |
| tree | 312a038420df4dc1bf9a5c4d1c56fa49a7754ef7 | |
| parent | 206685760abbc725765a1f4a5002c2a90abc0af8 (diff) | |
[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
X-original-commit: odoo/odoo@a55f125f5420797a9378925da5626e43d002b9b0
Related: odoo/enterprise#17889
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
| -rw-r--r-- | addons/mail/data/mail_data.xml | 2 | ||||
| -rw-r--r-- | addons/mail/models/mail_thread.py | 2 | ||||
| -rw-r--r-- | addons/portal/models/portal_mixin.py | 5 | ||||
| -rw-r--r-- | addons/sale/data/mail_data.xml | 3 | ||||
| -rw-r--r-- | addons/sale/models/sale.py | 13 |
5 files changed, 8 insertions, 17 deletions
diff --git a/addons/mail/data/mail_data.xml b/addons/mail/data/mail_data.xml index 3b4694997d8..6b5b6298aca 100644 --- a/addons/mail/data/mail_data.xml +++ b/addons/mail/data/mail_data.xml @@ -239,7 +239,7 @@ <t t-set="access_action" t-value="record.with_context(force_website=True).get_access_action()"/> <t t-set="is_online" t-value="access_action and access_action['type'] == 'ir.actions.act_url'"/> <t t-set="base_url" t-value="record.get_base_url()"/> - <t t-set="share_url" t-value="record._get_share_url(redirect=True, signup_partner=True)"/> + <t t-set="share_url" t-value="record._get_share_url(redirect=True, signup_partner=notification_is_customer, share_token=notification_is_customer)"/> <t t-set="access_url" t-value="is_online and share_url and base_url + share_url or ''"/> <t t-set="access_name"> View <t t-esc="model_description or 'document'"/> diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 4c85ef53044..6e0f725ae41 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -2602,6 +2602,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/data/mail_data.xml b/addons/sale/data/mail_data.xml index af9e49da8c2..fc13b95414e 100644 --- a/addons/sale/data/mail_data.xml +++ b/addons/sale/data/mail_data.xml @@ -56,7 +56,8 @@ </data> <!-- Template and notification section --> <data noupdate="1"> - <template id="mail_notification_paynow_online" inherit_id="mail.mail_notification_paynow" name="Quotation: Sign and Pay mail notification template"> + <template id="mail_notification_paynow_online" inherit_id="mail.mail_notification_paynow" + name="Quotation: Sign and Pay mail notification template"> <xpath expr="//t[@t-set='access_name']" position="after"> <t t-if="record._name == 'sale.order'"> <t t-set="is_transaction_pending" t-value="record.get_portal_last_transaction().state == 'pending'"/> diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 0ca6bfed411..cfbb6b9a369 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -1083,19 +1083,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_payment_type(self, tokenize=False): self.ensure_one() return 'form_save' if tokenize else 'form' |
