@@ -33,18 +33,19 @@ def _mis_builder_add_annotation(self, sheet, cell, row_pos, col_pos, notes):
3333 """
3434 if cell and (annotation := notes .get (cell .cell_id , {}).get ("text" )):
3535 sheet .write_comment (row_pos , col_pos , annotation )
36+
37+ def _get_worksheet_name (self , mis_instance ):
38+ return mis_instance ._get_xlsx_report_name ()[:31 ]
3639
37- def generate_xlsx_report (self , workbook , data , objects ):
40+ def _generate_xlsx_one_report (self , workbook , mis_instance ):
3841 # get the computed result of the report
39- matrix = objects ._compute_matrix ()
40- notes = objects .get_notes_by_cell_id ()
42+ matrix = mis_instance ._compute_matrix ()
43+ notes = mis_instance .get_notes_by_cell_id ()
4144 style_obj = self .env ["mis.report.style" ]
4245
4346 # create worksheet
44- report_name = "{} - {}" .format (
45- objects [0 ].name , ", " .join ([a .name for a in objects [0 ].query_company_ids ])
46- )
47- sheet = workbook .add_worksheet (report_name [:31 ])
47+ worksheet_name = self ._get_worksheet_name (mis_instance )
48+ sheet = workbook .add_worksheet (worksheet_name )
4849 row_pos = 0
4950 col_pos = 0
5051 # width of the labels column
@@ -57,13 +58,14 @@ def generate_xlsx_report(self, workbook, data, objects):
5758 header_format = workbook .add_format (
5859 {"bold" : True , "align" : "center" , "bg_color" : "#F0EEEE" }
5960 )
61+ report_name = mis_instance ._get_xlsx_report_name ()
6062 sheet .write (row_pos , 0 , report_name , bold )
6163 row_pos += 2
6264
6365 # filters
64- filter_descriptions = objects .get_filter_descriptions ()
66+ filter_descriptions = mis_instance .get_filter_descriptions ()
6567 if filter_descriptions :
66- for filter_description in objects .get_filter_descriptions ():
68+ for filter_description in mis_instance .get_filter_descriptions ():
6769 sheet .write (row_pos , 0 , filter_description )
6870 row_pos += 1
6971 row_pos += 1
@@ -88,7 +90,9 @@ def generate_xlsx_report(self, workbook, data, objects):
8890 else :
8991 sheet .write (row_pos , col_pos , label , header_format )
9092 col_width [col_pos ] = max (
91- col_width [col_pos ], len (col .label or "" ), len (col .description or "" )
93+ col_width [col_pos ],
94+ len (col .label or "" ),
95+ len (col .description or "" ),
9296 )
9397 col_pos += col .colspan
9498 row_pos += 1
@@ -184,3 +188,9 @@ def generate_xlsx_report(self, workbook, data, objects):
184188 min_col_pos = min (col_width .keys ())
185189 max_col_pos = max (col_width .keys ())
186190 sheet .set_column (min_col_pos , max_col_pos , data_col_width * COL_WIDTH )
191+
192+ return sheet
193+
194+ def generate_xlsx_report (self , workbook , data , objects ):
195+ for instance in objects :
196+ self ._generate_xlsx_one_report (workbook , instance )
0 commit comments