İç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 upload multiple file in website, and add it as an attachment to a new record?

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
attachmentcontrollerwebsite
3 Cevaplar
22664 Görünümler
Avatar
Luis Angel Bautista Molina

Hi there,

Has anybody tried to upload multiple file from the Odoo website, and then call a controller with method post to create a record and save the attachment?

 The input type file in my template view

<div class="form-group row form-field o_website_form_required_custom">
                                <div class="col-md-4 col-sm-3 text-right">
                                    <label class="control-label" for="project_managment"></label>
                                </div>
                                <div class="col-md-6 col-sm-7">
                                    <input type="file" name="attachment" class="file" multiple="true" data-show-upload="true" data-show-caption="true" lass="file" data-show-preview="true"/>
                                </div>
                            </div>

in my controller

@http.route(['/upload/file/<model("model.custom"):object>/<model("model.custom2"):object2>/confirm'],type='http',auth='user',website=True)
    def convocatoria_proyecto_info(self, convocatoria, proyecto, **kwargs):
        values = {}
        if kwargs.get('attachment',False):
            Attachments = request.env['ir.attachment']
            name = kwargs.get('attachment',False).filename     
            file = kwargs.get('attachment',False)          
            project_id = proyecto.id
            attachment = file.read()
            attachment_id = Attachments.sudo().create({
                'name':name,
                'datas_fname': name,
                'res_name': name,
                'type': 'binary',  
                'res_model': 'model.model',
                'res_id': project_id,
                'datas': base64.b64encode(attachment),
            })
            values = {'attachment' : attachment_id}
            return request.render("modulename.template_to_render", value)

Could anybody tell me in which format I should pass the multiple value, how to get & pass attach it as an attachment on the just create record?

Regards

1
Avatar
Vazgeç
Sehrish

Try this one: http://learnopenerp.blogspot.com/2019/01/add-attachement-file-from-odoo-website.html

Samo Arko

@Sehrish at least read the title! It says MULTIPLE files!!!

I'm having the same problem with multiple files. The problem is that you have only one file in your post variable. If you could get the files in a list you just call the create method in "for attachment in post.get(attachment)"

Avatar
Samo Arko
En İyi Yanıt

For uploading multiple files you need to have set the proper enctype in your form tag and have the option for multiple files in your input tag.

<form method="post" class="s_website_form" action="/new-ticket" enctype="multipart/form-data">
    <p><strong>Attachment </strong><input type="file" name="task_attachment" multiple="true"/></p>
</form>

In your controller you need to use request.httprequest.files.getlist() to get the files and just store them with a for loop.

if request.httprequest.method == 'POST':
        # ... # code that creates and fills a dictonary with validated data # ... new_task = request.env['project.task'].sudo().create(create_dict) if 'task_attachment' in request.params: attached_files = request.httprequest.files.getlist('task_attachment') for attachment in attached_files: attached_file = attachment.read() request.env['ir.attachment'].sudo().create({ 'name': attachment.filename, 'res_model': 'project.task', 'res_id': new_task.id, 'type': 'binary', 'datas_fname': attachment.filename, 'datas': attached_file.encode('base64'), })  

It's sad that something so basic for websites isn't better documented. I needed to analyze the whole http.py and go trough the wergzeug documentation to find the methods to get it working. 

7
Avatar
Vazgeç
COULIBALY Zana Dramane

It works fine for me. Thank you very much!

Samo Arko

Nice... no problem.

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
Add Attachement From website. Çözüldü
attachment website
Avatar
Avatar
2
Şub 24
26383
How to get the current user id from an Odoo Website Web Controller ? Çözüldü
controller website odoo
Avatar
Avatar
2
Ara 21
25209
Odoo bind custom website layout to model
controller website 13
Avatar
0
Oca 21
3014
Download pdf file on ir_attachment from other application Çözüldü
pdf attachment controller
Avatar
Avatar
1
Ağu 20
9837
inherit the home controller odoo 13
controller website Odoo13.0
Avatar
2
Tem 20
5011
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