Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

One2Many Attachment Field Download Error

Odebírat

Get notified when there's activity on this post

This question has been flagged
attachmentone2many
3 Odpovědi
12947 Zobrazení
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
Zrušit
Avatar
Nuno Marques
Nejlepší odpověď

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
Zrušit
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 Nejlepší odpověď

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
Zrušit
Avatar
Dan Mendes
Nejlepší odpověď

Hi Fahreza,

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

Thanks!

0
Avatar
Zrušit
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!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Refreshing one2many after file upload
attachment one2many files
Avatar
0
lis 16
4290
this is my travel agency and we are a travel manager
attachment
Avatar
0
lis 25
3
how pass value to on2many field from parent form via context
one2many
Avatar
Avatar
1
led 25
2808
View attachment within the browser
attachment
Avatar
Avatar
Avatar
5
kvě 23
16383
How to remove attachment?
attachment
Avatar
Avatar
Avatar
2
pro 23
6676
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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