I want to print a text file (.txt) just like how to print a pdf file in odoo. Is it there a way on how to do this feat? I've been searching in other forums with this same question but can't find a sufficient answer.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
2
ตอบกลับ
15102
มุมมอง
Hello jmevic amortizado,
You can use below python code in some button action so you can download your text file as odoo reports
Following python code:
f_read = Your test file file_data = f_read.read()#Pass your text file data using encoding.
values = {
'name': "Name of text file.txt",
'datas_fname': 'print_file_name.txt',
'res_model': 'ir.ui.view',
'res_id': False,
'type': 'binary',
'public': True,
'datas': file_data.encode('utf8').encode('base64'),
}
#Using your data create as attachment.
attachment_id = self.env['ir.attachment'].sudo().create(values)
#Prepare your download URL download_url = '/web/content/' + str(attachment_id.id) + '?download=True'
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
# Return so it will download in your system return {
"type": "ir.actions.act_url",
"url": str(base_url) + str(download_url),
"target": "new",
}
Hope this helps you!
Thanks.
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อRelated Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
---|---|---|---|---|
how to create and download a text file
แก้ไขแล้ว
|
|
1
พ.ย. 22
|
6443 | |
|
4
ก.ย. 24
|
2211 | ||
|
2
ก.ย. 24
|
1356 | ||
|
0
มี.ค. 15
|
3982 | ||
|
9
พ.ย. 19
|
11565 |
Hi,
Check this link, in this you can see how to create a .txt file and how to do operations in it.
You can give this python code in some button action so that the ..txt file we get created on clicking on it.
http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python