Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Discuss
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

How to create a file on the server, and download it on the client?

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
serverclientfiledownloadoutput
5 Replies
20313 Tampilan
Avatar
Eric

Hello, I need to output a file on the server so that users can download it on their machines.  How can I do this in Odoo?

1
Avatar
Buang
Sehrish

I hope you are looking this: http://learnopenerp.blogspot.com/2020/06/write-binary-data-nto-zip-file-and-downlaod-it-on-button-click-in-odoo.html

Avatar
Bole
Jawaban Terbai

Probably the best solution is to create it server side, base64 encode it, and attach it to relevant document... 
For simplicity here is example.. 
Let's say you want some xml report... 
1. you generate the xml_string then you pass it to a method like this:

def _attach_xml_file(self, cr, uid, ids, xml_string, context=None):  

      import base64

        assert len(ids) == 1, "Only one ID accepted"
        model_obj= self.pool.get('your.model')          # the model of record you want file attached
        record_obj= model_obj.browse(cr, uid, ids[0]) # actual record to wich you attach file
        file_name = 'name_your_file_here.xml'
        attach_name = file_name
        attach_obj = self.pool.get('ir.attachment')
        context.update({'default_res_id': ids[0], 
                                 'default_res_model': 'your.model'})

        attach_id = attach_obj.create(cr, uid, {'name': attach_name, 
                                                'datas': base64.encodestring(xml_string), 
                                                'datas_fname': file_name}, context=context)
        return attach_id

2. now yout file is attached to "record_obj" of "your.model"
Example: you need some additional conditions in xml form attached to sale order  then your.model = sale.order, and record_obj is the id of selected order... 
3. File is accesible for download to client via Attachment button (top of order view)

 

hope it helps...

1
Avatar
Buang
Eric
Penulis

Thank you for your reply. In my case I wanted to stay away from the ir.attachments model, but all i needed to do was read the file I created into a string variable. Then pass the string into the base64.encodestring(string_variable). Now I am able to download the file from the new model that I created. Thank you for your help

Avatar
Eric
Penulis Jawaban Terbai

First I added these two lines in the top of my python file

import io # used to output a file with exported data

import base64 # used to encode the contents of the exported file in binary form. this is used to download the file once its created

 

Fields Added in _columns { } on the python file:

"file_name": fields.char( "File Name" )

"file_binary": fields.binary( "Binary File" )

 

Code written in create()

I used the create method to save the new record with the binary data

def create(self, cr, uid, vals, context=None):

    # code goes in here...

 

Create the file:

Then I created the file like this in write mode

file_obj = open( "c:\Users\name_of_file.txt", "w")

file_obj.write( "some sample text..." )

file_obj.close()

 

Read file and encode with base64

# Re open the file_obj in read mode

file_obj = open( "c:\Users\name_of_file.txt", "r")

file_string = file_obj.read()

vals[ "file_binary" ] = base64.encodestring( file_string )   # Assuming this is in the create() and using the vals{ } to save the data

file_obj.close()

 

Create record with the filename and binary file data

new_id = super(current_model_used, self).create(cr, uid, vals, context)

 

XML form and tree views

Add the new fields on the form and tree views like this. This way when you download the file, then the file name will be used.

< field name="file_name" />

< field name="file_binary" filename="file_name" /> <!-- notice the filename attribute. Use this to set the file name with "file_name"  field-->

 

The end. Hope this helps!

 

1
Avatar
Buang
Avatar
Bole
Jawaban Terbai

Probably the best solution is to create it server side, base64 encode it, and attach it to relevant document... 
For simplicity here is example.. 
Let's say you want some xml report... 
1. you generate the xml_string then you pass it to a method like this:

def _attach_xml_file(self, cr, uid, ids, xml_string, context=None):

 import base64

        assert len(ids) == 1, "Only one ID accepted"
        model_obj= self.pool.get('your.model')          # the model of record you want file attached
        record_obj= model_obj.browse(cr, uid, ids[0]) # actual record to wich you attach file
        file_name = 'name_your_file_here.xml'
        attach_name = file_name
        attach_obj = self.pool.get('ir.attachment')
        context.update({'default_res_id': ids[0], 
                                 'default_res_model': 'your.model'})

        attach_id = attach_obj.create(cr, uid, {'name': attach_name, 
                                                'datas': base64.encodestring(xml_string), 
                                                'datas_fname': file_name}, context=context)
        return attach_id

1
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Upload un fichier téléchargeable par les visiteurs
upload file download
Avatar
0
Jun 23
3674
Download External File in Openerp 7.0
external file download
Avatar
3
Jun 20
9644
play and dowload mp3 from tree view
file download play
Avatar
0
Apr 16
6769
How can I make it so that when we click on a button on a website, a pdf file is automatically downloaded?
file download button_url PDF
Avatar
Avatar
Avatar
Avatar
3
Jan 25
2245
[10]Download a generated xlsx file by pressing a button Diselesaikan
file download xlsx odoo10
Avatar
Avatar
Avatar
Avatar
5
Apr 23
16895
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now