Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Odoo V13: Download zip-file created in python code

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
attachmentdownloadir.actionszipfile
9284 Widoki
Awatar
Ferdinand Saint Julien

Hey,


In a function of my TansientModel, i am getting the attribute store_fname from a couple of attachments from ir.attachments. With this, i use shutil.copy to copy the files from the related data/filestore/ folder to a new created folder in tmp/. Afterwards i create a zipfile from all the copied attachments and delete the recently created folder + copied attachments. This works fine for now. However, i want to make the created zipfile available for download, if possible without calling any other function, just in addition to my existing code. Do i need a field.Binary for this, or is there some option to send some kind of ir.actions.act_url to download a specific file on my server?


This is how i execute my python function from a button in my views.xml:

    <record id="bmd.export_all" model="ir.actions.server">
        <field name="name">BMD Export Complete Data</field>
        <field name="model_id" ref="model_bmd_bmd"/>
        <field name="type">ir.actions.server</field>
        <field name="state">code</field>
        <field name="code">model.export_all()</field>
    </record>


I could try to add the created zipfile to ir.attachments as a new entry, create a field.Binary (i think i have to do some encoding/decoding there aswell?) or, the for me best option: i could download the file directly from a specific location of my server.

However, when i add this to the end of my function, it doesnt work, no matter what kind of url i want to call:

        return {
            'type': 'ir.actions.act_url',
            'url': 'https://odoo.com',
            #'url': zipfile_path,
            'target': 'self',
        }


2
Awatar
Odrzuć
Yenthe Van Ginneken (Mainframe Monkey)

Use something such as a Python controller in which you return the ZIP:

http.send_file(zip_folder_location + filename, filename=filename, as_attachment=True)

Ferdinand Saint Julien
Autor

Hey yenthe, thanks for your answer! I imported the http controller like this:

from odoo import http

In my function i tried both:

zipfile_path = ''/home/odoo/tmp/bmd_export_09_27112020.zip" # this is created by my shutil.make_archive function, so it should represent the full path on the server

zipfile_path_short = os.sep + "tmp" + os.sep + "bmd_export_09_27112020.zip"

zipfile_name = "bmd_export_09_27112020.zip"

http.send_file(zipfile_path, filename=zipfile_name, as_attachment=True)

http.send_file(zipfile_path_short, filename=zipfile_name, as_attachment=True)

Executing this does not result in an error, but also does not begin my desired download. The reason for zipfile_path_short is because os.getcwd() tells me i am already in the folder /home/odoo. The zipfile name is generated by code, i just wrote it like this for simplicity.

fel ALb

I was considering to program something similar. Could you please be so kind to share your code?

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
How can I download binary file from python function
attachment download
Awatar
0
maj 22
3868
How to solve os.getcwd() error while convert file to zip?
attachment download odoo10.0
Awatar
0
cze 19
4055
How to open attachment after creating it programmatically?
attachment open download
Awatar
0
mar 15
4699
Get public url of attachments saved in Odoo for downloading from external web application Rozwiązane
attachment download v14 publicurl
Awatar
Awatar
1
sie 23
8951
Create a public attachment URL with database information
attachment url download publicurl
Awatar
0
sie 24
4318
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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