From f92f272130c06d87cdde64bbe1d4c1f9f99cfb33 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 8 Oct 2010 16:23:01 +0200 Subject: [PATCH] [IMP] reports: support generic report_file field instead of report_xml ; add "file" attribute for ; pending better refactoring after v6.0 bzr revid: odo@openerp.com-20101008142301-0os4ajp8xb9kt3cy --- bin/addons/base/ir/ir.xml | 4 ++-- bin/addons/base/ir/ir_actions.py | 8 ++++++-- bin/import_xml.rng | 3 ++- bin/report/report_sxw.py | 22 +++++++--------------- bin/tools/convert.py | 2 +- bin/tools/yaml_import.py | 2 +- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/bin/addons/base/ir/ir.xml b/bin/addons/base/ir/ir.xml index 8d35e469bd8..5821e3cafdb 100644 --- a/bin/addons/base/ir/ir.xml +++ b/bin/addons/base/ir/ir.xml @@ -433,15 +433,14 @@ + - - @@ -456,6 +455,7 @@ + diff --git a/bin/addons/base/ir/ir_actions.py b/bin/addons/base/ir/ir_actions.py index 297aebaf5dc..195241afb21 100644 --- a/bin/addons/base/ir/ir_actions.py +++ b/bin/addons/base/ir/ir_actions.py @@ -114,9 +114,13 @@ class report_xml(osv.osv): 'report_xsl': fields.char('XSL path', size=256), 'report_xml': fields.char('XML path', size=256, help=''), - 'report_rml': fields.char('RML path', size=256, help="The .rml path of the file or NULL if the content is in report_rml_content"), - 'report_sxw': fields.function(_report_sxw, method=True, type='char', string='SXW path'), + # Pending deprecation... to be replaced by report_file as this object will become the default report object (not so specific to RML anymore) + 'report_rml': fields.char('Main report file path', size=256, help="The path to the main report file (depending on Report Type) or NULL if the content is in another data field"), + # temporary related field as report_rml is pending deprecation - this field will replace report_rml after v6.0 + 'report_file': fields.related('report_rml', type="char", size=256, required=False, readonly=False, string='Report file', help="The path to the main report file (depending on Report Type) or NULL if the content is in another field", store=True), + + 'report_sxw': fields.function(_report_sxw, method=True, type='char', string='SXW path'), 'report_sxw_content_data': fields.binary('SXW content'), 'report_rml_content_data': fields.binary('RML content'), 'report_sxw_content': fields.function(_report_content, fnct_inv=_report_content_inv, method=True, type='binary', string='SXW content',), diff --git a/bin/import_xml.rng b/bin/import_xml.rng index 2ddc2336cc0..7b5a889a110 100644 --- a/bin/import_xml.rng +++ b/bin/import_xml.rng @@ -104,7 +104,8 @@ - + + diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index 3cd448eac58..7707ef2fff0 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -19,24 +19,18 @@ # ############################################################################## from lxml import etree -import traceback, sys import StringIO import cStringIO import base64 -import copy -import locale from datetime import datetime import os import re import time from interface import report_rml import preprocess -import ir -import netsvc -import osv +import logging import pooler import tools -import warnings import zipfile import common from osv.fields import float as float_class, function as function_class @@ -319,7 +313,7 @@ class rml_parse(object): if not self._transl_regex.match(piece_list[pn]): source_string = piece_list[pn].replace('\n', ' ').strip() if len(source_string): - translated_string = transl_obj._get_source(self.cr, self.uid, self.name, 'rml', lang, source_string) + translated_string = transl_obj._get_source(self.cr, self.uid, self.name, ('report', 'rml'), lang, source_string) if translated_string: piece_list[pn] = piece_list[pn].replace(source_string, translated_string) text = ''.join(piece_list) @@ -434,8 +428,8 @@ class report_sxw(report_rml, preprocess.report): result = self.create_single_pdf(cr, uid, [obj.id], data, report_xml, context) if not result: return False - try: - if aname: + if aname: + try: name = aname+'.'+result[1] pool.get('ir.attachment').create(cr, uid, { 'name': aname, @@ -445,11 +439,9 @@ class report_sxw(report_rml, preprocess.report): 'res_id': obj.id, }, context=context ) - cr.commit() - except Exception,e: - import traceback, sys - tb_s = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)) - netsvc.Logger().notifyChannel('report', netsvc.LOG_ERROR,str(e)) + except Exception: + #TODO: should probably raise a proper osv_except instead, shouldn't we? see LP bug #325632 + logging.getLogger('report').error('Could not create saved report attachment', exc_info=True) results.append(result) if results: if results[0][1]=='pdf': diff --git a/bin/tools/convert.py b/bin/tools/convert.py index a8749514958..ec3869f322f 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -300,7 +300,7 @@ form: module.record_id""" % (xml_id,) for dest,f in (('name','string'),('model','model'),('report_name','name')): res[dest] = rec.get(f,'').encode('utf8') assert res[dest], "Attribute %s of report is empty !" % (f,) - for field,dest in (('rml','report_rml'),('xml','report_xml'),('xsl','report_xsl'),('attachment','attachment'),('attachment_use','attachment_use')): + for field,dest in (('rml','report_rml'),('file','report_file'),('xml','report_xml'),('xsl','report_xsl'),('attachment','attachment'),('attachment_use','attachment_use')): if rec.get(field): res[dest] = rec.get(field).encode('utf8') if rec.get('auto'): diff --git a/bin/tools/yaml_import.py b/bin/tools/yaml_import.py index 814779b3f36..7f271767a04 100644 --- a/bin/tools/yaml_import.py +++ b/bin/tools/yaml_import.py @@ -675,7 +675,7 @@ class YamlInterpreter(object): for dest, f in (('name','string'), ('model','model'), ('report_name','name')): values[dest] = getattr(node, f) assert values[dest], "Attribute %s of report is empty !" % (f,) - for field,dest in (('rml','report_rml'),('xml','report_xml'),('xsl','report_xsl'),('attachment','attachment'),('attachment_use','attachment_use')): + for field,dest in (('rml','report_rml'),('file','report_file'),('xml','report_xml'),('xsl','report_xsl'),('attachment','attachment'),('attachment_use','attachment_use')): if getattr(node, field): values[dest] = getattr(node, field) if node.auto: