[MERGE] forward port of branch 7.0 up to de07c64
[odoo/odoo.git] / addons / portal / mail_mail.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2011 OpenERP S.A (<http://www.openerp.com>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp import SUPERUSER_ID
23 from openerp.osv import osv
24 from openerp.tools.translate import _
25
26
27 class mail_mail(osv.Model):
28     """ Update of mail_mail class, to add the signin URL to notifications. """
29     _inherit = 'mail.mail'
30
31     def _get_partner_access_link(self, cr, uid, mail, partner=None, context=None):
32         """ Generate URLs for links in mails:
33             - partner is not an user: signup_url
34             - partner is an user: fallback on classic URL
35         """
36         if context is None:
37             context = {}
38         partner_obj = self.pool.get('res.partner')
39         if partner and not partner.user_ids:
40             contex_signup = dict(context, signup_valid=True)
41             signup_url = partner_obj._get_signup_url_for_action(cr, SUPERUSER_ID, [partner.id],
42                                                                     model=mail.model, res_id=mail.res_id,
43                                                                     context=contex_signup)[partner.id]
44             return _("""<span class='oe_mail_footer_access'><small>Access your messages and documents through <a style='color:inherit' href="%s">our Customer Portal</a></small></span>""") % signup_url
45         else:
46             return super(mail_mail, self)._get_partner_access_link(cr, uid, mail, partner=partner, context=context)