From 0da07c281c5636b0dfefba91bdccb2f624145c57 Mon Sep 17 00:00:00 2001 From: Dhara Shah Date: Wed, 24 Dec 2008 17:00:37 +0530 Subject: [PATCH] changes for odt reports bzr revid: dsh@tinyerp.com-20081224113037-tth12tmw77p3lz7a --- .../base_report_designer.py | 13 +- .../tiny_sxw2rml/normalized_odt2rml.xsl | 681 ++++++++++++++++++ .../wizard/tiny_sxw2rml/tiny_sxw2rml.py | 12 +- addons/custom/corporate_odt_header.xml | 248 +++++++ 4 files changed, 947 insertions(+), 7 deletions(-) create mode 100644 addons/base_report_designer/wizard/tiny_sxw2rml/normalized_odt2rml.xsl create mode 100644 addons/custom/corporate_odt_header.xml diff --git a/addons/base_report_designer/base_report_designer.py b/addons/base_report_designer/base_report_designer.py index 69d31fda861..bf4c26fd4de 100644 --- a/addons/base_report_designer/base_report_designer.py +++ b/addons/base_report_designer/base_report_designer.py @@ -36,11 +36,11 @@ class report_xml(osv.osv): The use of this function is to get rml file from sxw file. ''' sxwval = StringIO(base64.decodestring(file_sxw)) - fp = tools.file_open('normalized_oo2rml.xsl', - subdir='addons/base_report_designer/wizard/tiny_sxw2rml') + fp = tools.file_open('normalized_odt2rml.xsl', + subdir='/home/dsh/my-work/bazaar/odt-sxw2ml') return {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))} - def upload_report(self, cr, uid, report_id, file_sxw, context): + def upload_report(self, cr, uid, report_id, file_sxw,file_type, context): ''' Untested function ''' @@ -48,9 +48,13 @@ class report_xml(osv.osv): sxwval = StringIO(base64.decodestring(file_sxw)) fp = tools.file_open('normalized_oo2rml.xsl', subdir='addons/base_report_designer/wizard/tiny_sxw2rml') + if file_type=='odt': + fp = tools.file_open('normalized_odt2rml.xsl', + subdir='/home/dsh/my-work/bazaar/odt-sxw2ml') report = pool.get('ir.actions.report.xml').write(cr, uid, [report_id], { 'report_sxw_content': base64.decodestring(file_sxw), - 'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())) + 'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())), + 'report_type' : file_type }) cr.commit() db = pooler.get_db_only(cr.dbname) @@ -59,6 +63,7 @@ class report_xml(osv.osv): def report_get(self, cr, uid, report_id, context={}): report = self.browse(cr, uid, report_id, context) return { + 'file_type' : report.report_type, 'report_sxw_content': report.report_sxw_content and base64.encodestring(report.report_sxw_content) or False, 'report_rml_content': report.report_rml_content and base64.encodestring(report.report_rml_content) or False } diff --git a/addons/base_report_designer/wizard/tiny_sxw2rml/normalized_odt2rml.xsl b/addons/base_report_designer/wizard/tiny_sxw2rml/normalized_odt2rml.xsl new file mode 100644 index 00000000000..b8c48673753 --- /dev/null +++ b/addons/base_report_designer/wizard/tiny_sxw2rml/normalized_odt2rml.xsl @@ -0,0 +1,681 @@ + + + + + + + + + + + + + + + + + + + + + + + + + ( + + , + + ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + white + + + + + + + + + + + ......... + + + + + + + + + + + + + 15 + 0 + + + + + + + + + + 6 + + + + + + ZapfDingbats + l + + + + + + + + + + + + + + + . + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + yes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LEFT + + + CENTER + + + RIGHT + + + JUSTIFY + + + + + + + + + + + + + + + + + + + + + + + + + + + Courier-BoldOblique + + + Courier-Bold + + + Courier-Oblique + + + Courier + + + + + + + Helvetica-BoldOblique + + + Helvetica-Bold + + + Helvetica-Oblique + + + Helvetica + + + + + + + Times-BoldItalic + + + Times-Bold + + + Times-Italic + + + Times-Roman + + + + + + + + Times-Roman + + + + + + +
+ + diff --git a/addons/base_report_designer/wizard/tiny_sxw2rml/tiny_sxw2rml.py b/addons/base_report_designer/wizard/tiny_sxw2rml/tiny_sxw2rml.py index 9bc62ac02c8..0d0ced599cb 100644 --- a/addons/base_report_designer/wizard/tiny_sxw2rml/tiny_sxw2rml.py +++ b/addons/base_report_designer/wizard/tiny_sxw2rml/tiny_sxw2rml.py @@ -151,6 +151,8 @@ class DomApi(DomApiGeneral): self.buildStylePropertiesDict() if self.styles_dom.getElementsByTagName("style:page-master").__len__()<>0: self.page_master = self.styles_dom.getElementsByTagName("style:page-master")[0] + if self.styles_dom.getElementsByTagName("style:page-layout").__len__()<>0 : + self.page_master = self.styles_dom.getElementsByTagName("style:page-layout")[0] self.document = self.content_dom.getElementsByTagName("office:document-content")[0] def buildStylePropertiesDict(self): @@ -265,7 +267,7 @@ class DomApi(DomApiGeneral): childs = self.style_dict[style_name].childNodes for c in childs: - if c.nodeType == c.ELEMENT_NODE and c.nodeName == "style:properties": + if c.nodeType == c.ELEMENT_NODE and c.nodeName.find("properties")>0 : for attr in c._attrs.keys(): res[attr] = c.getAttribute(attr).encode("latin-1") return res @@ -357,8 +359,12 @@ if __name__ == "__main__": fname = sys.argv[1] f = StringIO.StringIO(file(fname).read()) - - xsl = file(os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'normalized_oo2rml.xsl')).read() + xsl_file = 'normalized_oo2rml.xsl' + z = zipfile.ZipFile(fname,"r") + mimetype = z.read('mimetype') + if mimetype.split('/')[-1] == 'vnd.oasis.opendocument.text' : + xsl_file = 'normalized_odt2rml.xsl' + xsl = file(os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), xsl_file)).read() result = sxw2rml(f, xsl, output=opt.output, save_pict=False) print result diff --git a/addons/custom/corporate_odt_header.xml b/addons/custom/corporate_odt_header.xml new file mode 100644 index 00000000000..b27eeda8ccb --- /dev/null +++ b/addons/custom/corporate_odt_header.xml @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tiny sprl + + + + + + + + - + + + + + + Phone : + + + + + + + + Mail : + + + + + + + + + + + + + + + + Contact : Administrator + + + + + + + + \ No newline at end of file