Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
2 Besvarelser
4827 Visninger

Hello, I have created one button for exporting data into an excel file but it is storing an excel file locally on the system .instead of that I want to download that file with a button click. here is my code.

def object_button(self):
lists = []
for rec in self:
# project_detail_ids field of estimation table
for record in rec.project_detail_ids:
dicts = {}
for task in record.task_id:
print('task category_id', task.category_id)
print('dicts inside ---------------', dicts)
print("task_name=====>",task.module_name)
dicts['Catgory_name'] = task.category_id.category_name
dicts['Module_Name'] = task.module_name
dicts['Hours'] = record.hours
dicts['Notes'] = record.task_notes
dicts['Total_Hours']= self.total_hours
print('inside',dicts)
lists.append(dicts)
df = pd.DataFrame.from_dict(lists)
print("data frame==>",df)
# add data in excel sheet
data = df.to_excel('estimation.xlsx',index=False)
print(lists)
# st.download_button(label='Download',
# data=data,
# file_name= 'estimation.xlsx')
return {
'effect': {
'fadeout': 'slow',
'message': 'Export Successfully.. !!', 
'type': 'rainbow_man',
}
}




Avatar
Kassér
Bedste svar

Hi,

You can return this on the action of the button

return {
'type': 'ir.actions.report',
'data': {'model': 'model.name',
'options': json.dumps(data,default=date_utils.json_default),
'output_format': 'xlsx',
'report_name': 'IReport Name',
            },
 'report_type': 'xlsx'
}

Regards

Avatar
Kassér
Bedste svar

How about using Odoo's "export" functionality?

From a tree (list) view: Select records to export / action / export. 

Avatar
Kassér