Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

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

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
pythoninvoicesAccountingodoo16features
6 Replies
12015 Rodiniai
Portretas
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
Portretas
Atmesti
Portretas
Bhavin Patel
Best Answer

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
Portretas
Atmesti
Portretas
Benri
Best Answer

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
Portretas
Atmesti
Portretas
Stéphane REVEL
Best Answer

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
Portretas
Atmesti
Portretas
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

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
Portretas
Atmesti
Portretas
Aditya Irri
Best Answer

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
Portretas
Atmesti
Portretas
EFFET B
Best Answer

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
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

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

Registracija
Related Posts Replies Rodiniai Veikla
How to solve error 'numpy' has no attribute 'float' in Python
python odoo16features
Portretas
Portretas
Portretas
3
vas. 23
6484
Cash & Bank accounts balance GL in Dashboard are not showing up in Odoo v16 online
dashboard Accounting odoo16features
Portretas
Portretas
Portretas
Portretas
3
lapkr. 24
4404
Difference between bank balance in the General Ledger and in the bank journal Solved
Accounting odoo16features Quickstart
Portretas
Portretas
Portretas
Portretas
4
geg. 25
14852
Partner Ledger customize
accounting python odoo16features
Portretas
Portretas
1
vas. 24
2860
[Repair Order] Accounting records on start and end repair
Accounting odoo16features repairorder
Portretas
Portretas
1
lapkr. 23
2310
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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