From 7176d04f3b2021f4efd40b078edc3961326dd575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Dec 2017 17:06:42 +0100 Subject: [PATCH 1/6] [IMP] mail: allow parameters to /mail/view link Purpose is to allow to add parameters to the view link. Currently it is formatted like '/mail/view?model=model&res_id=res_id'. We would like to be able to add parameters like access token for example. It will allow to create view links specifically tailored for some people like customer portal. --- addons/mail/models/mail_thread.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 32639ae75a9..955d9ac4479 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -634,7 +634,7 @@ class MailThread(models.AbstractModel): local_kwargs.pop('res_id', None) if link_type in ['view', 'assign', 'follow', 'unfollow']: - params = dict(base_params) + params = dict(base_params, **local_kwargs) base_link = '/mail/%s' % link_type elif link_type == 'controller': controller = local_kwargs.pop('controller') From 0e22ccb721a93a4535b664a43f85db2a86e97008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Dec 2017 17:06:59 +0100 Subject: [PATCH 2/6] [IMP] portal: add access token link in notification emails for customers Purpose of this commit is to allow customer portal to have an access link containing an access token. Portal mixin now override the default mail.thread behavior when classifying recipients of a notification email in groups. If the model has an access_token and a customer field correctly defined the recipient that matches the customer will have an access link in its notification email holding the access token. It will also contain an auth signup token if it is enabled. --- addons/portal/models/portal_mixin.py | 48 +++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/addons/portal/models/portal_mixin.py b/addons/portal/models/portal_mixin.py index 62dc8403956..ec11771c571 100644 --- a/addons/portal/models/portal_mixin.py +++ b/addons/portal/models/portal_mixin.py @@ -3,7 +3,7 @@ from werkzeug.urls import url_encode -from odoo import api, fields, models +from odoo import api, fields, models, _ class PortalMixin(models.AbstractModel): @@ -18,6 +18,27 @@ class PortalMixin(models.AbstractModel): for record in self: record.portal_url = '#' + def _get_access_token_field(self): + """ Give the field used to fetch the customer portal access token, if + any. Override this method if the field holding the token is named + differently. """ + return 'access_token' if 'access_token' in self else False + + def _get_customer_field(self): + """ Give the field used to fetch the customer partner_id, if any. + Override this method if the field holding the token is named differently. """ + return 'partner_id' if 'partner_id' in self else False + + def _get_access_token(self): + """ Get the current record access token """ + field = self._get_access_token_field() + return self[field] if field else False + + def _get_customer(self): + """ Get the current record custome (res.partner record) """ + field = self._get_customer_field() + return self[field] if field else self.env['res.partner'] + def get_share_url(self): self.ensure_one() params = { @@ -30,3 +51,28 @@ class PortalMixin(models.AbstractModel): params.update(self.partner_id.signup_get_auth_param()[self.partner_id.id]) return '/mail/view?' + url_encode(params) + + @api.multi + def _notification_recipients(self, message, groups): + access_token = self._get_access_token() + customer = self._get_customer() + + if access_token and customer: + additional_params = { + 'access_token': self.access_token, + } + additional_params.update(customer.signup_get_auth_param()[customer.id]) + access_link = self._notification_link_helper('view', **additional_params) + + new_group = [ + ('portal_customer', lambda partner: partner.id == customer.id, { + 'has_button_access': False, + 'button_access': { + 'url': access_link, + 'title': ('View %s') % self.env['ir.model']._get(message.model).display_name, + }, + }) + ] + else: + new_group = [] + return super(PortalMixin, self)._notification_recipients(message, new_group + groups) From 75ec7ab257d93a150911fbb422f7e8aa306a4905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Dec 2017 17:35:25 +0100 Subject: [PATCH 3/6] [FIX] sale: reorder inherit to be able to pass through portal before mail thread Purpose is to enable override of mail.thread methods in portal mixin. An example is the _notification_recipients method defined in mail.thread and customized in portal.mixin. --- addons/sale/models/sale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index a646f5e0ed3..271bea23781 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -19,7 +19,7 @@ from odoo.addons import decimal_precision as dp class SaleOrder(models.Model): _name = "sale.order" - _inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin'] + _inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin'] _description = "Quotation" _order = 'date_order desc, id desc' From 2bf370ac2809c56f79e3a0dba74619b35f704e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Dec 2017 17:54:33 +0100 Subject: [PATCH 4/6] [FIX] account: reorder inherit to be able to pass through portal before mail thread Purpose is to enable override of mail.thread methods in portal mixin. An example is the _notification_recipients method defined in mail.thread and customized in portal.mixin. --- addons/account/models/account_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 48f7756c7e5..a3aadfe7fa7 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -41,7 +41,7 @@ MAGIC_COLUMNS = ('id', 'create_uid', 'create_date', 'write_uid', 'write_date') class AccountInvoice(models.Model): _name = "account.invoice" - _inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin'] + _inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin'] _description = "Invoice" _order = "date_invoice desc, number desc, id desc" From 467e490e5d695817f98b709c06763ff7a372729b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Dec 2017 17:54:40 +0100 Subject: [PATCH 5/6] [FIX] project: reorder inherit to be able to pass through portal before mail thread Purpose is to enable override of mail.thread methods in portal mixin. An example is the _notification_recipients method defined in mail.thread and customized in portal.mixin. --- addons/project/models/project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 4b824ded373..319f50724b6 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -68,7 +68,7 @@ class ProjectTaskType(models.Model): class Project(models.Model): _name = "project.project" _description = "Project" - _inherit = ['mail.alias.mixin', 'mail.thread', 'portal.mixin'] + _inherit = ['portal.mixin', 'mail.alias.mixin', 'mail.thread'] _inherits = {'account.analytic.account': "analytic_account_id"} _order = "sequence, name, id" _period_number = 5 @@ -444,7 +444,7 @@ class Task(models.Model): _name = "project.task" _description = "Task" _date_name = "date_start" - _inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin', 'rating.mixin'] + _inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin', 'rating.mixin'] _mail_post_access = 'read' _order = "priority desc, sequence, date_start, name, id" From 398c126cfaafcd2782d553475fadcb6f21f6fffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 2 Jan 2018 14:49:46 +0100 Subject: [PATCH 6/6] [IMP] account: display access buttons in notification email only on not draft not canceled invoices Indeed draft and canceled invoices should not be displayed to customer or portal customers. --- addons/account/models/account_invoice.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index a3aadfe7fa7..164f79bfa2a 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -875,10 +875,11 @@ class AccountInvoice(models.Model): def _notification_recipients(self, message, groups): groups = super(AccountInvoice, self)._notification_recipients(message, groups) - for group_name, group_method, group_data in groups: - if group_name == 'customer': - continue - group_data['has_button_access'] = True + if self.state not in ('draft', 'cancel'): + for group_name, group_method, group_data in groups: + if group_name == 'customer': + continue + group_data['has_button_access'] = True return groups