Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make attachments of other models #85

Open
wants to merge 1 commit into
base: v5_backport
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 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
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