Launchpad automatic translations update.
[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.osv.orm import except_orm
25 from openerp.tools import append_content_to_html
26 from openerp.tools.translate import _
27
28
29 class mail_mail(osv.Model):
30     """ Update of mail_mail class, to add the signin URL to notifications. """
31     _inherit = 'mail.mail'
32
33     def send_get_mail_body(self, cr, uid, mail, partner=None, context=None):
34         """ add a signin link inside the body of a mail.mail
35             :param mail: mail.mail browse_record
36             :param partner: browse_record of the specific recipient partner
37             :return: the resulting body_html
38         """
39         partner_obj = self.pool.get('res.partner')
40         body = mail.body_html
41         if partner:
42             contex_signup = dict(context or {}, signup_valid=True)
43             partner = partner_obj.browse(cr, SUPERUSER_ID, partner.id, context=contex_signup)
44             text = _("""<p>Access your messages and personal documents through <a href="%s">our Customer Portal</a></p>""") % partner.signup_url
45             # partner is an user: add a link to the document if read access
46             if partner.user_ids and mail.model and mail.res_id \
47                     and self.check_access_rights(cr, partner.user_ids[0].id, 'read', raise_exception=False):
48                 related_user = partner.user_ids[0]
49                 try:
50                     self.pool.get(mail.model).check_access_rule(cr, related_user.id, [mail.res_id], 'read', context=context)
51                     url = partner_obj._get_signup_url_for_action(cr, related_user.id, [partner.id], action='', res_id=mail.res_id, model=mail.model, context=context)[partner.id]
52                     text = _("""<p>Access this document <a href="%s">directly in OpenERP</a></p>""") % url
53                 except except_orm, e:
54                     pass
55             body = append_content_to_html(body, ("<div><p>%s</p></div>" % text), plaintext=False)
56         return body