Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

How to download an invoice file in pdf format in Odoo 16 using Python?

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
pythoninvoicesAccountingodoo16features
6 Antwoorden
12005 Weergaven
Avatar
Dmitry Chernetskyi

In Odoo 16, in the Accounting module in Invoices, I can download the invoice file after clicking the SEND & PRINT button. I need to download this file and save it in the directory I want through my Python script. How do I implement this?

0
Avatar
Annuleer
Avatar
Bhavin Patel
Beste antwoord

To download an invoice file in PDF format in Odoo 16 using Python, you can use the Odoo XML-RPC API to connect to your Odoo instance and download the PDF file.

Here is an example Python code that you can use to download an invoice file in PDF format:

python
import xmlrpc.client # Connect to the Odoo instance url = 'http://localhost:8069' db = 'my_database' username = 'my_username' password = 'my_password' common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) # Create a new XML-RPC client object models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url)) # Find the invoice you want to download invoice_ids = models.execute_kw(db, uid, password, 'account.move', 'search', [[['state', '=', 'posted'], ['type', '=', 'out_invoice']]]) # Download the PDF file for the first invoice in the list invoice = models.execute_kw(db, uid, password, 'account.move', 'read', [invoice_ids[0]], {'fields': ['name', 'invoice_date', 'amount_total']}) pdf_file = models.execute_kw(db, uid, password, 'account.move', 'invoice_print', [invoice_ids[0], 'pdf']) # Save the PDF file to disk filename = '{}_{}.pdf'.format(invoice['name'], invoice['invoice_date']) with open(filename, 'wb') as f: f.write(pdf_file)

In this example, you first connect to your Odoo instance using the XML-RPC API, then you search for the invoices you want to download. Once you find the invoice you want, you call the invoice_print method to download the PDF file.

Finally, you save the PDF file to disk using the open function in binary mode. You can customize the filename and directory where the PDF file is saved by modifying the filename variable.

Note that this is just an example code, and you will need to adapt it to your specific needs and customize it to handle errors and exceptions.

1
Avatar
Annuleer
Avatar
Benri
Beste antwoord

import xmlrpc.client


# Odoo connection details

url = "http://your-odoo-instance.com"

db = "your-database-name"

username = "your-username"

password = "your-password"


# Authenticate

common = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/common")

uid = common.authenticate(db, username, password, {})

models = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/object")


# Search for the invoice

invoice_ref = "INV/2025/0001"

invoice_ids = models.execute_kw(

    db, uid, password,

    'account.move', 'search',

    [[['name', '=', invoice_ref]]]

)


if invoice_ids:

    invoice_id = invoice_ids[0]


    # Generate the PDF

    pdf_data = models.execute_kw(

        db, uid, password,

        'report.account.report_invoice', 'render_qweb_pdf',

        [invoice_id]

    )


    pdf_content, filename = pdf_data


    # Save the PDF

    output_path = f"/path/to/save/{filename}"

    with open(output_path, "wb") as pdf_file:

        pdf_file.write(pdf_content)

    print(f"Invoice PDF saved to {output_path}")

else:

    print("Invoice not found!")


0
Avatar
Annuleer
Avatar
Stéphane REVEL
Beste antwoord

in v17, the call :

pdf_file_url = models.execute_kw(db, uid, password, 'account.move.send', 'action_send_and_print', [4, [invoice_id]])

returns :

<Fault 2: 'Record does not exist or has been deleted.\n(Record: account.move.send(4,), User: 6)'>

What do ye have to do for the PDF to be generated ?

0
Avatar
Annuleer
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Beste antwoord

Hi,

There is already a default function to print the invoice from the action menu. Please check it whether it meets your need
open any invoice -> Action button -> print -> invoices


Hope it helps

0
Avatar
Annuleer
Avatar
Aditya Irri
Beste antwoord

Try this code to download an invoice file in PDF in Odoo 17 using Python.

# Import necessary modules from Flask framework and other libraries
from flask import Flask, request, jsonify, send_file
import xmlrpc.client
import requests

# Set up credentials and URL for Odoo instance
url = 'https://your_odoo_instance_url.com'
db = 'your_odoo_database'
username = 'your_odoo_username'
password = 'your_odoo_password'

# Authenticate and get session ID from Odoo
session_url = f'{url}web/session/authenticate'
data = {
    'jsonrpc': '2.0',
    'method': 'call',
    'params': {
        "service": "common",
        "method": "login",
        'db': db,
        'login': username,
        'password': password,
    }
}
session_response = requests.post(session_url, json=data)
session_data = session_response.json()
session_id = session_response.cookies['session_id']

# Set up XML-RPC connection to Odoo
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

# Specify the ID of the invoice to retrieve
invoice_id = 21566

# Retrieve information about the specified invoice from Odoo
invoice = models.execute_kw(db, uid, password, 'account.move', 'read', [invoice_id], {'fields': ['name']})

# Trigger the action to send and print the invoice, and retrieve the URL of the generated PDF
pdf_file_url = models.execute_kw(db, uid, password, 'account.move.send', 'action_send_and_print', [4, [invoice_id]])

# Set up headers with the session ID for downloading the PDF
headers = {'Cookie': f'session_id={session_id}'}
download_url = f'{url}{pdf_file_url["url"]}'

# Download the PDF content of the invoice
response = requests.get(download_url, headers=headers)
pdf_content = response.content

# Specify the filename for the downloaded PDF based on the invoice name
filename = '{}.pdf'.format(invoice[0]['name'])

# Save the PDF content to a file
with open(filename, 'wb') as f:
    f.write(pdf_content)

Let me know if this works. It worked for me.

0
Avatar
Annuleer
Avatar
EFFET B
Beste antwoord

Hello,

I tried this script in odoo 17, but I have this error :

AttributeError: type object 'account.move' has no attribute 'invoice_print'

Do I need something else to make it work ?

Best regards

0
Avatar
Annuleer
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
How to solve error 'numpy' has no attribute 'float' in Python
python odoo16features
Avatar
Avatar
Avatar
3
feb. 23
6483
Cash & Bank accounts balance GL in Dashboard are not showing up in Odoo v16 online
dashboard Accounting odoo16features
Avatar
Avatar
Avatar
Avatar
3
nov. 24
4401
Difference between bank balance in the General Ledger and in the bank journal Opgelost
Accounting odoo16features Quickstart
Avatar
Avatar
Avatar
Avatar
4
mei 25
14842
Partner Ledger customize
accounting python odoo16features
Avatar
Avatar
1
feb. 24
2856
[Repair Order] Accounting records on start and end repair
Accounting odoo16features repairorder
Avatar
Avatar
1
nov. 23
2309
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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