dev-resources.site
for different kinds of informations.
Odoo : create CSV file and download
Published at
10/28/2024
Categories
Author
Jeevachaithanyan Sivanandan
Categories
1 categories in total
open
a wizard method to download some information of the sale order - order lines to csv file
this method have features as :
- get current sale order
- get product id and product quantities from sale order lines
- write those into a csv file
- initiate the download of csv file
- auto close the wizard
import base64
import csv
from io import StringIO
def action_download_template(self):
sale_order = self.get_current_sale_order()
dynamic_filename = f"so_{sale_order.id}_template.csv"
partner_id = sale_order.partner_id.id if sale_order.partner_id else ''
data = [["Partner ID", "Product ID", "Product Quantity"]]
for line in sale_order.order_line:
data.append([partner_id, line.product_template_id.default_code, line.product_uom_qty])
csv_data = StringIO()
writer = csv.writer(csv_data)
writer.writerows(data)
csv_data.seek(0)
csv_base64 = base64.b64encode(csv_data.getvalue().encode('utf-8'))
csv_data.close()
self.write({'csv_file': csv_base64, 'file_name': dynamic_filename})
return {
'type': 'ir.actions.act_url',
'url': f"/web/content/?model=sale.order.import.wizard&id={self.id}&field=csv_file&download=true&filename={dynamic_filename}",
'target': 'self',
'next': {'type': 'ir.actions.act_window_close'},
}
Articles
12 articles in total
Python Program for a Turing Machine Simulator python Copy code
read article
Install Odoo v 17 with Python 3.12 in MSWindows 11
read article
Boosting Code Quality in Odoo with Type Hints: Benefits Beyond Performance
read article
Odoo: Import CSV file and write into sale order lines
read article
Odoo : create CSV file and download
currently reading
Odoo : how to create a Wizard with download a file and auto close
read article
How to Configure Multiple Conditions in Odoo XML Views
read article
Odoo : Patch a Javascript class
read article
how to create new permission groups, permission category
read article
Odoo User Permission and groups
read article
extended unpacking in Python
read article
odoo v14 and issues with requirements.txt
read article
Featured ones: