Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Odoo V13: Download zip-file created in python code

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
attachmentdownloadir.actionszipfile
9303 Vues
Avatar
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
Avatar
Ignorer
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
Auteur

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?

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
How can I download binary file from python function
attachment download
Avatar
0
mai 22
3871
How to solve os.getcwd() error while convert file to zip?
attachment download odoo10.0
Avatar
0
juin 19
4063
How to open attachment after creating it programmatically?
attachment open download
Avatar
0
mars 15
4717
Get public url of attachments saved in Odoo for downloading from external web application Résolu
attachment download v14 publicurl
Avatar
Avatar
1
août 23
8962
Create a public attachment URL with database information
attachment url download publicurl
Avatar
0
août 24
4320
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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