Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    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 Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & 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
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Download pdf file on ir_attachment from other application

Naroči se

Get notified when there's activity on this post

This question has been flagged
pdfattachmentcontroller
1 Odgovori
9805 Prikazi
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
Opusti
Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

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
Opusti
rehan
Avtor

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!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
How to programmatically create PDF attachment in Odoo 10.0? Solved
pdf attachment
Avatar
Avatar
Avatar
11
apr. 23
30226
How to upload multiple file in website, and add it as an attachment to a new record? Solved
attachment controller website
Avatar
Avatar
3
jul. 21
22598
Adding an attachment from python Solved
pdf attachment odoo11
Avatar
1
apr. 20
7843
How to upload file in website, encode it in base64 and add it as an attachment to a new record in Odoo 9? Solved
javascript attachment controller 9.0
Avatar
Avatar
Avatar
Avatar
Avatar
5
feb. 24
50122
How to make `ir.attachment`, PDF read-only in Odoo V10
pdf attachment openerp odoo
Avatar
0
okt. 17
5572
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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