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

Subscribers

People subscribed via source and target branches

to all changes: