Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita 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
  • Proyectos
  • 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

Download pdf file on ir_attachment from other application

Suscribirse

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

Se marcó esta pregunta
pdfattachmentcontroller
1 Responder
9837 Vistas
Avatar
rehan

hello guys, i want to know is there a way to download attachment in record model from other applications outside odoo? im aware i have to use controller and im familiar on it, but i didn't know how to download attachments automatically from the controller thanks

0
Avatar
Descartar
Avatar
Niyas Raphy (Walnut Software Solutions)
Mejor respuesta

Hi,

If the other application is running on Python, you can download the report from the other application using the odoorpc package. See the documentation here: https://pythonhosted.org/OdooRPC/tuto_report.html


Read:

Download reports

Another nice feature is the reports generation with the report property. The list method allows you to list all reports available on your Odoo server (classified by models), while the download method will retrieve a report as a file (in PDF, HTML... depending of the report).

To list available reports:

>>> odoo.report.list()
{u'account.invoice': [{u'name': u'Duplicates', u'report_type': u'qweb-pdf', u'report_name': u'account.account_invoice_report_duplicate_main'}, {u'name': u'Invoices', u'report_type': u'qweb-pdf', u'report_name': u'account.report_invoice'}], u'res.partner': [{u'name': u'Aged Partner Balance', u'report_type': u'qweb-pdf', u'report_name': u'account.report_agedpartnerbalance'}, {u'name': u'Due Payments', u'report_type': u'qweb-pdf', u'report_name': u'account.report_overdue'}], ...}

To download a report:

>>> report = odoo.report.download('account.report_invoice', [1])

The method will return a file-like object, you will have to read its content in order to save it on your file-system:

>>> with open('invoice.pdf', 'w') as report_file:
...     report_file.write(report.read())
...


Thanks

0
Avatar
Descartar
rehan
Autor

i've found the answer

import logging

try:

from BytesIO import BytesIO

except ImportError:

from io import BytesIO

import zipfile

from datetime import datetime

from odoo import http

from odoo.http import request

from odoo.http import content_disposition

import ast

import json

_logger = logging.getLogger(__name__)

class Binary(http.Controller):

@http.route('/web/aflowz_attachments/download_all_document/<model_name>/<int:res_id>', type='http', auth="public")

def download_document(self, model_name=None, res_id=0, **kw):

attachment_ids = request.env['ir.attachment'].search([('res_model', '=', model_name), ('res_id', '=', res_id)])

file_dict = {}

if attachment_ids:

for attachment_id in attachment_ids:

file_store = attachment_id.store_fname

if file_store:

file_name = attachment_id.name

file_path = attachment_id._full_path(file_store)

file_dict["%s:%s" % (file_store, file_name)] = dict(path=file_path, name=file_name)

zip_filename = datetime.now()

zip_filename = "%s.zip" % zip_filename

bitIO = BytesIO()

zip_file = zipfile.ZipFile(bitIO, "w", zipfile.ZIP_DEFLATED)

for file_info in file_dict.values():

zip_file.write(file_info["path"], file_info["name"])

zip_file.close()

return request.make_response(bitIO.getvalue(),

headers=[('Content-Type', 'application/x-zip-compressed'),

('Content-Disposition', content_disposition(zip_filename))])

else:

return request.make_response(json.dumps({

"error": "Attachments not found",

"message": "There are no attachment",

"code": 404}),

headers={'Content-Type': 'application/json'}

)

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

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

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
How to programmatically create PDF attachment in Odoo 10.0? Resuelto
pdf attachment
Avatar
Avatar
Avatar
11
abr 23
30309
How to upload multiple file in website, and add it as an attachment to a new record? Resuelto
attachment controller website
Avatar
Avatar
3
jul 21
22668
Adding an attachment from python Resuelto
pdf attachment odoo11
Avatar
1
abr 20
7895
How to upload file in website, encode it in base64 and add it as an attachment to a new record in Odoo 9? Resuelto
javascript attachment controller 9.0
Avatar
Avatar
Avatar
Avatar
Avatar
5
feb 24
50246
How to make `ir.attachment`, PDF read-only in Odoo V10
pdf attachment openerp odoo
Avatar
0
oct 17
5624
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • 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 estar 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