|
24 | 24 | class MisBuilderXlsx(models.AbstractModel):
|
25 | 25 | _inherit = "report.mis_builder.mis_report_instance_xlsx"
|
26 | 26 |
|
| 27 | + # flake8: noqa: C901 |
27 | 28 | def generate_xlsx_report(self, workbook, data, objects):
|
28 |
| - |
| 29 | + if not objects[0].report_id.use_code_column: |
| 30 | + return super(MisBuilderXlsx, self).generate_xlsx_report( |
| 31 | + workbook, data, objects |
| 32 | + ) |
29 | 33 | # get the computed result of the report
|
30 | 34 | matrix = objects._compute_matrix()
|
31 | 35 | style_obj = self.env["mis.report.style"]
|
32 | 36 |
|
33 | 37 | # create worksheet
|
34 | 38 | report_name = "{} - {}".format(
|
35 |
| - objects[0].name, ", ".join([a.name for a in objects[0].query_company_ids]) |
| 39 | + objects[0].name, |
| 40 | + ", ".join([a.name for a in objects[0].query_company_ids]), |
36 | 41 | )
|
37 | 42 | sheet = workbook.add_worksheet(report_name[:31])
|
38 | 43 | row_pos = 0
|
@@ -78,7 +83,9 @@ def generate_xlsx_report(self, workbook, data, objects):
|
78 | 83 | else:
|
79 | 84 | sheet.write(row_pos, col_pos, label, header_format)
|
80 | 85 | col_width[col_pos] = max(
|
81 |
| - col_width[col_pos], len(col.label or ""), len(col.description or "") |
| 86 | + col_width[col_pos], |
| 87 | + len(col.label or ""), |
| 88 | + len(col.description or ""), |
82 | 89 | )
|
83 | 90 | col_pos += col.colspan
|
84 | 91 | row_pos += 1
|
@@ -111,13 +118,13 @@ def generate_xlsx_report(self, workbook, data, objects):
|
111 | 118 | row_format = workbook.add_format(row_xlsx_style)
|
112 | 119 | col_pos = 0
|
113 | 120 |
|
114 |
| - code = ( |
115 |
| - objects[0].report_id.kpi_ids.filtered(lambda k: k.id == row.kpi.id).code |
116 |
| - ) |
| 121 | + code = objects[0].report_id.computed_code(row.label) |
117 | 122 | sheet.write(row_pos, col_pos, code, row_format)
|
118 | 123 | col_pos += 1
|
119 | 124 |
|
120 | 125 | label = row.label
|
| 126 | + if code: |
| 127 | + label = label.split(" ")[1] |
121 | 128 | if row.description:
|
122 | 129 | label += "\n" + row.description
|
123 | 130 | sheet.set_row(row_pos, ROW_HEIGHT * 2)
|
|
0 commit comments