İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

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

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
serverclientfiledownloadoutput
5 Cevaplar
20306 Görünümler
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
Vazgeç
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
En İyi Yanıt

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
Vazgeç
Eric
Üretici

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
Üretici En İyi Yanıt

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
Vazgeç
Avatar
Bole
En İyi Yanıt

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
Vazgeç
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Upload un fichier téléchargeable par les visiteurs
upload file download
Avatar
0
Haz 23
3667
Download External File in Openerp 7.0
external file download
Avatar
3
Haz 20
9636
play and dowload mp3 from tree view
file download play
Avatar
0
Nis 16
6764
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
Oca 25
2231
[10]Download a generated xlsx file by pressing a button Çözüldü
file download xlsx odoo10
Avatar
Avatar
Avatar
Avatar
5
Nis 23
16872
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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