[IMP] reports: support generic report_file field instead of report_xml ; add "file" attribute for <report> ; pending better refactoring after v6.0

bzr revid: odo@openerp.com-20101008142301-0os4ajp8xb9kt3cy
This commit is contained in:
Olivier Dony 2010-10-08 16:23:01 +02:00
parent 2171202b32
commit f92f272130
6 changed files with 19 additions and 22 deletions

View File

@ -433,15 +433,14 @@
<field name="report_name" select="1"/>
<field name="report_type"/>
<field name="report_file"/>
</group>
<notebook colspan="4">
<page string="Other Configuration">
<group col="2" colspan="2">
<separator string="RML Report" colspan="2"/>
<field name="report_rml"/>
<field name="header"/>
<field name="auto"/>
</group>
<group col="2" colspan="2">
<separator string="XML Report" colspan="2"/>
@ -456,6 +455,7 @@
<group col="2" colspan="2">
<separator string="Miscellaneous" colspan="2"/>
<field name="multi"/>
<field name="auto"/>
</group>
</page>
<page string="Security">

View File

@ -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',),

View File

@ -104,7 +104,8 @@
<rng:optional><rng:attribute name="multi"/></rng:optional>
<rng:optional><rng:attribute name="menu"/></rng:optional>
<rng:optional><rng:attribute name="keyword"/></rng:optional>
<rng:optional><rng:attribute name="rml"/></rng:optional>
<rng:optional><rng:attribute name="rml"/></rng:optional><!-- pending deprecation after v6.0 -->
<rng:optional><rng:attribute name="file"/></rng:optional>
<rng:optional><rng:attribute name="sxw"/></rng:optional>
<rng:optional><rng:attribute name="xml"/></rng:optional>
<rng:optional><rng:attribute name="xsl"/></rng:optional>

View File

@ -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':

View File

@ -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'):

View File

@ -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: