Merge lp:~romaindeheele/poweremail/join-many-attachments into lp:poweremail

Proposed by Romain Deheele - Camptocamp
Status: Needs review
Proposed branch: lp:~romaindeheele/poweremail/join-many-attachments
Merge into: lp:poweremail
Diff against target: 262 lines (+89/-71)
4 files modified
poweremail_mailbox.py (+1/-1)
poweremail_send_wizard.py (+30/-29)
poweremail_template.py (+54/-39)
poweremail_template_view.xml (+4/-2)
To merge this branch: bzr merge lp:~romaindeheele/poweremail/join-many-attachments
Reviewer Review Type Date Requested Status
OpenERP Community Leaders Pending
Review via email: mp+82780@code.launchpad.net

Description of the change

Hello,

The two last commits on this branch allows to:
    - send several attachments linked on the object_name (ex: two different documents based on account.invoice)
    - send fixed attachments (ir.attachments linked directly on the template)

What do you think about it?

Romain Deheele

To post a comment you must log in.

Unmerged revisions

225. By <email address hidden>

allows to send fixed attachments(linked on poweremail.templates object id)

224. By <email address hidden>

Possibility to join several attachments on templates(compatible with events generation and wizard)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'poweremail_mailbox.py'
2--- poweremail_mailbox.py 2011-07-29 16:50:59 +0000
3+++ poweremail_mailbox.py 2011-11-19 16:19:23 +0000
4@@ -124,7 +124,7 @@
5 att_name = attachment.datas_fname or attachment.name
6 counter = 1
7 while att_name in payload:
8- att_name = "%s%d" % ( attachment.datas_fname or attachment.name, counter )
9+ att_name = "(%d)%s" % ( counter, attachment.datas_fname or attachment.name )
10 counter += 1
11 payload[att_name] = attachment.datas
12 result = core_obj.send_mail(cr, uid,
13
14=== modified file 'poweremail_send_wizard.py'
15--- poweremail_send_wizard.py 2011-07-29 15:36:50 +0000
16+++ poweremail_send_wizard.py 2011-11-19 16:19:23 +0000
17@@ -258,35 +258,36 @@
18 #Create partly the mail and later update attachments
19 mail_id = self.pool.get('poweremail.mailbox').create(cr, uid, vals, context)
20 mail_ids.append(mail_id)
21- if template.report_template:
22- reportname = 'report.' + self.pool.get('ir.actions.report.xml').read(cr, uid, template.report_template.id, ['report_name'], context)['report_name']
23- data = {}
24- data['model'] = self.pool.get('ir.model').browse(cr, uid, screen_vals['rel_model'], context).model
25+ if template.report_template_ids:
26+ for report_template in template.report_template_ids:
27+ reportname = 'report.' + self.pool.get('ir.actions.report.xml').read(cr, uid, report_template.id, ['report_name'], context)['report_name']
28+ data = {}
29+ data['model'] = self.pool.get('ir.model').browse(cr, uid, screen_vals['rel_model'], context).model
30
31- # Ensure report is rendered using template's language. If not found, user's launguage is used.
32- ctx = context.copy()
33- if template.lang:
34- ctx['lang'] = self.get_value(cr, uid, template, template.lang, context, id)
35- lang = self.get_value(cr, uid, template, template.lang, context, id)
36- if len(self.pool.get('res.lang').search(cr, uid, [('name','=',lang)], context = context)):
37- ctx['lang'] = lang
38- if not ctx.get('lang', False) or ctx['lang'] == 'False':
39- ctx['lang'] = self.pool.get('res.users').read(cr, uid, uid, ['context_lang'], context)['context_lang']
40- service = netsvc.LocalService(reportname)
41- if screen_vals['single_email'] and len(report_record_ids) > 1:
42- # The optional attachment will be generated as a single file for all these records
43- (result, format) = service.create(cr, uid, report_record_ids, data, ctx)
44- else:
45- (result, format) = service.create(cr, uid, [id], data, ctx)
46- attachment_id = self.pool.get('ir.attachment').create(cr, uid, {
47- 'name': _('%s (Email Attachment)') % tools.ustr(vals['pem_subject']),
48- 'datas': base64.b64encode(result),
49- 'datas_fname': tools.ustr(get_end_value(id, screen_vals['report']) or _('Report')) + "." + format,
50- 'description': vals['pem_body_text'] or _("No Description"),
51- 'res_model': 'poweremail.mailbox',
52- 'res_id': mail_id
53- }, context)
54- attachment_ids.append( attachment_id )
55+ # Ensure report is rendered using template's language. If not found, user's launguage is used.
56+ ctx = context.copy()
57+ if template.lang:
58+ ctx['lang'] = self.get_value(cr, uid, template, template.lang, context, id)
59+ lang = self.get_value(cr, uid, template, template.lang, context, id)
60+ if len(self.pool.get('res.lang').search(cr, uid, [('name','=',lang)], context = context)):
61+ ctx['lang'] = lang
62+ if not ctx.get('lang', False) or ctx['lang'] == 'False':
63+ ctx['lang'] = self.pool.get('res.users').read(cr, uid, uid, ['context_lang'], context)['context_lang']
64+ service = netsvc.LocalService(reportname)
65+ if screen_vals['single_email'] and len(report_record_ids) > 1:
66+ # The optional attachment will be generated as a single file for all these records
67+ (result, format) = service.create(cr, uid, report_record_ids, data, ctx)
68+ else:
69+ (result, format) = service.create(cr, uid, [id], data, ctx)
70+ attachment_id = self.pool.get('ir.attachment').create(cr, uid, {
71+ 'name': _('%s (Email Attachment)') % tools.ustr(vals['pem_subject']),
72+ 'datas': base64.b64encode(result),
73+ 'datas_fname': tools.ustr(get_end_value(id, screen_vals['report']) or _('Report')) + "." + format,
74+ 'description': vals['pem_body_text'] or _("No Description"),
75+ 'res_model': 'poweremail.mailbox',
76+ 'res_id': mail_id
77+ }, context)
78+ attachment_ids.append( attachment_id )
79
80 # Add document attachments
81 for attachment_id in screen_vals.get('attachment_ids',[]):
82@@ -311,7 +312,7 @@
83 name = name[:61] + '...'
84
85 model = res_id = False
86- if template.report_template and self.pool.get('res.request.link').search(cr, uid, [('object','=',data['model'])], context=context):
87+ if template.report_template_ids and self.pool.get('res.request.link').search(cr, uid, [('object','=',data['model'])], context=context):
88 model = data['model']
89 res_id = id
90 elif attachment_ids and self.pool.get('res.request.link').search(cr, uid, [('object','=','ir.attachment')], context=context):
91
92=== modified file 'poweremail_template.py'
93--- poweremail_template.py 2011-09-04 18:43:50 +0000
94+++ poweremail_template.py 2011-11-19 16:19:23 +0000
95@@ -253,6 +253,12 @@
96 'report_template':fields.many2one(
97 'ir.actions.report.xml',
98 'Report to send'),
99+ 'report_template_ids':fields.many2many(
100+ 'ir.actions.report.xml',
101+ 'template_report_rel',
102+ 'template_id',
103+ 'report_id',
104+ 'Report(s) to send'),
105 #'report_template':fields.reference('Report to send',[('ir.actions.report.xml','Reports')],size=128),
106 'allowed_groups':fields.many2many(
107 'res.groups',
108@@ -714,7 +720,7 @@
109 if len(name) > 64:
110 name = name[:61] + '...'
111 model = res_id = False
112- if template.report_template:
113+ if template.report_template_ids:
114 if self.pool.get('res.request.link').search(
115 cursor,
116 user,
117@@ -772,6 +778,7 @@
118 @param mail: Browse record of email object
119 @return: True
120 """
121+ list_attachment = []
122 lang = get_value(cursor,
123 user,
124 record_ids[0],
125@@ -782,50 +789,60 @@
126 ctx = context.copy()
127 ctx.update({'lang':lang})
128 template = self.browse(cursor, user, template.id, context=ctx)
129- reportname = 'report.' + \
130- self.pool.get('ir.actions.report.xml').read(
131- cursor,
132- user,
133- template.report_template.id,
134- ['report_name'],
135- context)['report_name']
136- service = netsvc.LocalService(reportname)
137- data = {}
138- data['model'] = template.model_int_name
139- (result, format) = service.create(cursor,
140- user,
141- record_ids,
142- data,
143- context)
144- attachment_obj = self.pool.get('ir.attachment')
145- new_att_vals = {
146- 'name': mail.pem_subject + ' (Email Attachment)',
147- 'datas': base64.b64encode(result),
148- 'datas_fname': tools.ustr(
149- get_value(
150- cursor,
151- user,
152- record_ids[0],
153- template.file_name,
154- template,
155- context
156- ) or 'Report') + "." + format,
157- 'description': mail.pem_subject or "No Description",
158- 'res_model': 'poweremail.mailbox',
159- 'res_id': mail.id
160- }
161- attachment_id = attachment_obj.create(cursor,
162+ for reports in template.report_template_ids:
163+ reportname = 'report.' + \
164+ self.pool.get('ir.actions.report.xml').read(
165+ cursor,
166+ user,
167+ reports.id,
168+ ['report_name'],
169+ context)['report_name']
170+ service = netsvc.LocalService(reportname)
171+ data = {}
172+ data['model'] = template.model_int_name
173+ (result, format) = service.create(cursor,
174+ user,
175+ record_ids,
176+ data,
177+ context)
178+ attachment_obj = self.pool.get('ir.attachment')
179+ new_att_vals = {
180+ 'name': mail.pem_subject + ' (Email Attachment)',
181+ 'datas': base64.b64encode(result),
182+ 'datas_fname': tools.ustr(
183+ get_value(
184+ cursor,
185+ user,
186+ record_ids[0],
187+ template.file_name,
188+ template,
189+ context
190+ ) or 'Report') + "." + format,
191+ 'description': mail.pem_subject or "No Description",
192+ 'res_model': 'poweremail.mailbox',
193+ 'res_id': mail.id
194+ }
195+ attachment_id = attachment_obj.create(cursor,
196 user,
197 new_att_vals,
198 context)
199- if attachment_id:
200+ list_attachment.append(attachment_id)
201+ self_attachments = self.pool.get('ir.attachment').search(cursor,
202+ user,
203+ [('res_id','=',template.id),
204+ ('res_model','=','poweremail.templates')],
205+ )
206+ if self_attachments:
207+ for self_id in self_attachments:
208+ list_attachment.append(self_id)
209+ if list_attachment:
210 self.pool.get('poweremail.mailbox').write(
211 cursor,
212 user,
213 mail.id,
214 {
215 'pem_attachments_ids':[
216- [6, 0, [attachment_id]]
217+ [6, 0, list_attachment]
218 ],
219 'mail_type':'multipart/mixed'
220 },
221@@ -953,7 +970,6 @@
222 template = self.browse(cursor, user, template_id, context=context)
223 if not template:
224 raise Exception("The requested template could not be loaded")
225-
226 if template.use_filter and template.filter:
227 filtered_record_ids=[]
228 for record in self.pool.get(template.object_name.model).browse(cursor, user, record_ids, context=context):
229@@ -965,7 +981,6 @@
230 if template.single_email and len(record_ids) > 1:
231 # We send a single email for several records
232 record_ids = record_ids[:1]
233-
234 for record_id in record_ids:
235 mailbox_id = self._generate_mailbox_item_from_template(
236 cursor,
237@@ -979,7 +994,7 @@
238 mailbox_id,
239 context=context
240 )
241- if template.report_template:
242+ if template.report_template_ids:
243 if template.single_email and len(report_record_ids) > 1:
244 # The optional attachment will be generated as a single file for all these records
245 self._generate_attach_reports(
246
247=== modified file 'poweremail_template_view.xml'
248--- poweremail_template_view.xml 2011-09-04 18:43:50 +0000
249+++ poweremail_template_view.xml 2011-11-19 16:19:23 +0000
250@@ -208,8 +208,10 @@
251 <separator string="Attachments (Report to attach)"
252 colspan="4" />
253 <field name="file_name" colspan="2" />
254- <field name="report_template" colspan="2"
255- domain="[('model','=',model_int_name)]" />
256+ <!--<field name="report_template" colspan="2"
257+ domain="[('model','=',model_int_name)]" />-->
258+ <field name="report_template_ids" colspan="2"
259+ domain="[('model','=',model_int_name)]"/>
260 <separator string="Log partner events"
261 colspan="4" />
262 <field name="partner_event" />

Subscribers

People subscribed via source and target branches