Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Información
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Odoo V13: Download zip-file created in python code

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
attachmentdownloadir.actionszipfile
9301 Vistas
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
Descartar
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?

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
How can I download binary file from python function
attachment download
Avatar
0
may 22
3869
How to solve os.getcwd() error while convert file to zip?
attachment download odoo10.0
Avatar
0
jun 19
4059
How to open attachment after creating it programmatically?
attachment open download
Avatar
0
mar 15
4712
Get public url of attachments saved in Odoo for downloading from external web application Resuelto
attachment download v14 publicurl
Avatar
Avatar
1
ago 23
8957
Create a public attachment URL with database information
attachment url download publicurl
Avatar
0
ago 24
4320
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

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