Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Download pdf file on ir_attachment from other application

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
pdfattachmentcontroller
1 Răspunde
9811 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Niyas Raphy (Walnut Software Solutions)
Cel mai bun răspuns

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
Imagine profil
Abandonează
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'}

)

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to programmatically create PDF attachment in Odoo 10.0? Rezolvat
pdf attachment
Imagine profil
Imagine profil
Imagine profil
11
apr. 23
30245
How to upload multiple file in website, and add it as an attachment to a new record? Rezolvat
attachment controller website
Imagine profil
Imagine profil
3
iul. 21
22613
Adding an attachment from python Rezolvat
pdf attachment odoo11
Imagine profil
1
apr. 20
7855
How to upload file in website, encode it in base64 and add it as an attachment to a new record in Odoo 9? Rezolvat
javascript attachment controller 9.0
Imagine profil
Imagine profil
Imagine profil
Imagine profil
Imagine profil
5
feb. 24
50139
How to make `ir.attachment`, PDF read-only in Odoo V10
pdf attachment openerp odoo
Imagine profil
0
oct. 17
5586
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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