- def _notify(self, cr, uid, msg_id, context=None):
- """ Send by email the notification depending on the user preferences """
- if context is None:
- context = {}
- # mail_notify_noemail (do not send email) or no partner_ids: do not send, return
- if context.get('mail_notify_noemail'):
- return True
- # browse as SUPERUSER_ID because of access to res_partner not necessarily allowed
- msg = self.pool.get('mail.message').browse(cr, SUPERUSER_ID, msg_id, context=context)
- notify_partner_ids = self.get_partners_to_notify(cr, uid, msg, context=context)
- if not notify_partner_ids:
+ def get_signature_footer(self, cr, uid, user_id, res_model=None, res_id=None, context=None):
+ """ Format a standard footer for notification emails (such as pushed messages
+ notification or invite emails).
+ Format:
+ <p>--<br />
+ Administrator
+ </p>
+ <div>
+ <small>Sent by <a ...>Your Company</a> using <a ...>OpenERP</a>.</small> OR
+ <small>Sent by Administrator using <a ...>OpenERP</a>.</small>
+ </div>
+ """
+ footer = ""
+ if not user_id:
+ return footer
+
+ # add user signature
+ user = self.pool.get("res.users").browse(cr, SUPERUSER_ID, [user_id], context=context)[0]
+ if 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')
+
+ # add company signature
+ if user.company_id.website:
+ website_url = ('http://%s' % user.company_id.website) if not user.company_id.website.lower().startswith(('http:', 'https:')) \
+ else user.company_id.website
+ company = "<a style='color:inherit' href='%s'>%s</a>" % (website_url, user.company_id.name)
+ else:
+ company = user.company_id.name
+ sent_by = _('Sent by %(company)s using %(openerp)s.')
+ signature_company = '<small>%s</small>' % (sent_by % {
+ 'company': company,
+ 'openerp': "<a style='color:inherit' href='https://www.openerp.com/'>OpenERP</a>"
+ })
+ footer = tools.append_content_to_html(footer, signature_company, plaintext=False, container_tag='div')
+
+ return footer
+
+ def update_message_notification(self, cr, uid, ids, message_id, partner_ids, context=None):
+ existing_pids = set()
+ new_pids = set()
+ new_notif_ids = []
+
+ for notification in self.browse(cr, uid, ids, context=context):
+ existing_pids.add(notification.partner_id.id)
+
+ # update existing notifications
+ self.write(cr, uid, ids, {'read': False}, context=context)
+
+ # create new notifications
+ new_pids = set(partner_ids) - existing_pids
+ for new_pid in new_pids:
+ new_notif_ids.append(self.create(cr, uid, {'message_id': message_id, 'partner_id': new_pid, 'read': False}, context=context))
+ return new_notif_ids
+
+ def _notify_email(self, cr, uid, ids, message_id, force_send=False, user_signature=True, context=None):
+ message = self.pool['mail.message'].browse(cr, SUPERUSER_ID, message_id, context=context)
+
+ # compute partners
+ email_pids = self.get_partners_to_email(cr, uid, ids, message, context=None)
+ if not email_pids: