andreparames
7 years ago
13 changed files with 316 additions and 0 deletions
-
77email_template_configurator/README.rst
-
1email_template_configurator/__init__.py
-
21email_template_configurator/__openerp__.py
-
2email_template_configurator/models/__init__.py
-
22email_template_configurator/models/email_template.py
-
17email_template_configurator/models/email_template_placeholder.py
-
33email_template_configurator/security/email_template_placeholder.xml
-
37email_template_configurator/tests/test_configurator.py
-
30email_template_configurator/views/email_template.xml
-
68email_template_configurator/views/email_template_placeholder.xml
-
1setup/email_template_configurator/odoo_addons/__init__.py
-
1setup/email_template_configurator/odoo_addons/email_template_configurator
-
6setup/email_template_configurator/setup.py
@ -0,0 +1,77 @@ |
|||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png |
|||
:target: https://www.gnu.org/licenses/agpl |
|||
:alt: License: AGPL-3 |
|||
|
|||
=========================== |
|||
email_template_configurator |
|||
=========================== |
|||
|
|||
This module implements a simpler interface for the email template dynamic |
|||
fields. A configurator allows the creation of predefined named replacement |
|||
strings, which can then be selected in the template. |
|||
|
|||
Configuration |
|||
============= |
|||
|
|||
To configure this module, you need to: |
|||
|
|||
#. Add your user to the "Template Placeholders Manager" group |
|||
|
|||
#. Go to Settings → Technical → Email → Template Placeholders to create new |
|||
predefined placeholders |
|||
|
|||
Usage |
|||
===== |
|||
|
|||
To use this module, you need to: |
|||
|
|||
#. Create a new template and go to the Configured Placeholders tab |
|||
|
|||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas |
|||
:alt: Try me on Runbot |
|||
:target: https://runbot.odoo-community.org/runbot/111/8.0 |
|||
|
|||
Bug Tracker |
|||
=========== |
|||
|
|||
Bugs are tracked on `GitHub Issues |
|||
<https://github.com/OCA/crm/issues>`_. In case of trouble, please |
|||
check there if your issue has already been reported. If you spotted it first, |
|||
help us smash it by providing detailed and welcomed feedback. |
|||
|
|||
Credits |
|||
======= |
|||
|
|||
Images |
|||
------ |
|||
|
|||
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_. |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* André Paramés Pereira (ACSONE) <github@andreparames.com> |
|||
|
|||
Do not contact contributors directly about support or help with technical issues. |
|||
|
|||
Funders |
|||
------- |
|||
|
|||
The development of this module has been financially supported by: |
|||
|
|||
* ACSONE SA/NV |
|||
|
|||
Maintainer |
|||
---------- |
|||
|
|||
.. image:: https://odoo-community.org/logo.png |
|||
:alt: Odoo Community Association |
|||
:target: https://odoo-community.org |
|||
|
|||
This module is maintained by the OCA. |
|||
|
|||
OCA, or the Odoo Community Association, is a nonprofit organization whose |
|||
mission is to support the collaborative development of Odoo features and |
|||
promote its widespread use. |
|||
|
|||
To contribute to this module, please visit https://odoo-community.org. |
@ -0,0 +1 @@ |
|||
from . import models |
@ -0,0 +1,21 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2018 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
{ |
|||
'name': 'Email Template Configurator', |
|||
'description': """ |
|||
Simplifies use of placeholders in email templates""", |
|||
'version': '8.0.1.0.0', |
|||
'license': 'AGPL-3', |
|||
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', |
|||
'website': 'https://github.com/OCA/crm', |
|||
'depends': [ |
|||
'email_template', |
|||
], |
|||
'data': [ |
|||
'security/email_template_placeholder.xml', |
|||
'views/email_template_placeholder.xml', |
|||
'views/email_template.xml', |
|||
], |
|||
} |
@ -0,0 +1,2 @@ |
|||
from . import email_template_placeholder |
|||
from . import email_template |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2018 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from openerp import api, fields, models |
|||
|
|||
|
|||
class EmailTemplate(models.Model): |
|||
|
|||
_inherit = 'email.template' |
|||
|
|||
# Fake field for auto-completing placeholder |
|||
placeholder_id = fields.Many2one( |
|||
'email.template.placeholder', string="Placeholder") |
|||
placeholder_value = fields.Char() |
|||
|
|||
@api.onchange('placeholder_id') |
|||
def _onchange_placeholder_id(self): |
|||
for tmpl in self: |
|||
if tmpl.placeholder_id: |
|||
tmpl.placeholder_value = tmpl.placeholder_id.placeholder |
|||
tmpl.placeholder_id = False |
@ -0,0 +1,17 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2018 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from openerp import fields, models |
|||
|
|||
|
|||
class EmailTemplatePlaceholder(models.Model): |
|||
|
|||
_name = 'email.template.placeholder' |
|||
_description = 'Email Template Placeholder' |
|||
|
|||
name = fields.Char(required=True) |
|||
model_id = fields.Many2one( |
|||
'ir.model', string='Model', required=True) |
|||
placeholder = fields.Char(required=True) |
|||
active = fields.Boolean(default=True) |
@ -0,0 +1,33 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- Copyright 2018 ACSONE SA/NV |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
|||
|
|||
<openerp> |
|||
<data> |
|||
|
|||
<record id="group_email_template_placeholders_manager" model="res.groups"> |
|||
<field name="name">Template Placeholders Manager</field> |
|||
</record> |
|||
|
|||
<record model="ir.model.access" id="email_template_placeholder_access_user"> |
|||
<field name="name">email.template.placeholder access user</field> |
|||
<field name="model_id" ref="model_email_template_placeholder"/> |
|||
<field name="group_id" ref="base.group_user"/> |
|||
<field name="perm_read" eval="1"/> |
|||
<field name="perm_create" eval="0"/> |
|||
<field name="perm_write" eval="0"/> |
|||
<field name="perm_unlink" eval="0"/> |
|||
</record> |
|||
|
|||
<record model="ir.model.access" id="email_template_placeholder_access_manager"> |
|||
<field name="name">email.template.placeholder access manager</field> |
|||
<field name="model_id" ref="model_email_template_placeholder"/> |
|||
<field name="group_id" ref="group_email_template_placeholders_manager"/> |
|||
<field name="perm_read" eval="1"/> |
|||
<field name="perm_create" eval="1"/> |
|||
<field name="perm_write" eval="1"/> |
|||
<field name="perm_unlink" eval="1"/> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1,37 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2018 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from openerp.tests import common |
|||
|
|||
|
|||
class test_configurator(common.TransactionCase): |
|||
|
|||
def test_configurator(self): |
|||
placeholders_obj = self.env['email.template.placeholder'] |
|||
templates_obj = self.env['email.template'] |
|||
invoice_model = self.env['ir.model'].search([ |
|||
('model', '=', 'account.invoice'), |
|||
]) |
|||
placeholders_vals = [ |
|||
{ |
|||
'name': 'Invoice partner name', |
|||
'model_id': invoice_model.id, |
|||
'placeholder': '${object.partner_id.name}', |
|||
}, |
|||
{ |
|||
'name': 'Invoice partner vat', |
|||
'model_id': invoice_model.id, |
|||
'placeholder': '${object.partner_id.vat}', |
|||
}, |
|||
] |
|||
for vals in placeholders_vals: |
|||
placeholder = placeholders_obj.create(vals) |
|||
|
|||
res = templates_obj.onchange({ |
|||
'placeholder_id': placeholder.id, |
|||
'placeholder_value': False, |
|||
}, 'placeholder_id', { |
|||
'placeholder_id': 1, |
|||
})['value'] |
|||
self.assertEqual(res['placeholder_value'], vals['placeholder']) |
@ -0,0 +1,30 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- Copyright 2018 ACSONE SA/NV |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
|||
|
|||
<openerp> |
|||
<data> |
|||
|
|||
<record model="ir.ui.view" id="email_template_form_view"> |
|||
<field name="name">email.template.form (in email_template_configurator)</field> |
|||
<field name="model">email.template</field> |
|||
<field name="inherit_id" ref="email_template.email_template_form"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//page[.//field[@name='model_object_field']]" position="attributes"> |
|||
<attribute name="groups">email_template_configurator.group_email_template_placeholders_manager</attribute> |
|||
</xpath> |
|||
<xpath expr="//page[.//field[@name='model_object_field']]" position="after"> |
|||
<page name="configured_placeholders" string="Configured Placeholders"> |
|||
<group> |
|||
<field name="placeholder_id" |
|||
domain="[('model_id','=',model_id)]" |
|||
options="{'no_quick_create':True,'no_create_edit':True}"/> |
|||
<field name="placeholder_value"/> |
|||
</group> |
|||
</page> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1,68 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- Copyright 2018 ACSONE SA/NV |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
|||
|
|||
<openerp> |
|||
<data> |
|||
|
|||
<record model="ir.ui.view" id="email_template_placeholder_form_view"> |
|||
<field name="name">email.template.placeholder.form (in email_template_configurator)</field> |
|||
<field name="model">email.template.placeholder</field> |
|||
<field name="arch" type="xml"> |
|||
<form> |
|||
<sheet> |
|||
<group> |
|||
<field name="name"/> |
|||
<field name="active"/> |
|||
</group> |
|||
<group> |
|||
<field name="model_id"/> |
|||
<field name="placeholder"/> |
|||
</group> |
|||
</sheet> |
|||
</form> |
|||
</field> |
|||
</record> |
|||
|
|||
<record model="ir.ui.view" id="email_template_placeholder_search_view"> |
|||
<field name="name">email.template.placeholder.search (in email_template_configurator)</field> |
|||
<field name="model">email.template.placeholder</field> |
|||
<field name="arch" type="xml"> |
|||
<search> |
|||
<field name="name"/> |
|||
<field name="model_id"/> |
|||
<group expand="0" string="Group by..."> |
|||
<filter string="Model" domain="[]" context="{'group_by':'model_id'}" icon="terp-accessories-archiver"/> |
|||
</group> |
|||
</search> |
|||
</field> |
|||
</record> |
|||
|
|||
<record model="ir.ui.view" id="email_template_placeholder_tree_view"> |
|||
<field name="name">email.template.placeholder.tree (in email_template_configurator)</field> |
|||
<field name="model">email.template.placeholder</field> |
|||
<field name="arch" type="xml"> |
|||
<tree> |
|||
<field name="name"/> |
|||
<field name="model_id"/> |
|||
<field name="placeholder"/> |
|||
</tree> |
|||
</field> |
|||
</record> |
|||
|
|||
<record model="ir.actions.act_window" id="email_template_placeholder_act_window"> |
|||
<field name="name">Template Placeholders</field> |
|||
<field name="res_model">email.template.placeholder</field> |
|||
<field name="view_mode">tree,form</field> |
|||
<field name="domain">[]</field> |
|||
<field name="context">{}</field> |
|||
</record> |
|||
|
|||
<record model="ir.ui.menu" id="email_template_placeholder_menu"> |
|||
<field name="name">Template Placeholders</field> |
|||
<field name="parent_id" ref="base.menu_email"/> |
|||
<field name="action" ref="email_template_placeholder_act_window"/> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1 @@ |
|||
__import__('pkg_resources').declare_namespace(__name__) |
@ -0,0 +1 @@ |
|||
../../../email_template_configurator |
@ -0,0 +1,6 @@ |
|||
import setuptools |
|||
|
|||
setuptools.setup( |
|||
setup_requires=['setuptools-odoo'], |
|||
odoo_addon=True, |
|||
) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue