Skip to content
Permalink
Browse files

⬆️1️⃣2️⃣ res_users_signature, res_users_signature (hr)

  • Loading branch information...
fedoranvar committed Aug 6, 2019
1 parent de9408d commit 05cad9fcd6040bbb8ae5c74cd32a1b1a31e23805
@@ -1,31 +1,40 @@
Allows create signature templates for users. For example,
====================================
Signature templates for user email
====================================

---
Add templated signature for users

<p>${user.name}, ${user.function} of ${user.partner_id.company_id.name}</p>
Credits
=======

<p>${user.phone},
Contributors
------------
* `Ivan Yelizariev <https://it-projects.info/team/yelizariev>`__
* `Anvar Kildebekov <https://it-projects.info/team/fedoranvar>`__

% if user.mobile
Sponsors
--------
* `IT-Projects LLC <https://it-projects.info>`__

${user.mobile},
Maintainers
-----------
* `IT-Projects LLC <https://it-projects.info>`__

% endif
To get a guaranteed support you are kindly requested to purchase the module at `odoo apps store <https://apps.odoo.com/apps/modules/12.0/res_users_signature/>`__.

${user.email}</p>
Thank you for understanding!

<p><img src="data:image/png;base64,${user.company_id.logo_web}"/></p>
`IT-Projects Team <https://www.it-projects.info/team>`__

Will be converted to
Further information
===================

---
Demo: http://runbot.it-projects.info/demo/12.0/misc-addons

<p>Bob, sale manager of You Company</p>
HTML Description: https://apps.odoo.com/apps/modules/12.0/res_users_signature/

<p>+123456789, sales@example.com</p>
Usage instructions: `<doc/index.rst>`_

<p><img src="data:image/png;base64,ABCDE....12345="/></p>
Changelog: `<doc/changelog.rst>`_

Tested on 8.0 ab7b5d7732a7c222a0aea45bd173742acd47242d

Further information and discussion: https://yelizariev.github.io/odoo/module/2015/03/17/email-signature-template.html
Tested on Odoo 12.0 32c2666d189047db66eb7b1392ea34b086fd341e
@@ -1 +1,4 @@
from . import res_users_signature_models
# Copyright 2014 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2019 Anvar Kildebekov <https://it-projects.info/team/fedoranvar>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
@@ -1,15 +1,25 @@
# Copyright 2014 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2019 Anvar Kildebekov <https://it-projects.info/team/fedoranvar>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'Signature templates for user emails',
'version': '1.0.0',
'external_dependencies': {
'python': [
'html2text',
],
},
'version': '12.0.1.0.0',
'author': 'IT-Projects LLC, Ivan Yelizariev',
'license': 'LGPL-3',
'category': 'Social Network',
'images': ["images/main.png"],
'website': 'https://yelizariev.github.io',
'depends': ['base'],
'data': [
'res_users_signature_views.xml',
'views/res_users_signature_views.xml',
'security/res_users_signature_security.xml',
'security/ir.model.access.csv',
],
'installable': False

'installable': True
}
@@ -0,0 +1,4 @@
`1.0.0`
-------

- **Init version**
@@ -0,0 +1,45 @@
=====================================
Signature templates for user emails
=====================================

Installation
============

* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way

Usage
=====

* `Activate Developer Mode <https://odoo-development.readthedocs.io/en/latest/odoo/usage/debug-mode.html>`__
* Open signatures ``[ Settings ]>> [ Users and Companies ]>>[ Signatures ]``
* Click ``[ Create ]``
* Fill the fields
* For `properly-handled` signature: in html-editor enter 'Code View'-mode by clicking "</>"-icon

Template example:

---

<p>${user.name}</p>

<p>${user.phone},

% if user.mobile

${user.mobile},

% endif

${user.email}</p>

<p><img src="data:image/jpeg;base64,${user.company_id.logo}"/></p>

Will be converted to

---

<p>Bob</p>

<p>+123456789, sales@example.com</p>

<p><img src="data:image/jpeg;base64,ABCDE....12345="/></p>
Binary file not shown.
@@ -0,0 +1,4 @@
# Copyright 2014 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2019 Anvar Kildebekov <https://it-projects.info/team/fedoranvar>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import res_users_signature_models
@@ -1,44 +1,44 @@
from openerp import fields as old_fields
from openerp import api, models, fields, tools
# Copyright 2014 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2019 Anvar Kildebekov <https://it-projects.info/team/fedoranvar>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models, fields, tools
try:
from openerp.addons.email_template.email_template import mako_template_env
from odoo.addons.mail.models.mail_template import mako_template_env
except ImportError:
try:
from openerp.addons.mail.mail_template import mako_template_env
except ImportError:
pass
pass

from openerp.loglevels import ustr
from odoo.loglevels import ustr
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.utils import COMMASPACE
from email.utils import formatdate
from email.utils import make_msgid
from email import Encoders
from openerp.tools import html2text
from email import encoders

import html2text
import re
import base64

from openerp.addons.base.models.ir_mail_server import encode_rfc2822_address_header, encode_header, encode_header_param
from odoo.addons.base.models.ir_mail_server import encode_rfc2822_address_header, encode_header, encode_header_param


class ResUsers(models.Model):
_inherit = 'res.users'

signature_id = fields.Many2one('res.users.signature', string='Signature template', help='Keep empty to edit signature manually')
signature = fields.Html('Signature', sanitize=False)

'signature': old_fields.Html('Signature', sanitize=False)


@api.one
@api.onchange('signature_id')
def render_signature_id(self):
if not self.signature_id:
return
mako = mako_template_env.from_string(tools.ustr(self.signature_id.template))
html = mako.render({'user': self})
pttrn = re.compile(r"base64,b&#39;(.*?)&#39;") # {&#39;} stands for {'}
while pttrn.search(html): # while there is <img>-base64-tags in html
repl = "base64," + pttrn.search(html).group(1)
html = html.replace(pttrn.search(html).group(0), repl)
if html != self.signature:
self.signature = html

@@ -53,6 +53,7 @@ def write(self, vals):

class ResUsersSignature(models.Model):
_name = 'res.users.signature'
_description = 'Users signatures'

name = fields.Char('Name')
comment = fields.Text('Internal note')
@@ -112,7 +113,7 @@ class IrMailServer(models.Model):
def build_email(self, email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False,
attachments=None, message_id=None, references=None, object_id=False, subtype='plain', headers=None,
body_alternative=None, subtype_alternative='plain'):
""" copy-pasted from openerp/addons/base/models/ir_mail_server.py::build_email """
""" copy-pasted from odoo/addons/base/models/ir_mail_server.py::build_email """

ftemplate = '__image-%s__'
fcounter = 0
@@ -130,7 +131,6 @@ def build_email(self, email_from, email_to, subject, body, email_cc=None, email_
e = match.end()
data = body[s + len('"data:image/png;base64,'):e - 1]
new_body += body[pos:s]

fname = ftemplate % fcounter
fcounter += 1
attachments.append((fname, base64.b64decode(data)))
@@ -184,7 +184,7 @@ def build_email(self, email_from, email_to, subject, body, email_cc=None, email_
msg['Bcc'] = encode_rfc2822_address_header(COMMASPACE.join(email_bcc))
msg['Date'] = formatdate()
# Custom headers may override normal headers or provide additional ones
for key, value in headers.iteritems():
for key, value in headers.items():
msg[ustr(key).encode('utf-8')] = encode_header(value)

if subtype == 'html' and not body_alternative and html2text:
@@ -212,11 +212,11 @@ def build_email(self, email_from, email_to, subject, body, email_cc=None, email_

# The default RFC2231 encoding of Message.add_header() works in Thunderbird but not GMail
# so we fix it by using RFC2047 encoding for the filename instead.
part.set_param('name', filename_rfc2047)
part.sudo().set_param('name', filename_rfc2047)
part.add_header('Content-Disposition', 'attachment', filename=filename_rfc2047)
part.add_header('Content-ID', '<%s>' % filename_rfc2047) # NEW STUFF

part.set_payload(fcontent)
Encoders.encode_base64(part)
encoders.encode_base64(part)
msg.attach(part)
return msg
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--# Copyright 2014 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2019 Anvar kildebekov <https://it-projects.info/team/fedoranvar>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-->
<odoo>
<record id="administrator" model="res.groups">
<field name="name">Signature administrator</field>
<field name="comment">the user will have access to edit signatures</field>
<field name="users" eval="[(4, ref('base.user_admin'))]"/>
</record>

</data>
</openerp>
</odoo>
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--# Copyright 2019 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2019 Anvar kildebekov <https://it-projects.info/team/fedoranvar>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-->
<odoo>

<record id="view_users_form" model="ir.ui.view">
<field name="name">res.users.form</field>
@@ -58,23 +59,16 @@
</field>
</record>


<record id="action_update_signature_multi" model="ir.actions.server">
<record id="ir_update_signature_multi" model="ir.actions.server">
<field name="name">Update signatures</field>
<field name="model_id" ref="model_res_users_signature"/>
<field name="binding_model_id" ref="model_res_users_signature"/>
<field name="state">code</field>
<field name="code">
self.action_update_signature(cr, uid, context['active_ids'], context=context)
</field>
</record>

<record id="ir_update_signature_multi" model="ir.values">
<field eval="'client_action_multi'" name="key2"/>
<field eval="'res.users.signature'" name="model"/>
<field name="name">Update signatures</field>
<field eval="'ir.actions.server,%d'%action_update_signature_multi" name="value"/>
</record>

<record id="action_res_users_signature" model="ir.actions.act_window">
<field name="name">Signatures</field>
<field name="type">ir.actions.act_window</field>
@@ -86,5 +80,4 @@

<menuitem action="action_res_users_signature" id="menu_action_res_users_signature" parent="base.menu_users"/>

</data>
</openerp>
</odoo>
@@ -1,8 +1,42 @@
Signature templates for user emails (HR)
========================================
=========================================
Signature templates for user email (HR)
=========================================

Connector for modules:

* Signature templates for user emails
* HR

Credits
=======

Contributors
------------
* `Ivan Yelizariev <https://it-projects.info/team/yelizariev>`__

Sponsors
--------
* `IT-Projects LLC <https://it-projects.info>`__

Maintainers
-----------
* `IT-Projects LLC <https://it-projects.info>`__

To get a guaranteed support you are kindly requested to purchase the module at `odoo apps store <https://apps.odoo.com/apps/modules/12.0/res_users_signature_hr/>`__.

Thank you for understanding!

`IT-Projects Team <https://www.it-projects.info/team>`__

Further information
===================

Demo: http://runbot.it-projects.info/demo/12.0/res_users_signature_hr

HTML Description: https://apps.odoo.com/apps/modules/12.0/res_users_signature_hr/

Usage instructions: `<doc/index.rst>`_

Changelog: `<doc/changelog.rst>`_

Tested on Odoo 12.0 32c2666d189047db66eb7b1392ea34b086fd341e
@@ -1 +1,3 @@
# Copyright 2014 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
@@ -1,14 +1,16 @@
# Copyright 2014 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2019 Anvar Kildebekov <https://it-projects.info/team/fedoranvar>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': "Signature templates for user emails (HR)",
'version': '1.0.0',
'version': '12.0.1.0.0',
'author': 'IT-Projects LLC, Ivan Yelizariev',
'license': 'LGPL-3',
'category': 'Custom',
'images': ["images/main.png"],
'website': 'https://yelizariev.github.io',
'depends': ['res_users_signature', 'hr'],
'data': [
'views.xml',
],
'installable': False,
'data': [],
'installable': True,
'auto_install': True,
}
@@ -0,0 +1,4 @@
`1.0.0`
-------

- **Init version**

0 comments on commit 05cad9f

Please sign in to comment.
You can’t perform that action at this time.