[IMP]report_xlsx: improvements and adapt to add `report_xlsx_boilerplate` module
- Add the xlsxwriter python external dependency in the manifest as it should have already been included in the past - Decouple workbook obtation - Add test file in order to add a test in the `report_xlsx_boilerplate` method. Only used if the latest module is installed.pull/798/head
parent
3b14b91780
commit
60b69e56e9
|
@ -5,7 +5,7 @@ import logging
|
||||||
import re
|
import re
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from odoo import models
|
from odoo import api, models
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -71,9 +71,9 @@ class ReportXlsxAbstract(models.AbstractModel):
|
||||||
|
|
||||||
def _get_objs_for_report(self, docids, data):
|
def _get_objs_for_report(self, docids, data):
|
||||||
"""
|
"""
|
||||||
Returns objects for xlx report. From WebUI these
|
Returns objects for xlsx report. From WebUI these
|
||||||
are either as docids taken from context.active_ids or
|
are either as docids taken from context.active_ids or
|
||||||
in the case of wizard are in data. Manual calls may rely
|
in the case of wizard are in data. Manual calls may rely
|
||||||
on regular context, setting docids, or setting data.
|
on regular context, setting docids, or setting data.
|
||||||
|
|
||||||
:param docids: list of integers, typically provided by
|
:param docids: list of integers, typically provided by
|
||||||
|
@ -101,7 +101,7 @@ class ReportXlsxAbstract(models.AbstractModel):
|
||||||
def create_xlsx_report(self, docids, data):
|
def create_xlsx_report(self, docids, data):
|
||||||
objs = self._get_objs_for_report(docids, data)
|
objs = self._get_objs_for_report(docids, data)
|
||||||
file_data = BytesIO()
|
file_data = BytesIO()
|
||||||
workbook = xlsxwriter.Workbook(file_data, self.get_workbook_options())
|
workbook = self.get_workbook(file_data)
|
||||||
self.generate_xlsx_report(workbook, data, objs)
|
self.generate_xlsx_report(workbook, data, objs)
|
||||||
workbook.close()
|
workbook.close()
|
||||||
file_data.seek(0)
|
file_data.seek(0)
|
||||||
|
@ -116,3 +116,15 @@ class ReportXlsxAbstract(models.AbstractModel):
|
||||||
|
|
||||||
def generate_xlsx_report(self, workbook, data, objs):
|
def generate_xlsx_report(self, workbook, data, objs):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _get_new_workbook(self, file_data):
|
||||||
|
"""
|
||||||
|
:return: empty Workbook
|
||||||
|
:rtype: xlsxwriter.Workbook object
|
||||||
|
"""
|
||||||
|
return xlsxwriter.Workbook(file_data, self.get_workbook_options())
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def get_workbook(self, file_data):
|
||||||
|
return self._get_new_workbook(file_data)
|
||||||
|
|
Binary file not shown.
|
@ -1,5 +1,7 @@
|
||||||
# generated from manifests external_dependencies
|
# generated from manifests external_dependencies
|
||||||
cryptography
|
cryptography
|
||||||
endesive
|
endesive
|
||||||
|
openpyxl
|
||||||
py3o.formats
|
py3o.formats
|
||||||
py3o.template
|
py3o.template
|
||||||
|
xlsxwriter
|
||||||
|
|
Loading…
Reference in New Issue