Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] mis_builder: allow to export multiple report in one xls #669

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion mis_builder/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,6 @@ def print_pdf(self):
)

def export_xls(self):
self.ensure_one()
return self.env.ref("mis_builder.xls_export").report_action(
self, data=dict(dummy=True)
) # required to propagate context
Expand Down
19 changes: 13 additions & 6 deletions mis_builder/report/mis_report_instance_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ class MisBuilderXlsx(models.AbstractModel):
_description = "MIS Builder XLSX report"
_inherit = "report.report_xlsx.abstract"

def generate_xlsx_report(self, workbook, data, objects):
def _generate_xlsx_one_report(self, workbook, mis_instance):
# get the computed result of the report
matrix = objects._compute_matrix()
matrix = mis_instance._compute_matrix()
style_obj = self.env["mis.report.style"]

# create worksheet
report_name = "{} - {}".format(
objects[0].name, ", ".join([a.name for a in objects[0].query_company_ids])
mis_instance[0].name,
", ".join([a.name for a in mis_instance[0].query_company_ids]),
)
sheet = workbook.add_worksheet(report_name[:31])
row_pos = 0
Expand All @@ -52,9 +53,9 @@ def generate_xlsx_report(self, workbook, data, objects):
row_pos += 2

# filters
filter_descriptions = objects.get_filter_descriptions()
filter_descriptions = mis_instance.get_filter_descriptions()
if filter_descriptions:
for filter_description in objects.get_filter_descriptions():
for filter_description in mis_instance.get_filter_descriptions():
sheet.write(row_pos, 0, filter_description)
row_pos += 1
row_pos += 1
Expand All @@ -79,7 +80,9 @@ def generate_xlsx_report(self, workbook, data, objects):
else:
sheet.write(row_pos, col_pos, label, header_format)
col_width[col_pos] = max(
col_width[col_pos], len(col.label or ""), len(col.description or "")
col_width[col_pos],
len(col.label or ""),
len(col.description or ""),
)
col_pos += col.colspan
row_pos += 1
Expand Down Expand Up @@ -174,3 +177,7 @@ def generate_xlsx_report(self, workbook, data, objects):
min_col_pos = min(col_width.keys())
max_col_pos = max(col_width.keys())
sheet.set_column(min_col_pos, max_col_pos, data_col_width * COL_WIDTH)

def generate_xlsx_report(self, workbook, data, objects):
for instance in objects:
self._generate_xlsx_one_report(workbook, instance)
11 changes: 11 additions & 0 deletions mis_builder/report/mis_report_instance_xlsx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@
<field name="report_type">xlsx</field>
<field name="report_file">mis_report_instance</field>
</record>

<record model="ir.actions.server" id="mis_builder_print_xls_report">
<field name="name">Export XLS</field>
<field name="model_id" ref="mis_builder.model_mis_report_instance" />
<field name="binding_model_id" ref="mis_builder.model_mis_report_instance" />
<field name="binding_view_types">list</field>
<field name="state">code</field>
<field name="code">
action = records.export_xls()
</field>
</record>
</odoo>
Loading