← Back to team overview

openerp-community-reviewer team mailing list archive

lp:~therp-nl/server-env-tools/7.0-add_email_template_conditional_attachment into lp:server-env-tools

 

Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/server-env-tools/7.0-add_email_template_conditional_attachment into lp:server-env-tools.

Requested reviews:
  Server Environment And Tools Core Editors (server-env-tools-core-editors)

For more details, see:
https://code.launchpad.net/~therp-nl/server-env-tools/7.0-add_email_template_conditional_attachment/+merge/202740

See the description in __openerp__.py

-- 
https://code.launchpad.net/~therp-nl/server-env-tools/7.0-add_email_template_conditional_attachment/+merge/202740
Your team Server Environment And Tools Core Editors is requested to review the proposed merge of lp:~therp-nl/server-env-tools/7.0-add_email_template_conditional_attachment into lp:server-env-tools.
=== added directory 'email_template_conditional_attachment'
=== added file 'email_template_conditional_attachment/__init__.py'
--- email_template_conditional_attachment/__init__.py	1970-01-01 00:00:00 +0000
+++ email_template_conditional_attachment/__init__.py	2014-01-22 20:10:39 +0000
@@ -0,0 +1,1 @@
+from . import model

=== added file 'email_template_conditional_attachment/__openerp__.py'
--- email_template_conditional_attachment/__openerp__.py	1970-01-01 00:00:00 +0000
+++ email_template_conditional_attachment/__openerp__.py	2014-01-22 20:10:39 +0000
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2014 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' : 'Conditional attachments on email templates',
+    'version' : '0.1',
+    'author' : 'Therp BV',
+    'category': 'Email',
+    'website': 'http://therp.nl',
+    'depends' : [
+        'email_template',
+        ],
+    'data': [
+        'view/email_template.xml',
+        'security/ir.model.access.csv',
+        ],
+    'description': """
+This module allows you to configure a set of static attachments on an email template
+that appear on generated emails conditionally. Conditions are specified in the
+technical *domain* notation that is widely used in OpenERP.
+
+For instance, if you want
+a specific attachment to only be sent out with invoices to Dutch speaking customers
+of a specific company, you can encode this on the template for outgoing invoices
+as a regular domain expression against the invoice model:
+
+    [('company_id', '=', 1), ('partner_id.lang', '=', 'nl_NL')]
+
+Generated emails will then only contain the attachment if the associated invoice
+meets these requirements.
+
+You can configure the conditional attachments on the *Advanced* tab of the email
+template form view.
+
+Again, only static attachments (so no dynamically generated reports) are currently
+supported. An example of usage is attaching a document containing general terms and
+conditions in various languages which can vary per company or customer region.
+    """,
+}

=== added directory 'email_template_conditional_attachment/i18n'
=== added file 'email_template_conditional_attachment/i18n/email_template_conditional_attachment.pot'
--- email_template_conditional_attachment/i18n/email_template_conditional_attachment.pot	1970-01-01 00:00:00 +0000
+++ email_template_conditional_attachment/i18n/email_template_conditional_attachment.pot	2014-01-22 20:10:39 +0000
@@ -0,0 +1,36 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+# 	* email_template_conditional_attachment
+#
+msgid ""
+msgstr ""
+
+#. module: email_template_conditional_attachment
+#: field:email.template.conditional.attachment,domain:0
+msgid "Domain"
+msgstr ""
+
+#. module: email_template_conditional_attachment
+#: field:email.template.conditional.attachment,template_id:0
+msgid "Email template"
+msgstr ""
+
+#. module: email_template_conditional_attachment
+#: model:ir.model,name:email_template_conditional_attachment.model_email_template
+msgid "Email Templates"
+msgstr ""
+
+#. module: email_template_conditional_attachment
+#: model:ir.model,name:email_template_conditional_attachment.model_email_template_conditional_attachment
+msgid "email.template.conditional.attachment"
+msgstr ""
+
+#. module: email_template_conditional_attachment
+#: field:email.template.conditional.attachment,attachment_id:0
+msgid "Attachment"
+msgstr ""
+
+#. module: email_template_conditional_attachment
+#: view:email.template:0 field:email.template,conditional_attachment_ids:0
+msgid "Conditional attachments"
+msgstr ""

=== added file 'email_template_conditional_attachment/i18n/nl.po'
--- email_template_conditional_attachment/i18n/nl.po	1970-01-01 00:00:00 +0000
+++ email_template_conditional_attachment/i18n/nl.po	2014-01-22 20:10:39 +0000
@@ -0,0 +1,48 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#	* email_template_conditional_attachment
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-01-22 18:49+0000\n"
+"PO-Revision-Date: 2014-01-22 18:49+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: email_template_conditional_attachment
+#: field:email.template.conditional.attachment,domain:0
+msgid "Domain"
+msgstr "Domein"
+
+#. module: email_template_conditional_attachment
+#: field:email.template.conditional.attachment,template_id:0
+msgid "Email template"
+msgstr "Emailsjabloon"
+
+#. module: email_template_conditional_attachment
+#: model:ir.model,name:email_template_conditional_attachment.model_email_template
+msgid "Email Templates"
+msgstr "Emailsjablonen"
+
+#. module: email_template_conditional_attachment
+#: model:ir.model,name:email_template_conditional_attachment.model_email_template_conditional_attachment
+msgid "email.template.conditional.attachment"
+msgstr "email.template.conditional.attachment"
+
+#. module: email_template_conditional_attachment
+#: field:email.template.conditional.attachment,attachment_id:0
+msgid "Attachment"
+msgstr "Bijlage"
+
+#. module: email_template_conditional_attachment
+#: view:email.template:0
+#: field:email.template,conditional_attachment_ids:0
+msgid "Conditional attachments"
+msgstr "Voorwaardelijke bijlagen"
+

