diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..890ff010 --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +bin/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo + +# Pycharm +.idea + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Rope +.ropeproject + +# Sphinx documentation +docs/_build/ + +# Backup files +*~ +*.swp diff --git a/.hgignore b/.hgignore deleted file mode 100644 index ca621bc4..00000000 --- a/.hgignore +++ /dev/null @@ -1,24 +0,0 @@ -syntax: glob -**/*.pyc -*.pyc -*.pyo -*.swp -.tmp* -*~ -*.egg-info -dist/* -build/* -lib/* -output/* -*.orig -*.log -.settings/* -storage/* -.project -.idea -.pydevproject -*.db -.ropeproject/* -.mob - - diff --git a/.hgtags b/.hgtags deleted file mode 100644 index 41e72145..00000000 --- a/.hgtags +++ /dev/null @@ -1,15 +0,0 @@ -ae59b92cb6bda5ada7fffd01d9006c800a6da9f4 TAG_1.0 -392758bf61eb33256bc3a46e16ca15d6195bc8a8 TAG_1.1 -b6c64ac6e39936d1ee13c58c14bf62b04c5b5202 TAG_1.2 -cd840bda3fa0d8cd4290700b299a8bad2c99606d TAG_1.2.1 -092018f8f6cab00d7198e0fdd2489e0d41c33f9f TAG_1.2.2 -2203f0ccc2e2d728c81080d37cba4559d705917e TAG_1.2.3 -d6fa2a1477bc1f7a3590eb425ab7f907779cb732 TAG_1.2.4 -067b603cc82e6403b66fedd1636f50ff104c3fee TAG_1.2.5 -ce6b34e125174856e86c108399dfbb0eb84a7418 TAG_1.3 -a9d3f37477695c6255e7f603fa47defcfbd3a2af TAG_1.3.1 -801e4bf837a28a824637570ec19bd6bc148c6837 TAG_2.0b1 -2e68df0df26d1dbcb28b30f8b626d8b237650751 TAG_2.0b2 -0118ec4a766ed2a279ac2d6caaf71e0c3db0023b TAG_8.0.2.0 -77b8df6148164972274ab8246a56e053357d61ca TAG_8.0.2.0 -65b3c62a20f1f7f06c36783bc3fa2cc52dd8a0b3 TAG_8.0.2.1 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..75e8bc4c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,38 @@ +sudo: false +cache: pip + +addons: + apt: + packages: + - expect-dev # provides unbuffer utility + - python-lxml # because pip installation is slow + +language: python + +python: + - "2.7" + +env: + global: + - VERSION="9.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0" + - TRANSIFEX_USER='transbot@odoo-community.org' + - secure: NUsXwVrMntcqge1ozKW+DSkP7dq+Rla6JVvFF2c89/g+zJaIqQRi8EQBLoqNwCdMk+rjpQeZt/JPELjH+EzPcmGddhDxOgVB3nUT9LvFXGCHF+NjmHXqyba4tuc7BnpG1WDD+rSlxVCt1aIjNIhhaZ4ic0rCWpKNYu/yFTsmChc= + matrix: + - LINT_CHECK="1" + - TRANSIFEX="1" + - TESTS="1" ODOO_REPO="odoo/odoo" + - TESTS="1" ODOO_REPO="OCA/OCB" + +virtualenv: + system_site_packages: true + +install: + - git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools + - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} + - travis_install_nightly + +script: + - travis_run_tests + +after_success: + - travis_after_tests_success diff --git a/LICENSE b/LICENSE index dba13ed2..3ffc5678 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ - GNU AFFERO GENERAL PUBLIC LICENSE +GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. @@ -633,8 +633,8 @@ the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -658,4 +658,4 @@ specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see -. +. \ No newline at end of file diff --git a/README.md b/README.md index 51709d3d..d57e0d22 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,43 @@ -### README ### +[![Runbot Status](https://runbot.odoo-community.org/runbot/badge/flat/143/9.0.svg)](https://runbot.odoo-community.org/runbot/repo/github-com-oca-reporting-engine-143) +[![Build Status](https://travis-ci.org/OCA/reporting-engine.svg?branch=9.0)](https://travis-ci.org/OCA/reporting-engine) +[![Coverage Status](https://img.shields.io/coveralls/OCA/reporting-engine.svg)](https://coveralls.io/r/OCA/reporting-engine?branch=9.0) +OCA alternative reporting engines and reporting utilities for Odoo +================================================================== -### LibreOffice Report Engine for Odoo/OpenERP ### +This repository hosts alternative reporting engines to the ones included on Odoo core (RML, QWeb and Webkit). It is complemented with the ones that host the reports theirself: +https://github.com/OCA/account-financial-reporting +https://github.com/OCA/purchase-reporting +https://github.com/OCA/sale-reporting +... -This module allows you to convert any type of report into LibreOffice/OpenOffice. -The benefits is that you have control over your documents and you can -modify them as needed. +The convention is to use a suffix to each module to indicate that it's for using with that report engine (for example, account_invoice_report_birt or sale_order_report_pentaho). +It can contain also another utilities directly involved with reports (like merge/split utils, checkers, signing tools and so on). -Requirements -============ +[//]: # (addons) +Available addons +---------------- +addon | version | summary +--- | --- | --- +[report_qweb_element_page_visibility](report_qweb_element_page_visibility/) | 9.0.1.0.0 | Report Qweb Element Page Visibility +[report_xlsx](report_xlsx/) | 9.0.1.0.0 | Base module to create xlsx report -The py3o.template package is required; install it with: - easy_install -UZ py3o.template +Unported addons +--------------- +addon | version | summary +--- | --- | --- +[base_report_assembler](base_report_assembler/) | 1.0 (unported) | Base Report Assembler +[report_custom_filename](report_custom_filename/) | 8.0.1.0.0 (unported) | Configure the filename to use when downloading a report +[report_xls](report_xls/) | 8.0.0.6.1 (unported) | Excel report engine +[//]: # (end addons) +---- + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +http://odoo-community.org/ diff --git a/__init__.py b/__init__.py deleted file mode 100644 index 2c4eac3f..00000000 --- a/__init__.py +++ /dev/null @@ -1 +0,0 @@ -import models \ No newline at end of file diff --git a/__openerp__.py b/__openerp__.py deleted file mode 100644 index 328da8e6..00000000 --- a/__openerp__.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# LibreOffice Report Engine, for OpenERP -# Copyright (C) 2013 XCG Consulting (http://odoo.consulting) -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -# Author: Anael LORIMIER -# Vincent Lhote-Hatakeyama -# -############################################################################## -{ - 'name': 'LibreOffice Report Engine', - 'description': ''' -Generation of LibreOffice/OpenOffice reports using LibreOffice/OpenOffice -templates. - -The py3o.template package is required; install it with: - pip install py3o.template -''', - 'version': '8.0.2.1', - 'category': 'Reporting', - 'author': 'XCG Consulting', - 'website': 'http://odoo.consulting/', - 'depends': [ - 'base', - 'report' - ], - 'external_dependencies': { - 'python': ['py3o.template'] - }, - 'data': [ - 'security/ir.model.access.csv', - - 'views/menu.xml', - 'views/py3o_template.xml', - 'views/py3o_server.xml', - 'views/ir_report.xml', - - 'data/py3o.fusion.filetype.csv', - ], - 'installable': True, -} diff --git a/base_report_assembler/__init__.py b/base_report_assembler/__init__.py new file mode 100644 index 00000000..f91d090e --- /dev/null +++ b/base_report_assembler/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Yannick Vaucher +# Copyright 2013 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import report_assembler +from . import assembled_report +from . import ir_report + diff --git a/base_report_assembler/__openerp__.py b/base_report_assembler/__openerp__.py new file mode 100644 index 00000000..89756551 --- /dev/null +++ b/base_report_assembler/__openerp__.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Yannick Vaucher +# Copyright 2013 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{'name': 'Base Report Assembler', + 'version': '1.0', + 'category': 'Report', + 'description': """ +Base Report Assembler +===================== + +Defines a new type of report which is an assemblage of multiple other reports +of the same object. + +For example you can merge the pdf output of a rml invoice report with the pdf +output of a webkit payment slip. + +To install this assemblage option for specific object you can install +the folling module(s): + +- Invoices: invoice_report_assemble (lp:account-invoice-report) + +""", + 'author': "Camptocamp,Odoo Community Association (OCA)", + 'maintainer': 'Camptocamp', + 'website': 'http://www.camptocamp.com/', + 'depends': ['base'], + 'data': [], + 'test': [], + 'installable': False, + 'auto_install': False, + 'application': False, + } diff --git a/base_report_assembler/assembled_report.py b/base_report_assembler/assembled_report.py new file mode 100644 index 00000000..212e5bf2 --- /dev/null +++ b/base_report_assembler/assembled_report.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Yannick Vaucher +# Copyright 2013 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp.osv import orm, fields + +class AssembledReport(orm.Model): + _name = 'assembled.report' + + _order = 'sequence' + + _columns = { + 'report_id': fields.many2one( + 'ir.actions.report.xml', 'Report', + domain="[('model', '=', model)," + "('report_type', '!=', 'assemblage')]", required=True), + 'model': fields.char('Object model'), + 'sequence': fields.integer('Sequence', required=True), + 'company_id': fields.many2one('res.company', 'Company', required=True), + } + + _defaults = { + 'sequence': 1, + 'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get( + cr, uid, 'assembled.report', context=c) + } diff --git a/base_report_assembler/i18n/base_report_assembler.pot b/base_report_assembler/i18n/base_report_assembler.pot new file mode 100644 index 00000000..5b2331ef --- /dev/null +++ b/base_report_assembler/i18n/base_report_assembler.pot @@ -0,0 +1,36 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_report_assembler +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-11-05 14:55+0000\n" +"PO-Revision-Date: 2013-11-05 14:55+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_report_assembler +#: field:assembled.report,model:0 +msgid "Object model" +msgstr "" + +#. module: base_report_assembler +#: field:assembled.report,sequence:0 +msgid "Sequence" +msgstr "" + +#. module: base_report_assembler +#: field:assembled.report,company_id:0 +msgid "Company" +msgstr "" + +#. module: base_report_assembler +#: field:assembled.report,report_id:0 +msgid "Report" +msgstr "" diff --git a/base_report_assembler/i18n/fr.po b/base_report_assembler/i18n/fr.po new file mode 100644 index 00000000..6dee61e0 --- /dev/null +++ b/base_report_assembler/i18n/fr.po @@ -0,0 +1,37 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_report_assembler +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-11-05 14:55+0000\n" +"PO-Revision-Date: 2013-11-05 14:55+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_report_assembler +#: field:assembled.report,model:0 +msgid "Object model" +msgstr "Modèle d'object" + +#. module: base_report_assembler +#: field:assembled.report,sequence:0 +msgid "Sequence" +msgstr "Séquence" + +#. module: base_report_assembler +#: field:assembled.report,company_id:0 +msgid "Company" +msgstr "Société" + +#. module: base_report_assembler +#: field:assembled.report,report_id:0 +msgid "Report" +msgstr "Rapport" + diff --git a/base_report_assembler/ir_report.py b/base_report_assembler/ir_report.py new file mode 100644 index 00000000..6cc901e5 --- /dev/null +++ b/base_report_assembler/ir_report.py @@ -0,0 +1,110 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Yannick Vaucher +# Copyright 2013 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp.osv import orm +from openerp import netsvc +from openerp.report.report_sxw import rml_parse +from report_assembler import PDFReportAssembler + + +def register_report(name, model, parser=rml_parse): + """ Register the report into the services """ + name = 'report.%s' % name + if netsvc.Service._services.get(name, False): + service = netsvc.Service._services[name] + if isinstance(service, PDFReportAssembler): + #already instantiated properly, skip it + return + if hasattr(service, 'parser'): + parser = service.parser + del netsvc.Service._services[name] + PDFReportAssembler(name, model, parser=parser) + + +class ReportAssembleXML(orm.Model): + + _name = 'ir.actions.report.xml' + _inherit = 'ir.actions.report.xml' + + def __init__(self, pool, cr): + super(ReportAssembleXML, self).__init__(pool, cr) + + def register_all(self, cursor): + value = super(ReportAssembleXML, self).register_all(cursor) + cursor.execute("SELECT * FROM ir_act_report_xml WHERE report_type = 'assemblage'") + records = cursor.dictfetchall() + for record in records: + register_report(record['report_name'], record['model']) + return value + + def unlink(self, cursor, user, ids, context=None): + """ Delete report and unregister it """ + trans_obj = self.pool.get('ir.translation') + trans_ids = trans_obj.search( + cursor, + user, + [('type', '=', 'report'), ('res_id', 'in', ids)] + ) + trans_obj.unlink(cursor, user, trans_ids) + + # Warning: we cannot unregister the services at the moment + # because they are shared across databases. Calling a deleted + # report will fail so it's ok. + + res = super(ReportAssembleXML, self).unlink( + cursor, + user, + ids, + context) + return res + + def create(self, cursor, user, vals, context=None): + """ Create report and register it """ + res = super(ReportAssembleXML, self).create(cursor, user, vals, context) + if vals.get('report_type', '') == 'assemblage': + # I really look forward to virtual functions :S + register_report( + vals['report_name'], + vals['model']) + return res + + def write(self, cr, uid, ids, vals, context=None): + """ Edit report and manage its registration """ + if isinstance(ids, (int, long)): + ids = [ids] + for rep in self.browse(cr, uid, ids, context=context): + if rep.report_type != 'assemblage': + continue + if (vals.get('report_name', False) + and vals['report_name'] != rep.report_name): + report_name = vals['report_name'] + else: + report_name = rep.report_name + + register_report( + report_name, + vals.get('model', rep.model), + False + ) + res = super(ReportAssembleXML, self).write(cr, uid, ids, vals, context) + return res + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/base_report_assembler/report_assembler.py b/base_report_assembler/report_assembler.py new file mode 100644 index 00000000..08b5a9b9 --- /dev/null +++ b/base_report_assembler/report_assembler.py @@ -0,0 +1,126 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Yannick Vaucher +# Copyright 2013 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import time +import base64 +from PyPDF2 import PdfFileReader, PdfFileWriter +from StringIO import StringIO + +from openerp.netsvc import ExportService +from openerp.report import report_sxw +from openerp import pooler + +_POLLING_DELAY = 0.25 + + +def assemble_pdf(pdf_list): + """ + Assemble a list of pdf + """ + # Even though we are using PyPDF2 we can't use PdfFileMerger + # as this issue still exists in mostly used wktohtml reports version + # http://code.google.com/p/wkhtmltopdf/issues/detail?id=635 + #merger = PdfFileMerger() + #merger.append(fileobj=StringIO(invoice_pdf)) + #merger.append(fileobj=StringIO(bvr_pdf)) + + #with tempfile.TemporaryFile() as merged_pdf: + #merger.write(merged_pdf) + #return merged_pdf.read(), 'pdf' + + output = PdfFileWriter() + for pdf in pdf_list: + reader = PdfFileReader(StringIO(pdf)) + for page in range(reader.getNumPages()): + output.addPage(reader.getPage(page)) + s = StringIO() + output.write(s) + return s.getvalue() + + +class PDFReportAssembler(report_sxw.report_sxw): + """ PDFReportAssembler allows to put 2 pdf reports in one single pdf""" + + def _generate_all_pdf(self, cr, uid, ids, data, report_ids, context=None): + """ + Return a list of pdf encoded in base64 + """ + pool = pooler.get_pool(cr.dbname) + report_obj = pool.get('ir.actions.report.xml') + + spool = ExportService._services['report'] + + pdf_reports = [] + report_list = report_obj.browse(cr, uid, report_ids, context=context) + for report in report_list: + + report_key = spool.exp_report(cr.dbname, uid, report.report_name, + ids, datas=data, context=context) + while 1: + res = spool.exp_report_get(cr.dbname, uid, report_key) + if res.get('state'): + break + time.sleep(_POLLING_DELAY) + pdf = base64.b64decode(res.get('result')) + pdf_reports.append(pdf) + return pdf_reports + + def _get_report_ids(self, cr, uid, ids, context=None): + """ + Hook to define the list of report to print + """ + return [] + + def create_single_pdf(self, cr, uid, ids, data, report_xml, context=None): + """Call both report to assemble both pdf""" + + report_ids = self._get_report_ids(cr, uid, ids, context=context) + + pdf_reports = self._generate_all_pdf(cr, uid, ids, data, report_ids, context=context) + + pdf_assemblage = assemble_pdf(pdf_reports) + return pdf_assemblage, 'pdf' + + def create(self, cr, uid, ids, data, context=None): + """We override the create function in order to handle generator + Code taken from report openoffice. Thanks guys :) """ + pool = pooler.get_pool(cr.dbname) + ir_obj = pool.get('ir.actions.report.xml') + report_xml_ids = ir_obj.search(cr, uid, + [('report_name', '=', self.name[7:])], context=context) + if report_xml_ids: + + report_xml = ir_obj.browse(cr, + uid, + report_xml_ids[0], + context=context) + report_xml.report_rml = None + report_xml.report_rml_content = None + report_xml.report_sxw_content_data = None + report_xml.report_sxw_content = None + report_xml.report_sxw = None + else: + return super(PDFReportAssembler, self).create(cr, uid, ids, data, context) + if report_xml.report_type != 'assemblage': + return super(PDFReportAssembler, self).create(cr, uid, ids, data, context) + result = self.create_source_pdf(cr, uid, ids, data, report_xml, context) + if not result: + return (False, False) + return result diff --git a/models/__init__.py b/models/__init__.py deleted file mode 100644 index 28989d9f..00000000 --- a/models/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -import ir_report -import py3o_fusion_filetype -import py3o_template -import py3o_server \ No newline at end of file diff --git a/models/py3o_fusion_filetype.py b/models/py3o_fusion_filetype.py deleted file mode 100644 index 570ca474..00000000 --- a/models/py3o_fusion_filetype.py +++ /dev/null @@ -1,18 +0,0 @@ -from openerp.osv import fields, osv - - -class py3o_fusion_filetype(osv.Model): - _name = 'py3o.fusion.filetype' - - _rec_name = 'human_ext' - - _columns = { - 'fusion_ext': fields.char( - u"Fusion Extension", - size=8, - ), - 'human_ext': fields.char( - u"Human readble extension", - size=8, - ), - } diff --git a/models/py3o_server.py b/models/py3o_server.py deleted file mode 100644 index d815a845..00000000 --- a/models/py3o_server.py +++ /dev/null @@ -1,19 +0,0 @@ -from openerp.osv import fields, osv - - -class py3o_server(osv.Model): - _name = 'py3o.server' - - _columns = { - 'url': fields.char( - u"URL", - size=256, - ), - 'is_active': fields.boolean( - u"Active", - ) - } - - _defaults = { - 'is_active': True, - } diff --git a/models/py3o_template.py b/models/py3o_template.py deleted file mode 100644 index 29b49dfd..00000000 --- a/models/py3o_template.py +++ /dev/null @@ -1,28 +0,0 @@ -from openerp.osv import fields, osv - - -class py3o_template(osv.Model): - _name = 'py3o.template' - - _columns = { - 'name': fields.char( - u"Name", - ), - - 'py3o_template_data': fields.binary( - u"LibreOffice template", - ), - - 'filetype': fields.selection( - [ - ('odt', u"ODF Text Document"), - ('ods', u"ODF Spreadsheet"), - ], - u"LibreOffice Template File Type", - required=True, - ), - } - - _defaults = { - 'filetype': 'odt' - } diff --git a/py3o_report_modif.py b/py3o_report_modif.py deleted file mode 100644 index 8683ea25..00000000 --- a/py3o_report_modif.py +++ /dev/null @@ -1,146 +0,0 @@ -from base64 import b64decode -from tempfile import NamedTemporaryFile as tempfile - -from openerp import pooler -from openerp.report.report_sxw import * -from openerp.tools.translate import _ -from openerp.osv.osv import except_osv - -from py3o.template import Template - -from oe_json_serializer import OESerializer - -import json -import requests -import os - - -class py3o_report(report_sxw): -# def __init__(self, name, table): -# super(py3o_report, self).__init__(name, table) - - def get_values(self, cr, uid, ids, data, context): - ''' Override this function to customize the dictionary given to the - py3o.template renderer. ''' - - return { - 'lang': self.get_lang(cr, uid, context), - 'objects': self.getObjects(cr, uid, ids, context), - } - - def get_lang(self, cr, uid, context): - pool = pooler.get_pool(cr.dbname) - lang_obj = pool.get('res.lang') - user_obj = pool.get('res.users') - - lang_code = user_obj.browse(cr, uid, uid, context=context).lang - lang = lang_obj.search(cr, uid, - [('code', '=', lang_code)], - context=context)[0] - return lang_obj.browse(cr, uid, lang, context=context) - - def format_date(self, date, values): - ''' Return a date formatted according to the language extracted from - the "values" argument (which should be the result of get_values). ''' - return date.strftime(values['lang'].date_format) - - def create(self, cr, uid, ids, data, context=None): - # Find the report definition to get its settings. - pool = pooler.get_pool(cr.dbname) - report_xml_obj = pool.get('ir.actions.report.xml') - report_xml_ids = report_xml_obj.search(cr, uid, - [('report_name', '=', self.name[7:])], # Ignore "report." - context=context) - - if not report_xml_ids: - return super(py3o_report, self).create(cr, uid, ids, data, - context=context) - report_xml = report_xml_obj.browse(cr, uid, - report_xml_ids[0], - context=context) - - template = report_xml.py3o_template_id - filetype = report_xml.py3o_fusion_filetype - - - #Try to request fusion server: - - fusion_server_obj = pool['py3o.server'] - #TODO: Raise a message if no config found - fusion_server_id = fusion_server_obj.search( - cr, uid, [], context=context - )[0] - fusion_server = fusion_server_obj.browse(cr, uid, fusion_server_id) - - # py3o.template operates on filenames so create temporary files. - in_temp = tempfile(suffix='.odt', prefix='py3o-template-') - - in_temp.write(b64decode(template.py3o_template_data)) - in_temp.seek(0) - out_temp = tempfile(suffix='.odt', prefix='py3o-report-') - - # We need to get the variables used in the template - #TODO: Find a way to avoid calling Template - t = Template(in_temp.name, out_temp.name) - # Remove 'py3o.' - user_variable = [x[5:] for x in t.get_all_user_python_expression()] - print user_variable - - values = self.get_values(cr, uid, ids, data, context) - t.render(values) - print values - - #WARNING: We rely on the fact that there is a for loop on the report - # on objects (for object in objects) due to lack of time - val_dict = {} - for val in values: - if val == 'objects': - o = [] - for obj in values[val]: - x = OESerializer.serialize( - obj, - [ - v[len('object') + 1:] - for v in user_variable - if v.startswith('object') - ] - ) - o.append(x) - val_dict.update({val: o}) - continue - - x = OESerializer.serialize( - values[val], - [ - v[len(val) + 1:] - for v in user_variable - if v.startswith(val) - ] - ) - val_dict.update({val: x}) - - import pprint - pprint.pprint(val_dict) - val_json = json.dumps(val_dict) - - fields = { - 'targetformat': filetype.fusion_ext, - 'datadict': val_json, - 'image_mapping': '{}', - } - print fields - - r = requests.post( - fusion_server.url, data=fields, files={'tmpl_file': in_temp} - ) - in_temp.close() - if r.status_code == 400: - raise Exception("Problem with fusion server: %s" % r.json()) - - chunk_size = 1024 - - ext = filetype.human_ext - for chunk in r.iter_content(chunk_size): - out_temp.write(chunk) - out_temp.seek(0) - return out_temp.read(), ext diff --git a/report_custom_filename/README.rst b/report_custom_filename/README.rst new file mode 100644 index 00000000..ca2d8b61 --- /dev/null +++ b/report_custom_filename/README.rst @@ -0,0 +1,47 @@ +Custom report filenames +======================= + +This addon allows for custom filenames for reports. + +Configuration +============= + +To configure this module, open the report whose filename you want to change and fill in the `Download filename` field. This field is evaluated as jinja2 template with `objects` being a list of browse records of the records to print, and `o` the first record. If your model contains a name field, you might write something like `${o.name}_report.pdf` as filename. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/143/8.0 + +Credits +======= + +Contributors +------------ + +* Holger Brunn + +Icon +---- + +Icon courtesy of http://www.picol.org/ (download_settings.svg) + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/report_custom_filename/__init__.py b/report_custom_filename/__init__.py new file mode 100644 index 00000000..cba0a4dc --- /dev/null +++ b/report_custom_filename/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import controllers +from . import model diff --git a/report_custom_filename/__openerp__.py b/report_custom_filename/__openerp__.py new file mode 100644 index 00000000..1b78fd7e --- /dev/null +++ b/report_custom_filename/__openerp__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name": "Custom report filenames", + "summary": "Configure the filename to use when downloading a report", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "complexity": "normal", + "category": "Reporting", + "depends": [ + 'web', + 'email_template', + ], + "data": [ + "view/ir_actions_report_xml.xml", + ], + "test": [ + ], + "auto_install": False, + 'installable': False, + "application": False, + "external_dependencies": { + 'python': ['jinja2'], + }, +} diff --git a/report_custom_filename/controllers/__init__.py b/report_custom_filename/controllers/__init__.py new file mode 100644 index 00000000..6eb84a90 --- /dev/null +++ b/report_custom_filename/controllers/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import reports +from . import report_controller diff --git a/report_custom_filename/controllers/report_controller.py b/report_custom_filename/controllers/report_controller.py new file mode 100644 index 00000000..536d2d69 --- /dev/null +++ b/report_custom_filename/controllers/report_controller.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp import http +from openerp.addons.email_template import email_template +from openerp.addons.report.controllers.main import ReportController +from openerp.addons.web.controllers.main import content_disposition + + +class ReportController(ReportController): + @http.route([ + '/report//', + '/report///', + ]) + def report_routes(self, reportname, docids=None, converter=None, **data): + response = super(ReportController, self).report_routes( + reportname, docids=docids, converter=converter, **data) + if docids: + docids = [int(i) for i in docids.split(',')] + report_xml = http.request.session.model('ir.actions.report.xml') + report_ids = report_xml.search( + [('report_name', '=', reportname)]) + for report in report_xml.browse(report_ids): + if not report.download_filename: + continue + objects = http.request.session.model(report.model)\ + .browse(docids or []) + generated_filename = email_template.mako_template_env\ + .from_string(report.download_filename)\ + .render({ + 'objects': objects, + 'o': objects[:1], + 'object': objects[:1], + 'ext': report.report_type.replace('qweb-', ''), + }) + response.headers['Content-Disposition'] = content_disposition( + generated_filename) + return response + + @http.route(['/report/download']) + def report_download(self, data, token): + response = super(ReportController, self).report_download(data, token) + # if we got another content disposition before, ditch the one added + # by super() + last_index = None + for i in range(len(response.headers) - 1, -1, -1): + if response.headers[i][0] == 'Content-Disposition': + if last_index: + response.headers.pop(last_index) + last_index = i + return response diff --git a/report_custom_filename/controllers/reports.py b/report_custom_filename/controllers/reports.py new file mode 100644 index 00000000..1ff58ed0 --- /dev/null +++ b/report_custom_filename/controllers/reports.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import simplejson +from openerp import http +from openerp.addons.web.controllers import main +from openerp.addons.email_template import email_template + + +class Reports(main.Reports): + @http.route('/web/report', type='http', auth="user") + @main.serialize_exception + def index(self, action, token): + result = super(Reports, self).index(action, token) + action = simplejson.loads(action) + context = dict(http.request.context) + context.update(action["context"]) + report_xml = http.request.session.model('ir.actions.report.xml') + report_ids = report_xml.search( + [('report_name', '=', action['report_name'])], + 0, False, False, context) + for report in report_xml.browse(report_ids): + if not report.download_filename: + continue + objects = http.request.session.model(context['active_model'])\ + .browse(context['active_ids']) + generated_filename = email_template.mako_template_env\ + .from_string(report.download_filename)\ + .render({ + 'objects': objects, + 'o': objects[0], + 'object': objects[0], + }) + result.headers['Content-Disposition'] = main.content_disposition( + generated_filename) + return result diff --git a/report_custom_filename/i18n/report_custom_filename.pot b/report_custom_filename/i18n/report_custom_filename.pot new file mode 100644 index 00000000..fa2ec82c --- /dev/null +++ b/report_custom_filename/i18n/report_custom_filename.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_custom_filename +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-12-19 12:17+0000\n" +"PO-Revision-Date: 2014-12-19 12:17+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: report_custom_filename +#: field:ir.actions.report.xml,download_filename:0 +msgid "Download filename" +msgstr "" + +#. module: report_custom_filename +#: help:ir.actions.report.xml,download_filename:0 +msgid "Fill in this field to have a custom file name when downloading this report. This string is evaluated as a jinja2 expression.\n" +"You can use python expressions, `objects` is a browse record list of the objects for which the report is being generated.\n" +"Check for this list's length to determine if it is a report being printed for multiple records or not. You also have access to `o`, which is the first record in the list" +msgstr "" + +#. module: report_custom_filename +#: model:ir.model,name:report_custom_filename.model_ir_actions_report_xml +msgid "ir.actions.report.xml" +msgstr "" + diff --git a/report_custom_filename/model/__init__.py b/report_custom_filename/model/__init__.py new file mode 100644 index 00000000..b7da7af1 --- /dev/null +++ b/report_custom_filename/model/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import ir_actions_report_xml diff --git a/report_custom_filename/model/ir_actions_report_xml.py b/report_custom_filename/model/ir_actions_report_xml.py new file mode 100644 index 00000000..5ea04300 --- /dev/null +++ b/report_custom_filename/model/ir_actions_report_xml.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp import models, fields + + +class IrActionsReportXml(models.Model): + _inherit = 'ir.actions.report.xml' + + download_filename = fields.Char( + 'Download filename', + help='Fill in this field to have a custom file name when downloading ' + 'this report. This string is evaluated as a jinja2 expression.\n' + 'You can use python expressions, `objects` is a browse record list of ' + 'the objects for which the report is being generated.\n' + 'Check for this list\'s length to determine if it is a report being ' + 'printed for multiple records or not. You also have access to `o`, ' + 'which is the first record in the list.\n' + 'For qweb reports, the variable `ext` gives you the requested format' + '\'s extension') diff --git a/report_custom_filename/static/description/icon.png b/report_custom_filename/static/description/icon.png new file mode 100644 index 00000000..df9ef01c Binary files /dev/null and b/report_custom_filename/static/description/icon.png differ diff --git a/report_custom_filename/view/ir_actions_report_xml.xml b/report_custom_filename/view/ir_actions_report_xml.xml new file mode 100644 index 00000000..412bc8db --- /dev/null +++ b/report_custom_filename/view/ir_actions_report_xml.xml @@ -0,0 +1,14 @@ + + + + + ir.actions.report.xml + + + + + + + + + diff --git a/report_py3o/LICENSE b/report_py3o/LICENSE new file mode 100644 index 00000000..dba13ed2 --- /dev/null +++ b/report_py3o/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/NEWS b/report_py3o/NEWS similarity index 100% rename from NEWS rename to report_py3o/NEWS diff --git a/report_py3o/README.md b/report_py3o/README.md new file mode 100644 index 00000000..51709d3d --- /dev/null +++ b/report_py3o/README.md @@ -0,0 +1,18 @@ +### README ### + + +### LibreOffice Report Engine for Odoo/OpenERP ### + + +This module allows you to convert any type of report into LibreOffice/OpenOffice. +The benefits is that you have control over your documents and you can +modify them as needed. + + +Requirements +============ + +The py3o.template package is required; install it with: + easy_install -UZ py3o.template + + diff --git a/report_py3o/__init__.py b/report_py3o/__init__.py new file mode 100644 index 00000000..9a7e03ed --- /dev/null +++ b/report_py3o/__init__.py @@ -0,0 +1 @@ +from . import models \ No newline at end of file diff --git a/report_py3o/__openerp__.py b/report_py3o/__openerp__.py new file mode 100644 index 00000000..8a4d7990 --- /dev/null +++ b/report_py3o/__openerp__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 XCG Consulting (http://odoo.consulting) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + 'name': 'LibreOffice Report Engine', + 'description': ''' +Generation of LibreOffice/OpenOffice reports using LibreOffice/OpenOffice +templates. + +The py3o.template package is required; install it with: + pip install py3o.template +''', + 'version': '9.0.1.0.0', + 'category': 'Reporting', + 'author': 'XCG Consulting', + 'website': 'http://odoo.consulting/', + 'depends': [ + 'base', + 'report' + ], + 'external_dependencies': { + 'python': ['py3o.template'] + }, + 'data': [ + 'security/ir.model.access.csv', + + 'views/menu.xml', + 'views/py3o_template.xml', + 'views/py3o_server.xml', + 'views/ir_report.xml', + + 'data/py3o.fusion.filetype.csv', + ], + 'installable': True, +} diff --git a/data/py3o.fusion.filetype.csv b/report_py3o/data/py3o.fusion.filetype.csv similarity index 100% rename from data/py3o.fusion.filetype.csv rename to report_py3o/data/py3o.fusion.filetype.csv diff --git a/i18n/fr.po b/report_py3o/i18n/fr.po similarity index 100% rename from i18n/fr.po rename to report_py3o/i18n/fr.po diff --git a/report_py3o/models/__init__.py b/report_py3o/models/__init__.py new file mode 100644 index 00000000..ccf621aa --- /dev/null +++ b/report_py3o/models/__init__.py @@ -0,0 +1,4 @@ +from . import ir_report +from . import py3o_fusion_filetype +from . import py3o_template +from . import py3o_server \ No newline at end of file diff --git a/models/ir_report.py b/report_py3o/models/ir_report.py similarity index 50% rename from models/ir_report.py rename to report_py3o/models/ir_report.py index 106bd332..927994e3 100644 --- a/models/ir_report.py +++ b/report_py3o/models/ir_report.py @@ -1,11 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 XCG Consulting (http://odoo.consulting) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import os -from openerp.osv import fields, osv +from openerp import api, fields, models from openerp.report.interface import report_int from ..py3o_parser import Py3oParser +from openerp.exceptions import ValidationError from openerp import addons -class report_xml(osv.Model): +class ReportXml(models.Model): """ Inherit from ir.actions.report.xml to allow customizing the template file. The user cam chose a template from a list. The list is configurable in the configuration tab, see py3o_template.py @@ -13,49 +17,32 @@ class report_xml(osv.Model): _inherit = 'ir.actions.report.xml' - _columns = { - # TODO required when report_type type is py3o, add python constraint - 'py3o_fusion_filetype': fields.many2one( - 'py3o.fusion.filetype', - u"Output Format", - ), - 'py3o_template_id': fields.many2one( - 'py3o.template', - u"Template", - ), - 'module': fields.char( - u"Module", - size=64, - help=u"The implementer module that provides this report", - ), - 'py3o_template_fallback': fields.char( - u"Fallback", - size=128, - help=( - u"If the user does not provide a template this will be used " - u"it should be a relative path to root of YOUR module" - ) - ), - 'report_type': fields.selection( - [ - ('qweb-pdf', u"PDF"), - ('qweb-html', u"HTML"), - ('controller', u"Controller"), - ('pdf', u"RML pdf (deprecated)"), - ('sxw', u"RML sxw (deprecated)"), - ('webkit', u"Webkit (deprecated)"), - ('py3o', u"Py3o"), - ], - string=u"Report Type", - required=True, - help=u"HTML will open the report directly in your browser, " - u"PDF will use wkhtmltopdf to render the HTML into a PDF " - u"file and let you download it, Controller allows you to " - u"define the url of a custom controller outputting " - u"any kind of report.", - ) - } + @api.one + @api.constrains("py3o_fusion_filetype", "report_type") + def _check_py3o_fusion_filetype(self): + if self.report_type == "py3o" and not self.py3o_fusion_filetype: + raise ValidationError( + "Field 'Output Format' is required for Py3O report") + + py3o_fusion_filetype = fields.Many2one( + 'py3o.fusion.filetype', + "Output Format") + py3o_template_id = fields.Many2one( + 'py3o.template', + "Template") + module = fields.Char( + "Module", + help="The implementer module that provides this report") + py3o_template_fallback = fields.Char( + "Fallback", + size=128, + help=( + "If the user does not provide a template this will be used " + "it should be a relative path to root of YOUR module" + )) + report_type = fields.Selection(selection_add=[('py3o', "Py3o")]) + @api.cr def _lookup_report(self, cr, name): """Look up a report definition. """ @@ -95,4 +82,4 @@ class report_xml(osv.Model): if new_report: return new_report else: - return super(report_xml, self)._lookup_report(cr, name) + return super(ReportXml, self)._lookup_report(cr, name) diff --git a/report_py3o/models/py3o_fusion_filetype.py b/report_py3o/models/py3o_fusion_filetype.py new file mode 100644 index 00000000..009494fc --- /dev/null +++ b/report_py3o/models/py3o_fusion_filetype.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 XCG Consulting (http://odoo.consulting) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp import fields, models + + +class Py3oFusionFiletype(models.Model): + _name = 'py3o.fusion.filetype' + + _rec_name = 'human_ext' + + fusion_ext = fields.Char("Fusion Extension", siez=8) + human_ext = fields.Char("Human readble extension", size=8) diff --git a/report_py3o/models/py3o_server.py b/report_py3o/models/py3o_server.py new file mode 100644 index 00000000..bf434a59 --- /dev/null +++ b/report_py3o/models/py3o_server.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 XCG Consulting (http://odoo.consulting) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp import fields, models + + +class Py3oServer(models.Model): + _name = 'py3o.server' + + url = fields.Char("URL", required=True) + is_active = fields.Boolean("Active", default=True) diff --git a/report_py3o/models/py3o_template.py b/report_py3o/models/py3o_template.py new file mode 100644 index 00000000..7281f333 --- /dev/null +++ b/report_py3o/models/py3o_template.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 XCG Consulting (http://odoo.consulting) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp import fields, models + + +class Py3oTemplate(models.Model): + _name = 'py3o.template' + + name = fields.Char(required=True) + py3o_template_data = fields.Binary("LibreOffice template") + filetype = fields.Selection( + selection=[ + ('odt', u"ODF Text Document"), + ('ods', u"ODF Spreadsheet"), + ], + string="LibreOffice Template File Type", + required=True, + default='odt') diff --git a/py3o_parser.py b/report_py3o/py3o_parser.py similarity index 97% rename from py3o_parser.py rename to report_py3o/py3o_parser.py index d7467f95..36ed669d 100644 --- a/py3o_parser.py +++ b/report_py3o/py3o_parser.py @@ -1,4 +1,6 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- +# Copyright 2013 XCG Consulting (http://odoo.consulting) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) from cStringIO import StringIO import json import pkg_resources @@ -66,8 +68,8 @@ class Py3oParser(report_sxw): or from the default template file provided by the implementer. ATM this method takes a report definition recordset - to try and fetch the report template from database. If not found it will - fallback to the template file referenced in the report definition. + to try and fetch the report template from database. If not found it + will fallback to the template file referenced in the report definition. @param report_obj: a recordset representing the report defintion @type report_obj: openerp.model.recordset instance diff --git a/security/ir.model.access.csv b/report_py3o/security/ir.model.access.csv similarity index 100% rename from security/ir.model.access.csv rename to report_py3o/security/ir.model.access.csv diff --git a/views/ir_report.xml b/report_py3o/views/ir_report.xml similarity index 92% rename from views/ir_report.xml rename to report_py3o/views/ir_report.xml index a5586aa4..1fbb52c4 100644 --- a/views/ir_report.xml +++ b/report_py3o/views/ir_report.xml @@ -9,7 +9,7 @@ - + diff --git a/views/menu.xml b/report_py3o/views/menu.xml similarity index 100% rename from views/menu.xml rename to report_py3o/views/menu.xml diff --git a/views/py3o_server.xml b/report_py3o/views/py3o_server.xml similarity index 100% rename from views/py3o_server.xml rename to report_py3o/views/py3o_server.xml diff --git a/views/py3o_template.xml b/report_py3o/views/py3o_template.xml similarity index 100% rename from views/py3o_template.xml rename to report_py3o/views/py3o_template.xml diff --git a/report_qweb_element_page_visibility/README.rst b/report_qweb_element_page_visibility/README.rst new file mode 100644 index 00000000..4d8282da --- /dev/null +++ b/report_qweb_element_page_visibility/README.rst @@ -0,0 +1,77 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=================================== +Report Qweb Element Page Visibility +=================================== + +This module allows you to use 4 classes in QWEB reports: + +- not-first-page: shows element in every page but first +- not-last-page: shows element in every page but last +- first-page: shows element only on first page +- last-page: shows element only on last page + +Usage +===== + +To use this module, you need to: + +In the QWEB ``ir.ui.views`` used by your report, +you can add an element with css class with any of the classes described above. +For example if you need to improve invoice report header with +invoice's number in every page but first, and sale order report header +with order's name in every page but last, add this code to external_layout_header:: + + +
+ +
+
+ +
+ +
+
+ +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/143/8.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. + + +Credits +======= + +Contributors +------------ + +* Nicola Malcontenti +* Lorenzo Battistini +* Alessio Gerace +* Alex Comba + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/report_qweb_element_page_visibility/__init__.py b/report_qweb_element_page_visibility/__init__.py new file mode 100644 index 00000000..ad15c9c0 --- /dev/null +++ b/report_qweb_element_page_visibility/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/report_qweb_element_page_visibility/__openerp__.py b/report_qweb_element_page_visibility/__openerp__.py new file mode 100644 index 00000000..af192ca0 --- /dev/null +++ b/report_qweb_element_page_visibility/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Report Qweb Element Page Visibility', + 'version': '9.0.1.0.0', + 'author': 'Agile Business Group, Odoo Community Association (OCA)', + 'category': 'Tools', + "website": "https://odoo-community.org/", + "license": "AGPL-3", + "application": False, + "installable": True, + 'data': [ + 'views/layouts.xml', + ], + 'depends': [ + 'report', + ], +} diff --git a/report_qweb_element_page_visibility/static/description/icon.png b/report_qweb_element_page_visibility/static/description/icon.png new file mode 100644 index 00000000..4f946b5d Binary files /dev/null and b/report_qweb_element_page_visibility/static/description/icon.png differ diff --git a/report_qweb_element_page_visibility/views/layouts.xml b/report_qweb_element_page_visibility/views/layouts.xml new file mode 100644 index 00000000..1cde96c3 --- /dev/null +++ b/report_qweb_element_page_visibility/views/layouts.xml @@ -0,0 +1,46 @@ + + + + + + diff --git a/report_xls/__init__.py b/report_xls/__init__.py new file mode 100644 index 00000000..e100e786 --- /dev/null +++ b/report_xls/__init__.py @@ -0,0 +1,25 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2014 Noviat nv/sa (www.noviat.com). All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import ir_report +from . import report_xls +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/report_xls/__openerp__.py b/report_xls/__openerp__.py new file mode 100644 index 00000000..cddc757e --- /dev/null +++ b/report_xls/__openerp__.py @@ -0,0 +1,82 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2014 Noviat nv/sa (www.noviat.com). All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Excel report engine', + 'version': '8.0.0.6.1', + 'license': 'AGPL-3', + 'author': "Noviat,Odoo Community Association (OCA)", + 'website': 'http://www.noviat.com', + 'category': 'Reporting', + 'description': """ +Excel report engine +=================== + +This module adds Excel export capabilities to the standard odoo reporting +engine. + +Report development +'''''''''''''''''' +In order to create an Excel report you can\n +- define a report of type 'xls' +- pass ``{'xls_export': 1}`` via the context to the report create method + +The ``report_xls`` class contains a number of attributes and methods to +facilitate the creation XLS reports in OpenERP. + +* cell types + + Supported cell types : text, number, boolean, date. + +* cell styles + + The predefined cell style definitions result in a consistent + look and feel of the OpenERP Excel reports. + +* cell formulas + + Cell formulas can be easily added with the help of the ``rowcol_to_cell()`` + function which you can import from the ``utils.py`` module. + +* Excel templates + + It is possible to define Excel templates which can be adapted + by 'inherited' modules. + Download the ``account_move_line_report_xls`` module + from http://apps.odoo.com as example. + +* XLS with multiple sheets + + Download the ``account_journal_report_xls`` module + from http://apps.odoo.com as example. + +Development assistance +'''''''''''''''''''''' +Contact info@noviat.com for help with the development of +Excel reports in odoo. + + """, + 'depends': ['base'], + 'external_dependencies': {'python': ['xlwt']}, + 'active': False, + 'installable': False, +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/report_xls/ir_report.py b/report_xls/ir_report.py new file mode 100644 index 00000000..332f32f0 --- /dev/null +++ b/report_xls/ir_report.py @@ -0,0 +1,36 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2014 Noviat nv/sa (www.noviat.com). All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import orm + + +class ir_actions_report_xml(orm.Model): + _inherit = 'ir.actions.report.xml' + + def _check_selection_field_value(self, cr, uid, + field, value, context=None): + if field == 'report_type' and value == 'xls': + return + return super(ir_actions_report_xml, self)._check_selection_field_value( + cr, uid, field, value, context=context) + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/report_xls/report_xls.py b/report_xls/report_xls.py new file mode 100644 index 00000000..4746b4b9 --- /dev/null +++ b/report_xls/report_xls.py @@ -0,0 +1,248 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2014 Noviat nv/sa (www.noviat.com). All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import xlwt +from xlwt.Style import default_style +import cStringIO +from datetime import datetime +from openerp.osv.fields import datetime as datetime_field +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT +import inspect +from types import CodeType +from openerp.report.report_sxw import report_sxw +from openerp import pooler +import logging +_logger = logging.getLogger(__name__) + + +class AttrDict(dict): + def __init__(self, *args, **kwargs): + super(AttrDict, self).__init__(*args, **kwargs) + self.__dict__ = self + + +class report_xls(report_sxw): + + xls_types = { + 'bool': xlwt.Row.set_cell_boolean, + 'date': xlwt.Row.set_cell_date, + 'text': xlwt.Row.set_cell_text, + 'number': xlwt.Row.set_cell_number, + } + xls_types_default = { + 'bool': False, + 'date': None, + 'text': '', + 'number': 0, + } + + # TO DO: move parameters infra to configurable data + + # header/footer + hf_params = { + 'font_size': 8, + 'font_style': 'I', # B: Bold, I: Italic, U: Underline + } + + # styles + _pfc = '26' # default pattern fore_color + _bc = '22' # borders color + decimal_format = '#,##0.00' + date_format = 'YYYY-MM-DD' + xls_styles = { + 'xls_title': 'font: bold true, height 240;', + 'bold': 'font: bold true;', + 'underline': 'font: underline true;', + 'italic': 'font: italic true;', + 'fill': 'pattern: pattern solid, fore_color %s;' % _pfc, + 'fill_blue': 'pattern: pattern solid, fore_color 27;', + 'fill_grey': 'pattern: pattern solid, fore_color 22;', + 'borders_all': + 'borders: ' + 'left thin, right thin, top thin, bottom thin, ' + 'left_colour %s, right_colour %s, ' + 'top_colour %s, bottom_colour %s;' + % (_bc, _bc, _bc, _bc), + 'left': 'align: horz left;', + 'center': 'align: horz center;', + 'right': 'align: horz right;', + 'wrap': 'align: wrap true;', + 'top': 'align: vert top;', + 'bottom': 'align: vert bottom;', + } + # TO DO: move parameters supra to configurable data + + def create(self, cr, uid, ids, data, context=None): + self.pool = pooler.get_pool(cr.dbname) + self.cr = cr + self.uid = uid + report_obj = self.pool.get('ir.actions.report.xml') + report_ids = report_obj.search( + cr, uid, [('report_name', '=', self.name[7:])], context=context) + if report_ids: + report_xml = report_obj.browse( + cr, uid, report_ids[0], context=context) + self.title = report_xml.name + if report_xml.report_type == 'xls': + return self.create_source_xls(cr, uid, ids, data, context) + elif context.get('xls_export'): + # use model from 'data' when no ir.actions.report.xml entry + self.table = data.get('model') or self.table + return self.create_source_xls(cr, uid, ids, data, context) + return super(report_xls, self).create(cr, uid, ids, data, context) + + def create_source_xls(self, cr, uid, ids, data, context=None): + if not context: + context = {} + parser_instance = self.parser(cr, uid, self.name2, context) + self.parser_instance = parser_instance + self.context = context + objs = self.getObjects(cr, uid, ids, context) + parser_instance.set_context(objs, data, ids, 'xls') + objs = parser_instance.localcontext['objects'] + n = cStringIO.StringIO() + wb = xlwt.Workbook(encoding='utf-8') + _p = AttrDict(parser_instance.localcontext) + _xs = self.xls_styles + self.xls_headers = { + 'standard': '', + } + report_date = datetime_field.context_timestamp( + cr, uid, datetime.now(), context) + report_date = report_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT) + self.xls_footers = { + 'standard': ( + '&L&%(font_size)s&%(font_style)s' + report_date + + '&R&%(font_size)s&%(font_style)s&P / &N' + ) % self.hf_params, + } + self.generate_xls_report(_p, _xs, data, objs, wb) + wb.save(n) + n.seek(0) + return (n.read(), 'xls') + + def render(self, wanted, col_specs, rowtype, render_space='empty'): + """ + returns 'evaluated' col_specs + + Input: + - wanted: element from the wanted_list + - col_specs : cf. specs[1:] documented in xls_row_template method + - rowtype : 'header' or 'data' + - render_space : type dict, (caller_space + localcontext) + if not specified + """ + if render_space == 'empty': + render_space = {} + caller_space = inspect.currentframe().f_back.f_back.f_locals + localcontext = self.parser_instance.localcontext + render_space.update(caller_space) + render_space.update(localcontext) + row = col_specs[wanted][rowtype][:] + for i in range(len(row)): + if isinstance(row[i], CodeType): + row[i] = eval(row[i], render_space) + row.insert(0, wanted) + return row + + def generate_xls_report(self, parser, xls_styles, data, objects, wb): + """ override this method to create your excel file """ + raise NotImplementedError() + + def xls_row_template(self, specs, wanted_list): + """ + Returns a row template. + + Input : + - 'wanted_list': list of Columns that will be returned in the + row_template + - 'specs': list with Column Characteristics + 0: Column Name (from wanted_list) + 1: Column Colspan + 2: Column Size (unit = the width of the character ’0′ + as it appears in the sheet’s default font) + 3: Column Type + 4: Column Data + 5: Column Formula (or 'None' for Data) + 6: Column Style + """ + r = [] + col = 0 + for w in wanted_list: + found = False + for s in specs: + if s[0] == w: + found = True + s_len = len(s) + c = list(s[:5]) + # set write_cell_func or formula + if s_len > 5 and s[5] is not None: + c.append({'formula': s[5]}) + else: + c.append({ + 'write_cell_func': report_xls.xls_types[c[3]]}) + # Set custom cell style + if s_len > 6 and s[6] is not None: + c.append(s[6]) + else: + c.append(None) + # Set cell formula + if s_len > 7 and s[7] is not None: + c.append(s[7]) + else: + c.append(None) + r.append((col, c[1], c)) + col += c[1] + break + if not found: + _logger.warn("report_xls.xls_row_template, " + "column '%s' not found in specs", w) + return r + + def xls_write_row(self, ws, row_pos, row_data, + row_style=default_style, set_column_size=False): + r = ws.row(row_pos) + for col, size, spec in row_data: + data = spec[4] + formula = spec[5].get('formula') and \ + xlwt.Formula(spec[5]['formula']) or None + style = spec[6] and spec[6] or row_style + if not data: + # if no data, use default values + data = report_xls.xls_types_default[spec[3]] + if size != 1: + if formula: + ws.write_merge( + row_pos, row_pos, col, col + size - 1, data, style) + else: + ws.write_merge( + row_pos, row_pos, col, col + size - 1, data, style) + else: + if formula: + ws.write(row_pos, col, formula, style) + else: + spec[5]['write_cell_func'](r, col, data, style) + if set_column_size: + ws.col(col).width = spec[2] * 256 + return row_pos + 1 + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/report_xls/static/description/help.png b/report_xls/static/description/help.png new file mode 100644 index 00000000..3e7338c8 Binary files /dev/null and b/report_xls/static/description/help.png differ diff --git a/report_xls/static/description/icon.png b/report_xls/static/description/icon.png new file mode 100644 index 00000000..b8a2fcdf Binary files /dev/null and b/report_xls/static/description/icon.png differ diff --git a/report_xls/static/description/index.html b/report_xls/static/description/index.html new file mode 100644 index 00000000..1cdf4263 --- /dev/null +++ b/report_xls/static/description/index.html @@ -0,0 +1,84 @@ +
+
+
+

