[IMP] mail: add a method get_signature_footer to add a good signature on bottom of messages sent with the chatter and invite followers
bzr revid: chm@openerp.com-20130124094241-k9ophrwqhne611il
This commit is contained in:
parent
d4f857862e
commit
468fed66be
|
@ -20,6 +20,8 @@
|
|||
##############################################################################
|
||||
from openerp.osv import osv, fields
|
||||
from openerp import tools, SUPERUSER_ID
|
||||
from openerp.tools.translate import _
|
||||
from openerp.tools.mail import plaintext2html
|
||||
|
||||
class mail_followers(osv.Model):
|
||||
""" mail_followers holds the data related to the follow mechanism inside
|
||||
|
@ -103,6 +105,54 @@ class mail_notification(osv.Model):
|
|||
notify_pids.append(partner.id)
|
||||
return notify_pids
|
||||
|
||||
def get_signature_footer(self, cr, uid, user_id, res_model=None, res_id=None, context=None):
|
||||
footer = ""
|
||||
user = self.pool.get("res.users").browse(cr, uid, [user_id], context=context)[0]
|
||||
if user and user.signature:
|
||||
signature = plaintext2html(user.signature)
|
||||
else:
|
||||
signature = "--<br>%s" % user.name
|
||||
footer = tools.append_content_to_html(footer, signature, plaintext=False, container_tag='p')
|
||||
|
||||
company = None
|
||||
if user.company_id:
|
||||
company = user.company_id.website and "<a style='color:inherit' href='%s'>%s</a>" % (user.company_id.website, user.company_id.name) or user.company_id.name
|
||||
else:
|
||||
company = user.name
|
||||
|
||||
model_name = None
|
||||
record_name = None
|
||||
if res_model:
|
||||
res_model_obj = self.pool.get('ir.model')
|
||||
res_model_ids = res_model_obj.search(cr, uid, [('model', '=', res_model)], context=context)
|
||||
model_name = res_model_obj.browse(cr, uid, res_model_ids, context=context)[0].name
|
||||
if res_id:
|
||||
record_obj = self.pool.get(res_model)
|
||||
record = record_obj.browse(cr, uid, [res_id], context=context)[0]
|
||||
record_name = record.name
|
||||
|
||||
if company:
|
||||
if model_name:
|
||||
if record_name:
|
||||
signature_company = _("This message is written on the document '<b>%(record_name)s</b>' of '<b>%(model_name)s</b>' from '%(company)s'." % {
|
||||
'record_name': record_name,
|
||||
'model_name': model_name,
|
||||
'company': company
|
||||
})
|
||||
else:
|
||||
signature_company = _("This message is written on '<b>%(model_name)s</b>' from '%(company)s'." % {
|
||||
'model_name': model_name,
|
||||
'company': company
|
||||
})
|
||||
else:
|
||||
signature_company = _("This message is written from '%(company)s'." % {
|
||||
'company': company
|
||||
})
|
||||
|
||||
footer = tools.append_content_to_html(footer, "<small>%s</small>" % signature_company, plaintext=False, container_tag='div')
|
||||
|
||||
return footer
|
||||
|
||||
def _notify(self, cr, uid, msg_id, context=None):
|
||||
""" Send by email the notification depending on the user preferences """
|
||||
if context is None:
|
||||
|
@ -120,14 +170,11 @@ class mail_notification(osv.Model):
|
|||
# TDE FIXME: commented, to be improved in a future branch
|
||||
# quote_context = self.pool.get('mail.message').message_quote_context(cr, uid, msg_id, context=context)
|
||||
|
||||
mail_mail = self.pool.get('mail.mail')
|
||||
# add signature
|
||||
body_html = msg.body
|
||||
# if quote_context:
|
||||
# body_html = tools.append_content_to_html(body_html, quote_context, plaintext=False)
|
||||
signature = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0].signature or ''
|
||||
if signature:
|
||||
body_html = tools.append_content_to_html(body_html, signature, plaintext=True, container_tag='div')
|
||||
user = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0] or None
|
||||
signature_company = self.get_signature_footer(cr, uid, user_id=user.id, res_model=msg.model, res_id=msg.res_id, context=context)
|
||||
body_html = tools.append_content_to_html(body_html, signature_company, plaintext=False, container_tag='div')
|
||||
|
||||
mail_values = {
|
||||
'mail_message_id': msg.id,
|
||||
|
@ -137,6 +184,7 @@ class mail_notification(osv.Model):
|
|||
'state': 'outgoing',
|
||||
}
|
||||
mail_values['email_to'] = ', '.join(mail_values['email_to'])
|
||||
mail_mail = self.pool.get('mail.mail')
|
||||
email_notif_id = mail_mail.create(cr, uid, mail_values, context=context)
|
||||
try:
|
||||
return mail_mail.send(cr, uid, [email_notif_id], recipient_ids=notify_partner_ids, context=context)
|
||||
|
|
|
@ -177,7 +177,7 @@ class mail_mail(osv.Model):
|
|||
'id': mail.res_id,
|
||||
}
|
||||
url = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment)))
|
||||
text = _("""<p>Access this document <a href="%s">directly in OpenERP</a></p>""") % url
|
||||
text = _("""<small>Access this document <a href="%s">directly in OpenERP</a></small>""") % url
|
||||
body = tools.append_content_to_html(body, ("<div><p>%s</p></div>" % text), plaintext=False)
|
||||
except except_orm, e:
|
||||
pass
|
||||
|
|
|
@ -62,10 +62,9 @@ class invite_wizard(osv.osv_memory):
|
|||
# send an email
|
||||
if wizard.message:
|
||||
# add signature
|
||||
user_id = self.pool.get("res.users").read(cr, uid, [uid], fields=["signature"], context=context)[0]
|
||||
signature = user_id and user_id["signature"] or ''
|
||||
if signature:
|
||||
wizard.message = tools.append_content_to_html(wizard.message, signature, plaintext=True, container_tag='div')
|
||||
signature_company = self.pool.get('mail.notification').get_signature_footer(cr, uid, user_id=uid, res_model=wizard.res_model, res_id=wizard.res_id, context=context)
|
||||
wizard.message = tools.append_content_to_html(wizard.message, signature_company, plaintext=False, container_tag='div')
|
||||
|
||||
# send mail to new followers
|
||||
for follower_id in new_follower_ids:
|
||||
mail_mail = self.pool.get('mail.mail')
|
||||
|
|
|
@ -41,7 +41,7 @@ class mail_mail(osv.Model):
|
|||
if partner:
|
||||
contex_signup = dict(context or {}, signup_valid=True)
|
||||
partner = partner_obj.browse(cr, SUPERUSER_ID, partner.id, context=contex_signup)
|
||||
text = _("""<p>Access your messages and personal documents through <a href="%s">our Customer Portal</a></p>""") % partner.signup_url
|
||||
text = _("""<small>Access your messages and personal documents through <a href="%s">our Customer Portal</a></small>""") % partner.signup_url
|
||||
# partner is an user: add a link to the document if read access
|
||||
if partner.user_ids and mail.model and mail.res_id \
|
||||
and self.check_access_rights(cr, partner.user_ids[0].id, 'read', raise_exception=False):
|
||||
|
@ -49,8 +49,8 @@ class mail_mail(osv.Model):
|
|||
try:
|
||||
self.pool.get(mail.model).check_access_rule(cr, related_user.id, [mail.res_id], 'read', context=context)
|
||||
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]
|
||||
text = _("""<p>Access this document <a href="%s">directly in OpenERP</a></p>""") % url
|
||||
text = _("""<small>Access this document <a href="%s">directly in OpenERP</a></small>""") % url
|
||||
except except_orm, e:
|
||||
pass
|
||||
body = append_content_to_html(body, ("<div><p>%s</p></div>" % text), plaintext=False)
|
||||
body = append_content_to_html(body, text, plaintext=False, container_tag='div')
|
||||
return body
|
||||
|
|
Loading…
Reference in New Issue