|
@ -17,8 +17,30 @@ except ImportError: |
|
|
class ReportXlsxAbstract(models.AbstractModel): |
|
|
class ReportXlsxAbstract(models.AbstractModel): |
|
|
_name = 'report.report_xlsx.abstract' |
|
|
_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): |
|
|
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() |
|
|
file_data = BytesIO() |
|
|
workbook = xlsxwriter.Workbook(file_data, self.get_workbook_options()) |
|
|
workbook = xlsxwriter.Workbook(file_data, self.get_workbook_options()) |
|
|
self.generate_xlsx_report(workbook, data, objs) |
|
|
self.generate_xlsx_report(workbook, data, objs) |
|
@ -27,6 +49,10 @@ class ReportXlsxAbstract(models.AbstractModel): |
|
|
return file_data.read(), 'xlsx' |
|
|
return file_data.read(), 'xlsx' |
|
|
|
|
|
|
|
|
def get_workbook_options(self): |
|
|
def get_workbook_options(self): |
|
|
|
|
|
""" |
|
|
|
|
|
See https://xlsxwriter.readthedocs.io/workbook.html constructor options |
|
|
|
|
|
:return: A dictionary of options |
|
|
|
|
|
""" |
|
|
return {} |
|
|
return {} |
|
|
|
|
|
|
|
|
def generate_xlsx_report(self, workbook, data, objs): |
|
|
def generate_xlsx_report(self, workbook, data, objs): |
|
|