Excel report engine

+
+
+
+ +
+
+
+

+

This module adds Excel export capabilities to the standard odoo reporting engine. +

+
+
+
+ +
+
+

Report development

+

+ In order to create an Excel report you can +

    +
  • define a report of type 'xls'
  • +
  • pass {'xls_export': 1} via the context to the report create method
  • +
+

+

+ The report_xls class contains a number of attributes and methods to facilitate the creation XLS reports in odoo. +

    +
  • + cell types +
    Supported cell types : text, number, boolean, date. +
  • +
+
    +
  • + cell styles +
    The predefined cell style definitions result in a consistent look and feel of the odoo Excel reports. +
  • +
+
    +
  • + cell formulas +
    Cell formulas can be easily added with the help of the rowcol_to_cell() function which you can import from the utils.py module. +
  • +
+
    +
  • + Excel templates +
    It is possible to define Excel templates which can be adapted by 'inherited' modules. +
    Download the account_move_line_report_xls module from http://apps.odoo.com as example. +
  • +
+
    +
  • + XLS with multiple sheets +
    Download the account_journal_report_xls module from http://apps.odoo.com as example. +
  • +
+

+
+
+ +
+
+
+

Development assistance

+
+
+
+
+
+
+
+
+

+

Contact info@noviat.com for help with the development of Excel reports in odoo. +

