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
    • Diskusi
    • 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

One2Many Attachment Field Download Error

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
attachmentone2many
3 Replies
12946 Tampilan
Avatar
PT SIVI

I need to create some object which able to have many attachments.

image description

As the figure shows, The object has two medical attachment entitled first and second. The files are uploaded too which names are tes.csv and tes2.csv

When I check them to Knowledge->Documents->Documents Menu, files were uploaded successfully as you can see here. image description

But, the problem is, when I click to download the attachment files, for example tes.csv file from one2many tree, the browser will get .bin files not .csv files.

This makes me frustrated, because of when I tried to download them from Knowledge->Documents->Documents Menu, the browser gets .csv files successfully.

You can see the difference of two methods when I'm hovering my mouse to these two form view.

1. My Module->Form View->One2Many Field
data:application/octet-stream

image description

2. Knowledge->Documents->Documents Menu->Form View->File Content Field
javascript:void(0)

image description

When I trace them, the First Method won't call ir_attachment._file_read method. And the second Method will call ir_attachment._file_read method for sure.

Please help me, so my new one2many field module attachment can download the files with their extension not just a BIN.FILE.

Thank you

Edited :

This one is .py

_name = 'hr.medreq'
_columns = {
    'name':fields.char('Name'),
    'attach_ids':fields.one2many('ir.attachment', 'medreq_id', 'Medical Attachment'),

    'attachment_ids': fields.many2many('ir.attachment', 'class_ir_attachments_rel', 'class_id', 'attachment_id', 'Attachments'),
   }

This one is .xml

<tree string="Medical Attachment">
    <field name="name"/>
    <field name="type" invisible="1"/>
    <field name="store_fname" invisible="1"/>
    <field name="datas" filename="datas_fname"/>
    <field name="datas_fname" invisible="1" modifiers="{'invisible': true}"/>
</tree>

Thanks!

2
Avatar
Buang
Avatar
Nuno Marques
Jawaban Terbai

Hi Fahreza,

I'm in Dan's team. I managed to fix this bug by editing /addons/web/controllers/main.py file. Search the saveas_ajax function. Arround the line nr 1307 you will find this:

    if filename_field:
        fields.append(filename_field)
    if data:
        res = { field: data }
    elif id:
        res = Model.read([int(id)], fields, context)[0]

edit it to this:

    if filename_field:
        fields.append(filename_field)
    if data:
        res = { field: data }
        # FIX
        if filename_field:
            filename_name = Model.read([int(id)], [filename_field], context)
            res[filename_field] = filename_name and filename_name[0] and filename_name[0][filename_field] or ''
    elif id:
        res = Model.read([int(id)], fields, context)[0]

The problem was in that case "res" didn't have filename_field filled, so a few lines later it names the file with the model name and attach id (like ir_attachment_1) but the data is fine. If you just rename the file to the correct file extension it works fine. With that fix, it fills the filename_field so it works fine.

Hope it works for you too.

4
Avatar
Buang
PT SIVI
Penulis

Great! It seems possible. I will try it and contact you soon. Thanks a lot, Nuno!

PT SIVI
Penulis

Great! I just tried it on my local server and it works 50% now. I mean, there are two methods to open this attachment right? The first method is open the related object first in one2many fields, and after window pops out, I successfully open the attachment with right extensions by clicking on the 'File Content' field. But the second method is directly click the link on one2many field columns, in this case 'datas' field. The first method works 100% but the second method still produces 'data:application/octet-stream:64'. See hee http://goo.gl/mZ9RUQ . Thank you very much by the way!

PT SIVI
Penulis

you can easily understand what I mean if you change the one2many field tree view in .xml file into this <tree string="Medical Attachment" editable="bottom">

Thank you

phu nguyen

hi Fahreza, i'm following your post. I try it in my custom module. i got problem "when you click on file to dowload. It dosenot reach the "saveas_ajax" function." Could you help me this problem, plz?

PT SIVI
Penulis

Yes, actually I'm still having the same problem and I can't get it right. That's why I haven't closed this question yet.

Avatar
PT SIVI
Penulis Jawaban Terbai

This one is .py

_name = 'hr.medreq'
_columns = {
    'name':fields.char('Name'),
    'attach_ids':fields.one2many('ir.attachment', 'medreq_id', 'Medical Attachment'),

    'attachment_ids': fields.many2many('ir.attachment', 'class_ir_attachments_rel', 'class_id', 'attachment_id', 'Attachments'),
   }

This one is .xml

<tree string="Medical Attachment">
    <field name="name"/>
    <field name="type" invisible="1"/>
    <field name="store_fname" invisible="1"/>
    <field name="datas" filename="datas_fname"/>
    <field name="datas_fname" invisible="1" modifiers="{'invisible': true}"/>
</tree>

Thanks!

0
Avatar
Buang
Avatar
Dan Mendes
Jawaban Terbai

Hi Fahreza,

Can you show me how you did that one2many field in the _columns, and the corresponding view?

Thanks!

0
Avatar
Buang
PT SIVI
Penulis

^ I edited my question. Thanks

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
Refreshing one2many after file upload
attachment one2many files
Avatar
0
Nov 16
4290
this is my travel agency and we are a travel manager
attachment
Avatar
0
Nov 25
3
how pass value to on2many field from parent form via context
one2many
Avatar
Avatar
1
Jan 25
2806
View attachment within the browser
attachment
Avatar
Avatar
Avatar
5
Mei 23
16383
How to remove attachment?
attachment
Avatar
Avatar
Avatar
2
Des 23
6676
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