Browse Source
Merge pull request #171 from etobella/11.0-mig-report_xlsx
Merge pull request #171 from etobella/11.0-mig-report_xlsx
[11.0] [MIG] report_xlsxpull/177/head
Jordi Ballester Alomar
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 569 additions and 0 deletions
-
90report_xlsx/README.rst
-
5report_xlsx/__init__.py
-
31report_xlsx/__manifest__.py
-
1report_xlsx/controllers/__init__.py
-
44report_xlsx/controllers/main.py
-
16report_xlsx/demo/report.xml
-
24report_xlsx/i18n/de.po
-
24report_xlsx/i18n/es.po
-
24report_xlsx/i18n/fr.po
-
24report_xlsx/i18n/hr.po
-
24report_xlsx/i18n/hr_HR.po
-
24report_xlsx/i18n/it.po
-
24report_xlsx/i18n/nl_NL.po
-
24report_xlsx/i18n/pt_PT.po
-
24report_xlsx/i18n/tr.po
-
1report_xlsx/models/__init__.py
-
33report_xlsx/models/ir_report.py
-
2report_xlsx/report/__init__.py
-
15report_xlsx/report/report_partner_xlsx.py
-
33report_xlsx/report/report_xlsx.py
-
BINreport_xlsx/static/description/icon.png
-
42report_xlsx/static/src/js/report/qwebactionmanager.js
-
1report_xlsx/tests/__init__.py
-
24report_xlsx/tests/test_report.py
-
13report_xlsx/views/webclient_templates.xml
-
2requirements.txt
@ -0,0 +1,90 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
||||
|
:target: https://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 |
||||
|
|
||||
|
For testing it is also necessary ``xlrd`` Python module installed:: |
||||
|
|
||||
|
$ pip install xlrd |
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
An example of XLSX report for partners on a module called `module_name`: |
||||
|
|
||||
|
A python class :: |
||||
|
|
||||
|
from odoo import models |
||||
|
|
||||
|
class PartnerXlsx(models.AbstractModel): |
||||
|
_name = 'report.module_name.report_name' |
||||
|
_inherit = 'report.report_xlsx.abstract' |
||||
|
|
||||
|
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) |
||||
|
|
||||
|
To manipulate the ``workbook`` and ``sheet`` objects, refer to the |
||||
|
`documentation <http://xlsxwriter.readthedocs.org/>`_ of ``xlsxwriter``. |
||||
|
|
||||
|
A report XML record :: |
||||
|
|
||||
|
<report |
||||
|
id="partner_xlsx" |
||||
|
model="res.partner" |
||||
|
string="Print to XLSX" |
||||
|
report_type="xlsx" |
||||
|
name="module_name.report_name" |
||||
|
file="res_partner" |
||||
|
attachment_use="False" |
||||
|
/> |
||||
|
|
||||
|
.. 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/11.0 |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues |
||||
|
<https://github.com/OCA/reporting-engine/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. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Adrien Peiffer <adrien.peiffer@acsone.eu> |
||||
|
* Enric Tobella <etobella@creublanca.es> |
||||
|
|
||||
|
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. |
@ -0,0 +1,5 @@ |
|||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from . import controllers |
||||
|
from . import models |
||||
|
from . import report |
@ -0,0 +1,31 @@ |
|||||
|
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>) |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
{ |
||||
|
'name': "Base report xlsx", |
||||
|
|
||||
|
'summary': """ |
||||
|
Base module to create xlsx report""", |
||||
|
'author': 'ACSONE SA/NV,' |
||||
|
'Creu Blanca,' |
||||
|
'Odoo Community Association (OCA)', |
||||
|
'website': "http://github.com/oca/reporting-engine", |
||||
|
'category': 'Reporting', |
||||
|
'version': '11.0.1.0.0', |
||||
|
'license': 'AGPL-3', |
||||
|
'external_dependencies': { |
||||
|
'python': [ |
||||
|
'xlsxwriter', |
||||
|
'xlrd', |
||||
|
], |
||||
|
}, |
||||
|
'depends': [ |
||||
|
'base', 'web', |
||||
|
], |
||||
|
'data': [ |
||||
|
'views/webclient_templates.xml', |
||||
|
], |
||||
|
'demo': [ |
||||
|
'demo/report.xml', |
||||
|
], |
||||
|
'installable': True, |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
from . import main |
@ -0,0 +1,44 @@ |
|||||
|
# Copyright (C) 2017 Creu Blanca |
||||
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). |
||||
|
|
||||
|
from odoo.addons.web.controllers import main as report |
||||
|
from odoo.http import route, request |
||||
|
|
||||
|
import json |
||||
|
|
||||
|
|
||||
|
class ReportController(report.ReportController): |
||||
|
@route() |
||||
|
def report_routes(self, reportname, docids=None, converter=None, **data): |
||||
|
if converter == 'xlsx': |
||||
|
report = request.env['ir.actions.report']._get_report_from_name( |
||||
|
reportname) |
||||
|
context = dict(request.env.context) |
||||
|
if docids: |
||||
|
docids = [int(i) for i in docids.split(',')] |
||||
|
if data.get('options'): |
||||
|
data.update(json.loads(data.pop('options'))) |
||||
|
if data.get('context'): |
||||
|
# Ignore 'lang' here, because the context in data is the one |
||||
|
# from the webclient *but* if the user explicitely wants to |
||||
|
# change the lang, this mechanism overwrites it. |
||||
|
data['context'] = json.loads(data['context']) |
||||
|
if data['context'].get('lang'): |
||||
|
del data['context']['lang'] |
||||
|
context.update(data['context']) |
||||
|
xlsx = report.with_context(context).render_xlsx( |
||||
|
docids, data=data |
||||
|
)[0] |
||||
|
xlsxhttpheaders = [ |
||||
|
('Content-Type', 'application/vnd.openxmlformats-' |
||||
|
'officedocument.spreadsheetml.sheet'), |
||||
|
('Content-Length', len(xlsx)), |
||||
|
( |
||||
|
'Content-Disposition', |
||||
|
'attachment; filename=' + report.report_file + '.xlsx' |
||||
|
) |
||||
|
] |
||||
|
return request.make_response(xlsx, headers=xlsxhttpheaders) |
||||
|
return super(ReportController, self).report_routes( |
||||
|
reportname, docids, converter, **data |
||||
|
) |
@ -0,0 +1,16 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<odoo> |
||||
|
<!-- |
||||
|
© 2017 Creu Blanca |
||||
|
License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). |
||||
|
--> |
||||
|
<report |
||||
|
id="partner_xlsx" |
||||
|
model="res.partner" |
||||
|
string="Print to XLSX" |
||||
|
report_type="xlsx" |
||||
|
name="report_xlsx.partner_xlsx" |
||||
|
file="res_partner" |
||||
|
attachment_use="False" |
||||
|
/> |
||||
|
</odoo> |
@ -0,0 +1,24 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * report_xlsx |
||||
|
# |
||||
|
# Translators: |
||||
|
# Niki Waibel <niki.waibel@gmail.com>, 2016 |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 10.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2016-11-01 20:11+0000\n" |
||||
|
"PO-Revision-Date: 2016-11-01 20:11+0000\n" |
||||
|
"Last-Translator: Niki Waibel <niki.waibel@gmail.com>, 2016\n" |
||||
|
"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Language: de\n" |
||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n" |
||||
|
|
||||
|
#. module: report_xlsx |
||||
|
#: model:ir.model,name:report_xlsx.model_ir_actions_report_xml |
||||
|
msgid "ir.actions.report.xml" |
||||
|
msgstr "ir.actions.report.xml" |
@ -0,0 +1,24 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * report_xlsx |
||||
|
# |
||||
|
# Translators: |
||||
|
# Pedro M. Baeza <pedro.baeza@gmail.com>, 2016 |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 10.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2016-11-01 20:11+0000\n" |
||||
|
"PO-Revision-Date: 2016-11-01 20:11+0000\n" |
||||
|
"Last-Translator: Pedro M. Baeza <pedro.baeza@gmail.com>, 2016\n" |
||||
|
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Language: es\n" |
||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n" |
||||
|
|
||||
|
#. module: report_xlsx |
||||
|
#: model:ir.model,name:report_xlsx.model_ir_actions_report_xml |
||||
|
msgid "ir.actions.report.xml" |
||||
|
msgstr "ir.actions.report.xml" |
@ -0,0 +1,24 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * report_xlsx |
||||
|
# |
||||
|
# Translators: |
||||
|
# OCA Transbot <transbot@odoo-community.org>, 2017 |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 10.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2017-05-31 03:52+0000\n" |
||||
|
"PO-Revision-Date: 2017-05-31 03:52+0000\n" |
||||
|
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n" |
||||
|
"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Language: fr\n" |
||||
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
||||
|
|
||||
|
#. module: report_xlsx |
||||
|
#: model:ir.model,name:report_xlsx.model_ir_actions_report_xml |
||||
|
msgid "ir.actions.report.xml" |
||||
|
msgstr "ir.actions.report.xml" |
@ -0,0 +1,24 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * report_xlsx |
||||
|
# |
||||
|
# Translators: |
||||
|
# OCA Transbot <transbot@odoo-community.org>, 2017 |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 10.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2017-05-31 03:52+0000\n" |
||||
|
"PO-Revision-Date: 2017-05-31 03:52+0000\n" |
||||
|
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n" |
||||
|
"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Language: hr\n" |
||||
|
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" |
||||
|
|
||||
|
#. module: report_xlsx |
||||
|
#: model:ir.model,name:report_xlsx.model_ir_actions_report_xml |
||||
|
msgid "ir.actions.report.xml" |
||||
|
msgstr "ir.actions.report.xml" |
@ -0,0 +1,24 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * report_xlsx |
||||
|
# |
||||
|
# Translators: |
||||
|
# Bole <bole@dajmi5.com>, 2016 |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 10.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2016-11-01 20:11+0000\n" |
||||
|
"PO-Revision-Date: 2016-11-01 20:11+0000\n" |
||||
|
"Last-Translator: Bole <bole@dajmi5.com>, 2016\n" |
||||
|
"Language-Team: Croatian (Croatia) (https://www.transifex.com/oca/teams/23907/hr_HR/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Language: hr_HR\n" |
||||
|
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" |
||||
|
|
||||
|
#. module: report_xlsx |
||||
|
#: model:ir.model,name:report_xlsx.model_ir_actions_report_xml |
||||
|
msgid "ir.actions.report.xml" |
||||
|
msgstr "ir.actions.report.xml" |
@ -0,0 +1,24 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * report_xlsx |
||||
|
# |
||||
|
# Translators: |
||||
|
# OCA Transbot <transbot@odoo-community.org>, 2017 |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 10.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2017-05-31 03:52+0000\n" |
||||
|
"PO-Revision-Date: 2017-05-31 03:52+0000\n" |
||||
|
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n" |
||||
|
"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Language: it\n" |
||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n" |
||||
|
|
||||
|
#. module: report_xlsx |
||||
|
#: model:ir.model,name:report_xlsx.model_ir_actions_report_xml |
||||
|
msgid "ir.actions.report.xml" |
||||
|
msgstr "ir.actions.report.xml" |
@ -0,0 +1,24 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * report_xlsx |
||||
|
# |
||||
|
# Translators: |
||||
|
# Peter Hageman <hageman.p@gmail.com>, 2017 |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 10.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2017-06-23 00:28+0000\n" |
||||
|
"PO-Revision-Date: 2017-06-23 00:28+0000\n" |
||||
|
"Last-Translator: Peter Hageman <hageman.p@gmail.com>, 2017\n" |
||||
|
"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/teams/23907/nl_NL/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Language: nl_NL\n" |
||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n" |
||||
|
|
||||
|
#. module: report_xlsx |
||||
|
#: model:ir.model,name:report_xlsx.model_ir_actions_report_xml |
||||
|
msgid "ir.actions.report.xml" |
||||
|
msgstr "ir.actions.report.xml" |
@ -0,0 +1,24 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * report_xlsx |
||||
|
# |
||||
|
# Translators: |
||||
|
# OCA Transbot <transbot@odoo-community.org>, 2017 |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 10.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2017-05-31 03:52+0000\n" |
||||
|
"PO-Revision-Date: 2017-05-31 03:52+0000\n" |
||||
|
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n" |
||||
|
"Language-Team: Portuguese (Portugal) (https://www.transifex.com/oca/teams/23907/pt_PT/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Language: pt_PT\n" |
||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n" |
||||
|
|
||||
|
#. module: report_xlsx |
||||
|
#: model:ir.model,name:report_xlsx.model_ir_actions_report_xml |
||||
|
msgid "ir.actions.report.xml" |
||||
|
msgstr "ir.actions.report.xml" |
@ -0,0 +1,24 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * report_xlsx |
||||
|
# |
||||
|
# Translators: |
||||
|
# OCA Transbot <transbot@odoo-community.org>, 2017 |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 10.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2017-05-31 03:52+0000\n" |
||||
|
"PO-Revision-Date: 2017-05-31 03:52+0000\n" |
||||
|
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n" |
||||
|
"Language-Team: Turkish (https://www.transifex.com/oca/teams/23907/tr/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Language: tr\n" |
||||
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
||||
|
|
||||
|
#. module: report_xlsx |
||||
|
#: model:ir.model,name:report_xlsx.model_ir_actions_report_xml |
||||
|
msgid "ir.actions.report.xml" |
||||
|
msgstr "ir.actions.report.xml" |
@ -0,0 +1 @@ |
|||||
|
from . import ir_report |
@ -0,0 +1,33 @@ |
|||||
|
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>) |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from odoo import api, fields, models, _ |
||||
|
from odoo.exceptions import UserError |
||||
|
|
||||
|
|
||||
|
class ReportAction(models.Model): |
||||
|
_inherit = 'ir.actions.report' |
||||
|
|
||||
|
report_type = fields.Selection(selection_add=[("xlsx", "xlsx")]) |
||||
|
|
||||
|
@api.model |
||||
|
def render_xlsx(self, docids, data): |
||||
|
report_model_name = 'report.%s' % self.report_name |
||||
|
report_model = self.env.get(report_model_name) |
||||
|
if report_model is None: |
||||
|
raise UserError(_('%s model was not found' % report_model_name)) |
||||
|
return report_model.with_context({ |
||||
|
'active_model': self.model |
||||
|
}).create_xlsx_report(docids, data) |
||||
|
|
||||
|
@api.model |
||||
|
def _get_report_from_name(self, report_name): |
||||
|
res = super(ReportAction, self)._get_report_from_name(report_name) |
||||
|
if res: |
||||
|
return res |
||||
|
report_obj = self.env['ir.actions.report'] |
||||
|
qwebtypes = ['xlsx'] |
||||
|
conditions = [('report_type', 'in', qwebtypes), |
||||
|
('report_name', '=', report_name)] |
||||
|
context = self.env['res.users'].context_get() |
||||
|
return report_obj.with_context(context).search(conditions, limit=1) |
@ -0,0 +1,2 @@ |
|||||
|
from . import report_xlsx |
||||
|
from . import report_partner_xlsx |
@ -0,0 +1,15 @@ |
|||||
|
# Copyright 2017 Creu Blanca |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from odoo import models |
||||
|
|
||||
|
|
||||
|
class PartnerXlsx(models.AbstractModel): |
||||
|
_name = 'report.report_xlsx.partner_xlsx' |
||||
|
_inherit = 'report.report_xlsx.abstract' |
||||
|
|
||||
|
def generate_xlsx_report(self, workbook, data, partners): |
||||
|
for obj in partners: |
||||
|
sheet = workbook.add_worksheet('Report') |
||||
|
bold = workbook.add_format({'bold': True}) |
||||
|
sheet.write(0, 0, obj.name, bold) |
@ -0,0 +1,33 @@ |
|||||
|
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>) |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from io import BytesIO |
||||
|
|
||||
|
from odoo import models |
||||
|
|
||||
|
import logging |
||||
|
_logger = logging.getLogger(__name__) |
||||
|
|
||||
|
try: |
||||
|
import xlsxwriter |
||||
|
except ImportError: |
||||
|
_logger.debug('Can not import xlsxwriter`.') |
||||
|
|
||||
|
|
||||
|
class ReportXlsxAbstract(models.AbstractModel): |
||||
|
_name = 'report.report_xlsx.abstract' |
||||
|
|
||||
|
def create_xlsx_report(self, docids, data): |
||||
|
objs = self.env[self.env.context.get('active_model')].browse(docids) |
||||
|
file_data = BytesIO() |
||||
|
workbook = xlsxwriter.Workbook(file_data, self.get_workbook_options()) |
||||
|
self.generate_xlsx_report(workbook, data, objs) |
||||
|
workbook.close() |
||||
|
file_data.seek(0) |
||||
|
return file_data.read(), 'xlsx' |
||||
|
|
||||
|
def get_workbook_options(self): |
||||
|
return {} |
||||
|
|
||||
|
def generate_xlsx_report(self, workbook, data, objs): |
||||
|
raise NotImplementedError() |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -0,0 +1,42 @@ |
|||||
|
// © 2017 Creu Blanca
|
||||
|
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
|
odoo.define('report_xml.report', function(require){ |
||||
|
'use strict'; |
||||
|
|
||||
|
var ActionManager= require('web.ActionManager'); |
||||
|
var crash_manager = require('web.crash_manager'); |
||||
|
var framework = require('web.framework'); |
||||
|
|
||||
|
ActionManager.include({ |
||||
|
ir_actions_report: function (action, options){ |
||||
|
var self = this; |
||||
|
var cloned_action = _.clone(action); |
||||
|
if (cloned_action.report_type === 'xlsx') { |
||||
|
framework.blockUI(); |
||||
|
var report_xlsx_url = 'report/xlsx/' + cloned_action.report_name; |
||||
|
if(cloned_action.context.active_ids){ |
||||
|
report_xlsx_url += '/' + cloned_action.context.active_ids.join(','); |
||||
|
}else{ |
||||
|
report_xlsx_url += '?options=' + encodeURIComponent(JSON.stringify(cloned_action.data)); |
||||
|
report_xlsx_url += '&context=' + encodeURIComponent(JSON.stringify(cloned_action.context)); |
||||
|
} |
||||
|
self.getSession().get_file({ |
||||
|
url: report_xlsx_url, |
||||
|
data: {data: JSON.stringify([ |
||||
|
report_xlsx_url, |
||||
|
cloned_action.report_type |
||||
|
])}, |
||||
|
error: crash_manager.rpc_error.bind(crash_manager), |
||||
|
success: function (){ |
||||
|
if(cloned_action && options && !cloned_action.dialog){ |
||||
|
options.on_close(); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
framework.unblockUI(); |
||||
|
return; |
||||
|
} |
||||
|
return self._super(action, options); |
||||
|
} |
||||
|
}); |
||||
|
}); |
@ -0,0 +1 @@ |
|||||
|
from . import test_report |
@ -0,0 +1,24 @@ |
|||||
|
# Copyright 2017 Creu Blanca |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from odoo.tests import common |
||||
|
import logging |
||||
|
_logger = logging.getLogger(__name__) |
||||
|
|
||||
|
try: |
||||
|
from xlrd import open_workbook |
||||
|
except ImportError: |
||||
|
_logger.debug('Can not import xlsxwriter`.') |
||||
|
|
||||
|
|
||||
|
class TestReport(common.TransactionCase): |
||||
|
def test_report(self): |
||||
|
report_object = self.env['ir.actions.report'] |
||||
|
report_name = 'report_xlsx.partner_xlsx' |
||||
|
report = report_object._get_report_from_name(report_name) |
||||
|
docs = self.env['res.company'].search([], limit=1).partner_id |
||||
|
self.assertEqual(report.report_type, 'xlsx') |
||||
|
rep = report.render(docs.ids, {}) |
||||
|
wb = open_workbook(file_contents=rep[0]) |
||||
|
sheet = wb.sheet_by_index(0) |
||||
|
self.assertEqual(sheet.cell(0, 0).value, docs.name) |
@ -0,0 +1,13 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<odoo> |
||||
|
<!-- |
||||
|
© 2017 Creu Blanca |
||||
|
License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). |
||||
|
--> |
||||
|
<template id="assets_backend" inherit_id="web.assets_backend"> |
||||
|
<xpath expr="." position="inside"> |
||||
|
<script type="text/javascript" src="/report_xlsx/static/src/js/report/qwebactionmanager.js"/> |
||||
|
</xpath> |
||||
|
|
||||
|
</template> |
||||
|
</odoo> |
@ -0,0 +1,2 @@ |
|||||
|
xlsxwriter |
||||
|
xlrd |
Write
Preview
Loading…
Cancel
Save
Reference in new issue