=== added directory 'email_template_conditional_attachment/model'
=== added file 'email_template_conditional_attachment/model/__init__.py'
--- email_template_conditional_attachment/model/__init__.py	1970-01-01 00:00:00 +0000
+++ email_template_conditional_attachment/model/__init__.py	2014-01-22 20:10:39 +0000
@@ -0,0 +1,2 @@
+from . import email_template_conditional_attachment
+from . import email_template

=== added file 'email_template_conditional_attachment/model/email_template.py'
--- email_template_conditional_attachment/model/email_template.py	1970-01-01 00:00:00 +0000
+++ email_template_conditional_attachment/model/email_template.py	2014-01-22 20:10:39 +0000
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2014 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 ast import literal_eval
+from openerp.osv import orm, fields
+
+
+class EmailTemplate(orm.Model):
+    _inherit = 'email.template'
+    _columns = {
+        'conditional_attachment_ids': fields.one2many(
+            'email.template.conditional.attachment',
+            'template_id', 'Conditional attachments'),
+        }
+
+    def generate_email(self, cr, uid, template_id, res_id, context=None):
+        """
+        Go through the conditional attachments and select those
+        of which the domain matches the resource.
+        """
+        res = super(EmailTemplate, self).generate_email(
+            cr, uid, template_id, res_id, context=context)
+        if res_id:
+            template = self.browse(cr, uid, template_id, context=context)
+            for attachment in template.conditional_attachment_ids:
+                domain = (
+                    ['&', ('id', '=', res_id)] +
+                    literal_eval(attachment.domain))
+                if self.pool.get(template.model).search(
+                        cr, uid, domain, context=context):
+                    res['attachment_ids'].append(
+                        attachment.attachment_id.id)
+        return res
+            

=== added file 'email_template_conditional_attachment/model/email_template_conditional_attachment.py'
--- email_template_conditional_attachment/model/email_template_conditional_attachment.py	1970-01-01 00:00:00 +0000
+++ email_template_conditional_attachment/model/email_template_conditional_attachment.py	2014-01-22 20:10:39 +0000
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2014 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 import orm, fields
+
+
+class EmailTemplateConditionalAttachment(orm.Model):
+    _name = 'email.template.conditional.attachment'
+    
+    _columns = {
+        'template_id': fields.many2one(
+            'email.template', 'Email template', required=True,
+            ondelete='CASCADE'),
+        'attachment_id': fields.many2one(
+            'ir.attachment', 'Attachment', required=True),
+        'domain': fields.char(
+            size=256, string='Domain', required=True),
+        }

=== added directory 'email_template_conditional_attachment/security'
=== added file 'email_template_conditional_attachment/security/ir.model.access.csv'
--- email_template_conditional_attachment/security/ir.model.access.csv	1970-01-01 00:00:00 +0000
+++ email_template_conditional_attachment/security/ir.model.access.csv	2014-01-22 20:10:39 +0000
@@ -0,0 +1,3 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_email_template_conditional_attachment,email.template,model_email_template_conditional_attachment,,1,1,1,0
+access_email_template_conditional_attachment_system,email.template system,model_email_template_conditional_attachment,base.group_system,1,1,1,1

=== added directory 'email_template_conditional_attachment/static'
=== added directory 'email_template_conditional_attachment/static/src'
=== added directory 'email_template_conditional_attachment/static/src/img'
=== added file 'email_template_conditional_attachment/static/src/img/icon.png'
Binary files email_template_conditional_attachment/static/src/img/icon.png	1970-01-01 00:00:00 +0000 and email_template_conditional_attachment/static/src/img/icon.png	2014-01-22 20:10:39 +0000 differ
=== added directory 'email_template_conditional_attachment/view'
=== added file 'email_template_conditional_attachment/view/email_template.xml'
--- email_template_conditional_attachment/view/email_template.xml	1970-01-01 00:00:00 +0000
+++ email_template_conditional_attachment/view/email_template.xml	2014-01-22 20:10:39 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        
+        <record model="ir.ui.view" id="email_template_form">
+            <field name="name">Add list of conditional attachments to email template form</field>
+            <field name="model">email.template</field>
+            <field name="inherit_id" ref="email_template.email_template_form" />
+            <field name="arch" type="xml">
+                <field name="attachment_ids" position="after">
+                    <field name="conditional_attachment_ids" colspan="4">
+                        <tree string="Conditional attachments" editable="bottom">
+                            <field name="attachment_id" />
+                            <field name="domain" />
+                        </tree>
+                    </field>
+                </field>
+            </field>
+        </record>
+        
+    </data>
+</openerp>


Follow ups