+
+
+
+ diff --git a/report_xls/static/description/open_receivables.png b/report_xls/static/description/open_receivables.png new file mode 100644 index 00000000..a00c3ba4 Binary files /dev/null and b/report_xls/static/description/open_receivables.png differ diff --git a/report_xls/utils.py b/report_xls/utils.py new file mode 100644 index 00000000..943daae7 --- /dev/null +++ b/report_xls/utils.py @@ -0,0 +1,51 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2014 Noviat nv/sa (www.noviat.com). All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +def _render(code): + return compile(code, '', 'eval') + + +def rowcol_to_cell(row, col, row_abs=False, col_abs=False): + # Code based upon utils from xlwt distribution + """ + Convert numeric row/col notation to an Excel cell + reference string in A1 notation. + """ + d = col // 26 + m = col % 26 + chr1 = "" # Most significant character in AA1 + if row_abs: + row_abs = '$' + else: + row_abs = '' + if col_abs: + col_abs = '$' + else: + col_abs = '' + if d > 0: + chr1 = chr(ord('A') + d - 1) + chr2 = chr(ord('A') + m) + # Zero index to 1-index + return col_abs + chr1 + chr2 + row_abs + str(row + 1) + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/report_xlsx/README.rst b/report_xlsx/README.rst new file mode 100644 index 00000000..2ce2e112 --- /dev/null +++ b/report_xlsx/README.rst @@ -0,0 +1,87 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================ +Base report xlsx +================ + +This module provides a basic report class to generate xlsx report. + +Installation +============ + +Make sure you have ``xlsxwriter`` Python module installed:: + +$ pip install xlsxwriter + +Usage +===== + +An example of XLSX report for partners: + +A python class :: + + from openerp.addons.report_xlsx.report.report_xlsx import ReportXlsx + + class PartnerXlsx(ReportXlsx): + + def generate_xlsx_report(self, workbook, data, partners): + for obj in partners: + report_name = obj.name + # One sheet by partner + sheet = workbook.add_worksheet(report_name[:31]) + bold = workbook.add_format({'bold': True}) + sheet.write(0, 0, obj.name, bold) + + + PartnerXlsx('report.res.partner.xlsx', + 'res.partner') + +To manipulate the ``workbook`` and ``sheet`` objects, refer to the +`documentation `_ of ``xlsxwriter``. + +A report XML record :: + + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/143/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Adrien Peiffer + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/report_xlsx/__init__.py b/report_xlsx/__init__.py new file mode 100644 index 00000000..9a384baf --- /dev/null +++ b/report_xlsx/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import models +from . import report diff --git a/report_xlsx/__openerp__.py b/report_xlsx/__openerp__.py new file mode 100644 index 00000000..07985d16 --- /dev/null +++ b/report_xlsx/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': "Base report xlsx", + + 'summary': """ + Base module to create xlsx report""", + 'author': 'ACSONE SA/NV,' + 'Odoo Community Association (OCA)', + 'website': "http://acsone.eu", + 'category': 'Reporting', + 'version': '9.0.1.0.0', + 'license': 'AGPL-3', + 'external_dependencies': {'python': ['xlsxwriter']}, + 'depends': [ + 'base', + ], +} diff --git a/report_xlsx/models/__init__.py b/report_xlsx/models/__init__.py new file mode 100644 index 00000000..521aa82b --- /dev/null +++ b/report_xlsx/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).+ + +from . import ir_report diff --git a/report_xlsx/models/ir_report.py b/report_xlsx/models/ir_report.py new file mode 100644 index 00000000..e3793ae6 --- /dev/null +++ b/report_xlsx/models/ir_report.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import fields, models + + +class IrActionsReportXml(models.Model): + _inherit = 'ir.actions.report.xml' + + report_type = fields.Selection(selection_add=[("xlsx", "xlsx")]) diff --git a/report_xlsx/report/__init__.py b/report_xlsx/report/__init__.py new file mode 100644 index 00000000..37c50512 --- /dev/null +++ b/report_xlsx/report/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import report_xlsx diff --git a/report_xlsx/report/report_xlsx.py b/report_xlsx/report/report_xlsx.py new file mode 100644 index 00000000..285c97b5 --- /dev/null +++ b/report_xlsx/report/report_xlsx.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from cStringIO import StringIO + +from openerp.report.report_sxw import report_sxw +from openerp.api import Environment + +import logging +_logger = logging.getLogger(__name__) + +try: + import xlsxwriter +except ImportError: + _logger.debug('Can not import xlsxwriter`.') + + +class ReportXlsx(report_sxw): + + def create(self, cr, uid, ids, data, context=None): + self.env = Environment(cr, uid, context) + report_obj = self.env['ir.actions.report.xml'] + report = report_obj.search([('report_name', '=', self.name[7:])]) + if report.ids: + self.title = report.name + if report.report_type == 'xlsx': + return self.create_xlsx_report(ids, data, report) + return super(ReportXlsx, self).create(cr, uid, ids, data, context) + + def create_xlsx_report(self, ids, data, report): + self.parser_instance = self.parser( + self.env.cr, self.env.uid, self.name2, self.env.context) + objs = self.getObjects( + self.env.cr, self.env.uid, ids, self.env.context) + self.parser_instance.set_context(objs, data, ids, 'xlsx') + file_data = StringIO() + workbook = xlsxwriter.Workbook(file_data) + self.generate_xlsx_report(workbook, data, objs) + workbook.close() + file_data.seek(0) + return (file_data.read(), 'xlsx') + + def generate_xlsx_report(self, workbook, data, objs): + raise NotImplementedError() diff --git a/report_xlsx/static/description/icon.png b/report_xlsx/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/report_xlsx/static/description/icon.png differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..222148e9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +xlwt +xlsxwriter +py3o.template diff --git a/setup/.setuptools-odoo-make-default-ignore b/setup/.setuptools-odoo-make-default-ignore new file mode 100644 index 00000000..207e6153 --- /dev/null +++ b/setup/.setuptools-odoo-make-default-ignore @@ -0,0 +1,2 @@ +# addons listed in this file are ignored by +# setuptools-odoo-make-default (one addon per line) diff --git a/setup/README b/setup/README new file mode 100644 index 00000000..a63d633e --- /dev/null +++ b/setup/README @@ -0,0 +1,2 @@ +To learn more about this directory, please visit +https://pypi.python.org/pypi/setuptools-odoo diff --git a/setup/report_py3o/odoo_addons/__init__.py b/setup/report_py3o/odoo_addons/__init__.py new file mode 100644 index 00000000..de40ea7c --- /dev/null +++ b/setup/report_py3o/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/report_py3o/odoo_addons/report_py3o b/setup/report_py3o/odoo_addons/report_py3o new file mode 120000 index 00000000..5e51a0c1 --- /dev/null +++ b/setup/report_py3o/odoo_addons/report_py3o @@ -0,0 +1 @@ +../../../report_py3o \ No newline at end of file diff --git a/setup/report_py3o/setup.py b/setup/report_py3o/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/report_py3o/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/report_qweb_element_page_visibility/odoo_addons/__init__.py b/setup/report_qweb_element_page_visibility/odoo_addons/__init__.py new file mode 100644 index 00000000..de40ea7c --- /dev/null +++ b/setup/report_qweb_element_page_visibility/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/report_qweb_element_page_visibility/odoo_addons/report_qweb_element_page_visibility b/setup/report_qweb_element_page_visibility/odoo_addons/report_qweb_element_page_visibility new file mode 120000 index 00000000..44b835bb --- /dev/null +++ b/setup/report_qweb_element_page_visibility/odoo_addons/report_qweb_element_page_visibility @@ -0,0 +1 @@ +../../../report_qweb_element_page_visibility \ No newline at end of file diff --git a/setup/report_qweb_element_page_visibility/setup.py b/setup/report_qweb_element_page_visibility/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/report_qweb_element_page_visibility/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/report_xlsx/odoo_addons/__init__.py b/setup/report_xlsx/odoo_addons/__init__.py new file mode 100644 index 00000000..de40ea7c --- /dev/null +++ b/setup/report_xlsx/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/report_xlsx/odoo_addons/report_xlsx b/setup/report_xlsx/odoo_addons/report_xlsx new file mode 120000 index 00000000..6ef6301e --- /dev/null +++ b/setup/report_xlsx/odoo_addons/report_xlsx @@ -0,0 +1 @@ +../../../report_xlsx \ No newline at end of file diff --git a/setup/report_xlsx/setup.py b/setup/report_xlsx/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/report_xlsx/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)