diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 48f7756c7e5..164f79bfa2a 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" @@ -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 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') 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) 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" 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'