Merge lp:~openbias/openobject-addons/6.1_email_template_attachments into lp:~openbias/openobject-addons/6.1_produccion

Proposed by OpenBias
Status: Merged
Merged at revision: 6801
Proposed branch: lp:~openbias/openobject-addons/6.1_email_template_attachments
Merge into: lp:~openbias/openobject-addons/6.1_produccion
Diff against target: 144 lines (+92/-0)
5 files modified
email_template/__init__.py (+1/-0)
email_template/__openerp__.py (+1/-0)
email_template/email_template_attach.py (+37/-0)
email_template/email_template_attach_view.xml (+27/-0)
email_template/wizard/mail_compose_message.py (+26/-0)
To merge this branch: bzr merge lp:~openbias/openobject-addons/6.1_email_template_attachments
Reviewer Review Type Date Requested Status
OpenBias Approve
Jose Patricio Villarreal Pending
Review via email: mp+107142@code.launchpad.net

Description of the change

Add different attachment posibilities

To post a comment you must log in.
Revision history for this message
OpenBias (openbias) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'email_template/__init__.py'
2--- email_template/__init__.py 2011-10-05 11:38:46 +0000
3+++ email_template/__init__.py 2012-05-24 00:05:21 +0000
4@@ -22,5 +22,6 @@
5 import email_template
6 import wizard
7 import res_partner
8+import email_template_attach
9
10 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
11
12=== modified file 'email_template/__openerp__.py'
13--- email_template/__openerp__.py 2012-01-31 13:36:57 +0000
14+++ email_template/__openerp__.py 2012-05-24 00:05:21 +0000
15@@ -61,6 +61,7 @@
16 "data": [
17 'wizard/email_template_preview_view.xml',
18 'email_template_view.xml',
19+ 'email_template_attach_view.xml',
20 'res_partner_view.xml',
21 'wizard/email_compose_message_view.xml',
22 'security/ir.model.access.csv'
23
24=== added file 'email_template/email_template_attach.py'
25--- email_template/email_template_attach.py 1970-01-01 00:00:00 +0000
26+++ email_template/email_template_attach.py 2012-05-24 00:05:21 +0000
27@@ -0,0 +1,37 @@
28+# -*- coding: utf-8 -*-
29+##############################################################################
30+#
31+# OpenERP, Open Source Management Solution
32+# Copyright (C) 2009 Sharoon Thomas
33+# Copyright (C) 2010-2010 OpenERP SA (<http://www.openerp.com>)
34+#
35+# This program is free software: you can redistribute it and/or modify
36+# it under the terms of the GNU General Public License as published by
37+# the Free Software Foundation, either version 3 of the License, or
38+# (at your option) any later version.
39+#
40+# This program is distributed in the hope that it will be useful,
41+# but WITHOUT ANY WARRANTY; without even the implied warranty of
42+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43+# GNU General Public License for more details.
44+#
45+# You should have received a copy of the GNU General Public License
46+# along with this program. If not, see <http://www.gnu.org/licenses/>
47+#
48+##############################################################################
49+
50+from osv import osv, fields
51+from tools.translate import _
52+
53+class email_template(osv.osv):
54+ "Templates for sending Email"
55+
56+ _inherit = "email.template"
57+
58+ _columns = {
59+ 'ext': fields.char('Extension', size=128, help="Extensions of attachments that you want add to mail"),
60+ }
61+
62+email_template()
63+
64+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
65
66=== added file 'email_template/email_template_attach_view.xml'
67--- email_template/email_template_attach_view.xml 1970-01-01 00:00:00 +0000
68+++ email_template/email_template_attach_view.xml 2012-05-24 00:05:21 +0000
69@@ -0,0 +1,27 @@
70+<?xml version="1.0" encoding="UTF-8"?>
71+<openerp>
72+ <data>
73+
74+ <!--EMail add other attachments to Form view -->
75+ <record id="email_template_inherit_form" model="ir.ui.view">
76+ <field name="name">email.template.inherit.form</field>
77+ <field name="model">email.template</field>
78+ <field name="type">form</field>
79+ <field name="inherit_id" ref="email_template.email_template_form"/>
80+ <field name="arch" type="xml">
81+ <xpath expr="/form/notebook/page[@string='Advanced']/group[2]//notebook/page[@string='Attach existing files']" position="after">
82+ <page string="Extension of Attachments">
83+ <separator string="Example: xml, txt, ... (or all for all attachments)" colspan="4"/>
84+ <field name="ext"/>
85+ </page>
86+ </xpath>
87+ </field>
88+ </record>
89+
90+ </data>
91+</openerp>
92+
93+
94+
95+
96+
97
98=== modified file 'email_template/wizard/mail_compose_message.py'
99--- email_template/wizard/mail_compose_message.py 2012-05-11 01:28:23 +0000
100+++ email_template/wizard/mail_compose_message.py 2012-05-24 00:05:21 +0000
101@@ -77,6 +77,30 @@
102 'template_id' : lambda self, cr, uid, context={} : context.get('mail.compose.template_id', False)
103 }
104
105+ def _get_attachment(self, cr, uid, template_id, att_ids, context):
106+ #############################################################################################################################
107+ # #
108+ # This code are added by BIAS. #
109+ # Check "Extension" field (ext) of "Email Template" (email.template), if so, search for the object's attachments with #
110+ # the comma separated extensions defined in "Extension" field and add it to mail as attachment. #
111+ # #
112+ if template_id: #
113+ att_obj = self.pool.get('ir.attachment') #
114+ ctx = [('res_model','=',context.get('active_model')),('res_id','=',context.get('active_id'))] #
115+ all_attach = att_obj.search(cr, uid, ctx) #
116+ if context.get('mail.compose.template_id'): #
117+ template = self.pool.get('email.template').browse(cr, uid, context['mail.compose.template_id']) #
118+ for attachment_id in all_attach: #
119+ if template.ext: #
120+ if template.ext == 'all': #
121+ att_ids.append(attachment_id) #
122+ else: #
123+ for ext in template.ext.split(','): #
124+ if ext.strip().lower() == att_obj.browse(cr, uid, attachment_id).datas_fname[-3:].lower(): #
125+ att_ids.append(attachment_id) #
126+ #############################################################################################################################
127+ return att_ids
128+
129 def on_change_template(self, cr, uid, ids, use_template, template_id, email_from=None, email_to=None, context=None):
130 if context is None:
131 context = {}
132@@ -87,10 +111,12 @@
133 # use the original template values - to be rendered when actually sent
134 # by super.send_mail()
135 values = self.pool.get('email.template').read(cr, uid, template_id, self.fields_get_keys(cr, uid), context)
136+ values['attachment_ids'] = self._get_attachment(cr, uid, template_id, values['attachment_ids'], context)
137 else:
138 # render the mail as one-shot
139 values = self.pool.get('email.template').generate_email(cr, uid, template_id, res_id, context=context)
140 # retrofit generated attachments in the expected field format
141+ values['attachment_ids'] = self._get_attachment(cr, uid, template_id, values['attachment_ids'], context)
142 if values['attachments']:
143 attachment = values.pop('attachments')
144 attachment_obj = self.pool.get('ir.attachment')

Subscribers

People subscribed via source and target branches

to all changes: