From 176404dd1444d5863ad677b9ed66a5a476b73e8c Mon Sep 17 00:00:00 2001 From: Simon Lejeune <sle@openerp.com> Date: Wed, 24 Sep 2014 17:33:00 +0200 Subject: [PATCH] [FIX] Report: attachment_use need attachment --- addons/report/models/report.py | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/addons/report/models/report.py b/addons/report/models/report.py index afcf4a3bcb0e..c2e1cd27a64b 100644 --- a/addons/report/models/report.py +++ b/addons/report/models/report.py @@ -316,27 +316,27 @@ class Report(osv.Model): save_in_attachment['model'] = report.model save_in_attachment['loaded_documents'] = {} - for record_id in ids: - obj = self.pool[report.model].browse(cr, uid, record_id) - filename = eval(report.attachment, {'object': obj, 'time': time}) - - # If the user has checked 'Reload from Attachment' - if report.attachment_use: - alreadyindb = [('datas_fname', '=', filename), - ('res_model', '=', report.model), - ('res_id', '=', record_id)] - attach_ids = self.pool['ir.attachment'].search(cr, uid, alreadyindb) - if attach_ids: - # Add the loaded pdf in the loaded_documents list - pdf = self.pool['ir.attachment'].browse(cr, uid, attach_ids[0]).datas - pdf = base64.decodestring(pdf) - save_in_attachment['loaded_documents'][record_id] = pdf - _logger.info('The PDF document %s was loaded from the database' % filename) - - continue # Do not save this document as we already ignore it - - # If the user has checked 'Save as Attachment Prefix' - if report.attachment: + if report.attachment: + for record_id in ids: + obj = self.pool[report.model].browse(cr, uid, record_id) + filename = eval(report.attachment, {'object': obj, 'time': time}) + + # If the user has checked 'Reload from Attachment' + if report.attachment_use: + alreadyindb = [('datas_fname', '=', filename), + ('res_model', '=', report.model), + ('res_id', '=', record_id)] + attach_ids = self.pool['ir.attachment'].search(cr, uid, alreadyindb) + if attach_ids: + # Add the loaded pdf in the loaded_documents list + pdf = self.pool['ir.attachment'].browse(cr, uid, attach_ids[0]).datas + pdf = base64.decodestring(pdf) + save_in_attachment['loaded_documents'][record_id] = pdf + _logger.info('The PDF document %s was loaded from the database' % filename) + + continue # Do not save this document as we already ignore it + + # If the user has checked 'Save as Attachment Prefix' if filename is False: # May be false if, for instance, the 'attachment' field contains a condition # preventing to save the file. -- GitLab