Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

One2Many Attachment Field Download Error

Subscriure's

Get notified when there's activity on this post

This question has been flagged
attachmentone2many
3 Respostes
12942 Vistes
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
Descartar
Avatar
Nuno Marques
Best Answer

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
Descartar
PT SIVI
Autor

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

PT SIVI
Autor

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
Autor

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
Autor

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
Autor Best Answer

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
Descartar
Avatar
Dan Mendes
Best Answer

Hi Fahreza,

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

Thanks!

0
Avatar
Descartar
PT SIVI
Autor

^ I edited my question. Thanks

Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Related Posts Respostes Vistes Activitat
Refreshing one2many after file upload
attachment one2many files
Avatar
0
de nov. 16
4289
this is my travel agency and we are a travel manager
attachment
Avatar
0
de nov. 25
3
how pass value to on2many field from parent form via context
one2many
Avatar
Avatar
1
de gen. 25
2802
View attachment within the browser
attachment
Avatar
Avatar
Avatar
5
de maig 23
16379
How to remove attachment?
attachment
Avatar
Avatar
Avatar
2
de des. 23
6675
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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