Skip to content

Commit

Permalink
IMP: Make attachments of other references
Browse files Browse the repository at this point in the history
  • Loading branch information
destanyol committed Mar 2, 2022
1 parent 1b27e92 commit 66ebd52
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
20 changes: 16 additions & 4 deletions poweremail_send_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,23 @@ def get_end_value(id, value):
if template.report_template.context:
ctx.update(eval(template.report_template.context))

if screen_vals['single_email'] and len(report_record_ids) > 1:
# The optional attachment will be generated as a single file for all these records
(result, format) = service.create(cr, uid, report_record_ids, data, ctx)
if template.report_template_object_reference:
if screen_vals['single_email'] and len(report_record_ids) > 1:
report_reference_ids = []
for record_id in report_record_ids:
report_reference_ids.append(self.get_value(cr, uid, template, template.report_template_object_reference, context, record_id))
record_to_print_ids = report_record_ids
else:
report_reference_id = self.get_value(cr, uid, template, template.report_template_object_reference, context, id)
record_to_print_ids = [report_reference_id]
else:
(result, format) = service.create(cr, uid, [id], data, ctx)
if screen_vals['single_email'] and len(report_record_ids) > 1:
record_to_print_ids = report_record_ids
else:
record_to_print_ids = [id]

(result, format) = service.create(cr, uid, record_to_print_ids, data, ctx)

attachment_id = self.pool.get('ir.attachment').create(cr, uid, {
'name': _('%s (Email Attachment)') % tools.ustr(vals['pem_subject']),
'datas': base64.b64encode(result),
Expand Down
3 changes: 3 additions & 0 deletions poweremail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def _get_model_name(
'report_template':fields.many2one(
'ir.actions.report.xml',
'Report to send'),
'report_template_object_reference': fields.char('Reference of the report', size=300, required=False),
#'report_template':fields.reference('Report to send',[('ir.actions.report.xml','Reports')],size=128),
'allowed_groups':fields.many2many(
'res.groups',
Expand Down Expand Up @@ -802,6 +803,8 @@ def _generate_attach_reports(self,
@param mail: Browse record of email object
@return: True
"""
if template.report_id:
record_ids = [template.report_id]
lang = get_value(cursor,
user,
record_ids[0],
Expand Down
4 changes: 2 additions & 2 deletions poweremail_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@
<separator string="Attachments (Report to attach)"
colspan="4" />
<field name="file_name" colspan="2" />
<field name="report_template" colspan="2"
domain="[('model','=',model_int_name)]" />
<field name="report_template" colspan="2"/>
<field name="report_template_object_reference" colspan="2"/>
<field name="tmpl_attachment_ids" colspan="4" nolabel="1"/>
<separator string="Log partner events"
colspan="4" />
Expand Down

0 comments on commit 66ebd52

Please sign in to comment.