diff options
| author | Christophe Simonis <chs@odoo.com> | 2016-06-15 12:40:59 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2016-06-15 12:40:59 +0200 |
| commit | baf494c67ba7ecba331b24bcfa5eed9bde8a16da (patch) | |
| tree | 3b2c9ec3cacabcf0a5b0fb78a667d5e1b27505dc /addons/report/models | |
| parent | 133490b4d0e347d75bab20da8e5e0ad1f95d3a2d (diff) | |
| parent | 1d81bb06a47b1aee1b7a0dcdaa03084ddedf8b7b (diff) | |
[MERGE] forward port of branch saas-9 up to 1d81bb0
# Conflicts:
# addons/account_extra_reports/i18n/ca.po
# addons/account_extra_reports/i18n/fi.po
# addons/account_extra_reports/i18n/pl.po
# addons/account_extra_reports/i18n/te.po
# addons/account_extra_reports/i18n/zh_CN.po
# addons/account_full_reconcile/i18n/hu.po
# addons/account_full_reconcile/i18n/pl.po
# addons/crm/crm_lead_menu.xml
# addons/crm_claim/i18n/es_PE.po
# addons/crm_claim/i18n/hu.po
# addons/crm_claim/i18n/ja.po
# addons/crm_claim/i18n/pl.po
# addons/delivery/views/delivery_view.xml
# addons/product/product_view.xml
# addons/project_timesheet/i18n/es_PE.po
# addons/stock/stock_view.xml
Diffstat (limited to 'addons/report/models')
| -rw-r--r-- | addons/report/models/report.py | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/addons/report/models/report.py b/addons/report/models/report.py index 448f29b10a5..3aabbd3b929 100644 --- a/addons/report/models/report.py +++ b/addons/report/models/report.py @@ -28,6 +28,17 @@ from pyPdf import PdfFileWriter, PdfFileReader from reportlab.graphics.barcode import createBarcodeDrawing +# A lock occurs when the user wants to print a report having multiple barcode while the server is +# started in threaded-mode. The reason is that reportlab has to build a cache of the T1 fonts +# before rendering a barcode (done in a C extension) and this part is not thread safe. We attempt +# here to init the T1 fonts cache at the start-up of Odoo so that rendering of barcode in multiple +# thread does not lock the server. +try: + createBarcodeDrawing('Code128', value='foo', format='png', width=100, height=100, humanReadable=1).asString('png') +except Exception: + pass + + #-------------------------------------------------------------------------- # Helpers #-------------------------------------------------------------------------- @@ -115,11 +126,11 @@ class Report(osv.Model): """ # If the report is using a custom model to render its html, we must use it. # Otherwise, fallback on the generic html rendering. - try: - report_model_name = 'report.%s' % report_name - particularreport_obj = self.pool[report_model_name] + report_model_name = 'report.%s' % report_name + particularreport_obj = self.pool.get(report_model_name) + if particularreport_obj is not None: return particularreport_obj.render_html(cr, uid, ids, data=data, context=context) - except KeyError: + else: report = self._get_report_from_name(cr, uid, report_name) report_obj = self.pool[report.model] docs = report_obj.browse(cr, uid, ids, context=context) @@ -296,19 +307,20 @@ class Report(osv.Model): save_in_attachment['loaded_documents'] = {} if report.attachment: + records = self.pool[report.model].browse(cr, uid, ids) + filenames = self._attachment_filename(cr, uid, records, report) + attachments = None + if report.attachment_use: + attachments = self._attachment_stored(cr, uid, records, report, filenames=filenames) for record_id in ids: - obj = self.pool[report.model].browse(cr, uid, record_id) - filename = eval(report.attachment, {'object': obj, 'time': time}) + filename = filenames[record_id] # 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: + if attachments: + attachment = attachments[record_id] + if attachment: # Add the loaded pdf in the loaded_documents list - pdf = self.pool['ir.attachment'].browse(cr, uid, attach_ids[0]).datas + pdf = attachment.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) @@ -330,6 +342,20 @@ class Report(osv.Model): return Report._check_attachment_use( self._model, self._cr, self._uid, records.ids, report, context=self._context) + @api.model + def _attachment_filename(self, records, report): + return dict((record.id, eval(report.attachment, {'object': record, 'time': time})) for record in records) + + @api.model + def _attachment_stored(self, records, report, filenames=None): + if not filenames: + filenames = self._attachment_filename(records, report) + return dict((record.id, self.env['ir.attachment'].search([ + ('datas_fname', '=', filenames[record.id]), + ('res_model', '=', report.model), + ('res_id', '=', record.id) + ], limit=1)) for record in records) + def _check_wkhtmltopdf(self): return wkhtmltopdf_state |
