Fix report_xlsx for printing from wizards

This commit is contained in:
Graeme Gellatly
2018-08-25 15:20:02 +12:00
committed by Alex Cuellar
parent 498fd57c87
commit fcc3c36c56
4 changed files with 74 additions and 12 deletions

View File

@@ -17,8 +17,30 @@ except ImportError:
class ReportXlsxAbstract(models.AbstractModel):
_name = 'report.report_xlsx.abstract'
def _get_objs_for_report(self, docids, data):
"""
Returns objects for xlx report. From WebUI these
are either as docids taken from context.active_ids or
in the case of wizard are in data. Manual calls may rely
on regular context, setting docids, or setting data.
:param docids: list of integers, typically provided by
qwebactionmanager for regular Models.
:param data: dictionary of data, if present typically provided
by qwebactionmanager for TransientModels.
:param ids: list of integers, provided by overrides.
:return: recordset of active model for ids.
"""
if docids:
ids = docids
elif data and 'context' in data:
ids = data["context"].get('active_ids', [])
else:
ids = self.env.context.get('active_ids', [])
return self.env[self.env.context.get('active_model')].browse(ids)
def create_xlsx_report(self, docids, data):
objs = self.env[self.env.context.get('active_model')].browse(docids)
objs = self._get_objs_for_report(docids, data)
file_data = BytesIO()
workbook = xlsxwriter.Workbook(file_data, self.get_workbook_options())
self.generate_xlsx_report(workbook, data, objs)
@@ -27,6 +49,10 @@ class ReportXlsxAbstract(models.AbstractModel):
return file_data.read(), 'xlsx'
def get_workbook_options(self):
"""
See https://xlsxwriter.readthedocs.io/workbook.html constructor options
:return: A dictionary of options
"""
return {}
def generate_xlsx_report(self, workbook, data, objs):