Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
6751 Vizualizări

Hello,

I'm working on Odoo 11, and i have a button to print XLS Report, I generate the report successfully using the xlswriter library but i don't know what should i return in the function in order to allow the user to download the XLS file.

Please, see the code bellow and tell me what should i put instead of *****?

def generate_excel_report(self):
self.calculate_validation_lines()
workbook = xlsxwriter.Workbook("Stock valuation report {0} to {1}".format(str(self.date_from), str(self.date_to)))
for company in self.all_companies:
if self.has_valuation(company):
sheet = self.create_worksheet(workbook, company)
row = 9
col = 0
for line in self.stock_valuation_lines:
if line.product_id.company_id == company:
sheet.write(row, col, line.product_id.categ_id.name)
sheet.write(row, col+1, line.product_id.name)
sheet.write(row, col+2, line.product_id.barcode)
sheet.write(row, col+3, line.product_id.default_code)
sheet.write(row, col+4, line.beginning_qty)
sheet.write(row, col+5, line.received_qty)
sheet.write(row, col+6, line.sale_qty)
sheet.write(row, col+7, line.internal_qty)
sheet.write(row, col+8, line.adjustment_qty)
sheet.write(row, col+9, line.ending_qty)
sheet.write(row, col+10, line.cost)
sheet.write(row, col+11, line.total_value)
workbook.close()
return *****


Imagine profil
Abandonează
Cel mai bun răspuns
xlsx_data = output.getvalue()    
return request.make_response(xlsx_data,
[('Content-Type', 'application/vnd.ms-excel'),
('Content-Disposition', content_disposition(str(section_name)+'.xlsx'))])

Hope this will heps you


Imagine profil
Abandonează
Cel mai bun răspuns

First save, then close

    workbook.save()
workbook.close()

That will save the file.  By the looks of it, you didn't specify a file path so it will be in whatever directory the Python script is in.  I would use `tempfile` to store into a temporary directory.  If you need the file path, you can then return that.  If not, you can use open in read-binary & return the file in binary.

Imagine profil
Abandonează
Autor

And what should i return ?

Related Posts Răspunsuri Vizualizări Activitate
3
iul. 25
26871
2
dec. 17
3486
0
dec. 21
3400
5
dec. 19
11063
4
oct. 18
4769