Holger Brunn
12 years ago
5 changed files with 201 additions and 0 deletions
-
1email_template_template/__init__.py
-
52email_template_template/__openerp__.py
-
21email_template_template/model/__init__.py
-
56email_template_template/model/email_template.py
-
71email_template_template/view/email_template.xml
@ -0,0 +1 @@ |
|||||
|
import model |
@ -0,0 +1,52 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2012 Therp BV (<http://therp.nl>). |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
{ |
||||
|
"name": "Templates for email templates", |
||||
|
"version": "1.0", |
||||
|
"author": "Therp BV", |
||||
|
"category": 'Tools', |
||||
|
'complexity': "expert", |
||||
|
"description": """If an organisation's email layout is a bit more |
||||
|
complicated, changes can be tedious when having to do that across several email |
||||
|
templates. So this addon allows to define templates for mails that is referenced |
||||
|
by other mail templates. |
||||
|
This way we can put the layout parts into the template template and only content |
||||
|
in the other templates. Changing the layout is then only a matter of changing |
||||
|
the template template. |
||||
|
|
||||
|
|
||||
|
Usage: |
||||
|
Create an email template with the related document model 'Email Templates'. Now |
||||
|
most of the fields gray out and you can only edit body_text and body_html. Be |
||||
|
sure to use ${body_text} and ${body_html} respectively in your template |
||||
|
template. |
||||
|
|
||||
|
Then select this newly created template templates in one of your actual |
||||
|
templates.""", |
||||
|
'website': 'http://therp.nl', |
||||
|
'images': [], |
||||
|
'depends': ['email_template'], |
||||
|
'data': [ |
||||
|
'view/email_template.xml', |
||||
|
], |
||||
|
"license": 'AGPL-3', |
||||
|
} |
||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
@ -0,0 +1,21 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2012 Therp BV (<http://therp.nl>). |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
import email_template |
@ -0,0 +1,56 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2012 Therp BV (<http://therp.nl>). |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from openerp.osv.orm import Model |
||||
|
from openerp.osv import fields |
||||
|
|
||||
|
|
||||
|
class email_template(Model): |
||||
|
_inherit = 'email.template' |
||||
|
|
||||
|
def _get_is_template_template(self, cr, uid, ids, fields_name, arg, |
||||
|
context=None): |
||||
|
cr.execute('''select |
||||
|
id, (select count(*) > 0 from email_template e |
||||
|
where email_template_id=email_template.id) |
||||
|
from email_template |
||||
|
where id in %s''', (tuple(ids),)) |
||||
|
return dict(cr.fetchall()) |
||||
|
|
||||
|
_columns = { |
||||
|
'email_template_id': fields.many2one('email.template', 'Template'), |
||||
|
'is_template_template': fields.function( |
||||
|
_get_is_template_template, type='boolean', |
||||
|
string='Is a template template'), |
||||
|
} |
||||
|
|
||||
|
def get_email_template(self, cr, uid, template_id=False, record_id=None, |
||||
|
context=None): |
||||
|
this = super(email_template, self).get_email_template( |
||||
|
cr, uid, template_id, record_id, context) |
||||
|
|
||||
|
if this.email_template_id and not this.is_template_template: |
||||
|
for field in ['body_html', 'body_text']: |
||||
|
if this[field] and this.email_template_id[field]: |
||||
|
this._data[this.id][field] = self.render_template( |
||||
|
cr, uid, this.email_template_id[field], |
||||
|
this.email_template_id.model, |
||||
|
this.id, this._context) |
||||
|
return this |
@ -0,0 +1,71 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record id="email_template_form" model="ir.ui.view"> |
||||
|
<field name="name">email.template.form</field> |
||||
|
<field name="model">email.template</field> |
||||
|
<field name="inherit_id" ref="email_template.email_template_form" /> |
||||
|
<field name="type">form</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<data> |
||||
|
<field name="name" position="after"> |
||||
|
<field name="is_template_template" invisible="1" /> |
||||
|
<field name="email_template_id" domain="[('email_template_id', '=', False), ('model_id', '=', %(email_template.model_email_template)s)]" |
||||
|
attrs="{'readonly': [('is_template_template','=',True), ('email_template_id','=',False)]}" |
||||
|
context="{'default_model_id': %(email_template.model_email_template)s}" |
||||
|
/> |
||||
|
|
||||
|
</field> |
||||
|
<field name="model_id" position="attributes"> |
||||
|
<attribute name="attrs"> |
||||
|
{'readonly': [('is_template_template','=',True)]} |
||||
|
</attribute> |
||||
|
</field> |
||||
|
<field name="email_from" position="attributes"> |
||||
|
<attribute name="required">0</attribute> |
||||
|
<attribute name="attrs"> |
||||
|
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} |
||||
|
</attribute> |
||||
|
</field> |
||||
|
<field name="email_to" position="attributes"> |
||||
|
<attribute name="required">0</attribute> |
||||
|
<attribute name="attrs"> |
||||
|
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} |
||||
|
</attribute> |
||||
|
</field> |
||||
|
<field name="email_cc" position="attributes"> |
||||
|
<attribute name="attrs"> |
||||
|
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} |
||||
|
</attribute> |
||||
|
</field> |
||||
|
<field name="email_bcc" position="attributes"> |
||||
|
<attribute name="attrs"> |
||||
|
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} |
||||
|
</attribute> |
||||
|
</field> |
||||
|
<field name="reply_to" position="attributes"> |
||||
|
<attribute name="attrs"> |
||||
|
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} |
||||
|
</attribute> |
||||
|
</field> |
||||
|
<field name="lang" position="attributes"> |
||||
|
<attribute name="attrs"> |
||||
|
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} |
||||
|
</attribute> |
||||
|
</field> |
||||
|
<field name="user_signature" position="attributes"> |
||||
|
<attribute name="attrs"> |
||||
|
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} |
||||
|
</attribute> |
||||
|
</field> |
||||
|
<field name="subject" position="attributes"> |
||||
|
<attribute name="required">0</attribute> |
||||
|
<attribute name="attrs"> |
||||
|
{'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} |
||||
|
</attribute> |
||||
|
</field> |
||||
|
</data> |
||||
|
</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue