From b3a9dbe231a294dd755a3b87b5dae99848c92ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 9 Aug 2017 11:59:15 +0200 Subject: [PATCH] [IMP] portal: add portal.mixin for portal access records This mixin holds the replacement for website_published.mixin website_url field. This field is called portal_url to avoid confusion with the website and enforce the new portal use. It also contains get_share_url method that will be used to generate the URL to use in emails or various communication for customers. --- addons/portal/__init__.py | 1 + addons/portal/models/__init__.py | 4 ++++ addons/portal/models/portal_mixin.py | 32 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 addons/portal/models/__init__.py create mode 100644 addons/portal/models/portal_mixin.py diff --git a/addons/portal/__init__.py b/addons/portal/__init__.py index c92af4efd3d..88710707227 100644 --- a/addons/portal/__init__.py +++ b/addons/portal/__init__.py @@ -2,4 +2,5 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import controllers +from . import models from . import wizard diff --git a/addons/portal/models/__init__.py b/addons/portal/models/__init__.py new file mode 100644 index 00000000000..bccc8440508 --- /dev/null +++ b/addons/portal/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import portal_mixin diff --git a/addons/portal/models/portal_mixin.py b/addons/portal/models/portal_mixin.py new file mode 100644 index 00000000000..62dc8403956 --- /dev/null +++ b/addons/portal/models/portal_mixin.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from werkzeug.urls import url_encode + +from odoo import api, fields, models + + +class PortalMixin(models.AbstractModel): + _name = "portal.mixin" + + portal_url = fields.Char( + 'Portal Access URL', compute='_compute_portal_url', + help='Customer Portal URL') + + @api.multi + def _compute_portal_url(self): + for record in self: + record.portal_url = '#' + + def get_share_url(self): + self.ensure_one() + params = { + 'model': self._name, + 'res_id': self.id, + } + if hasattr(self, 'access_token') and self.access_token: + params['access_token'] = self.access_token + if hasattr(self, 'partner_id') and self.partner_id: + params.update(self.partner_id.signup_get_auth_param()[self.partner_id.id]) + + return '/mail/view?' + url_encode(params)