Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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č

Copy of PDF invoice on external storage

Naroči se

Get notified when there's activity on this post

This question has been flagged
pdfinvoicesodoo v17
2 Odgovori
1625 Prikazi
Avatar
Xavier

Hi,

I try to automate the creation of reccuring invoices. I manage to create the invoice, send it by mail using my template with the pdf attached. 
Now I try to copy the Pdf file on a nextcloud instance. The connection is Ok, I managed to create the folders but my issue is : when I generate the pdf file, the corresponding invoice is deleted. 
Here is my code : 


from odoo import models, fields, api
import base64
import requests
import locale
import logging
from urllib.parse import quote
_logger = logging.getLogger(__name__)

class AccountMove(models.Model):
    _inherit = 'account.move'

    @api.model
    def envoyer_quittance_et_sauvegarder(self):
      # ID du modèle de facture à copier
        facture_modele_id = 16
        facture_modele = self.env['account.move'].browse(facture_modele_id)

        # Dupliquer et valider
        nouvelle_facture = facture_modele.copy()
        nouvelle_facture.action_post()
        # Envoi par mail
        template = self.env.ref('quittance.modele_email')
template.send_mail(nouvelle_facture.id, force_send=True)

""" Code about construction of the Url and Nextcloud authentication """

# Générer le PDF
        report = self.env['ir.actions.report']._get_report_from_name('account.report_invoice')
        pdf_content, _ = report._render_qweb_pdf(nouvelle_facture.id)
       
        # Envoyer le PDF sur Nextcloud
        response = requests.put(
            url_pdf,
            data=pdf_content,
            auth=(username, password),
            headers={'Content-Type': 'application/pdf'}
        )

        if response.status_code not in (200, 201, 204):
            _logger.warning(f" Erreur envoi PDF : {response.status_code} - {response.text}")
        else:
            _logger.info(f" Quittance enregistrée : {pdf_filename} dans {url_quittances}")


Is there another way for creating a pdf file?

0
Avatar
Opusti
Avatar
D Enterprise
Best Answer

try:

    report = self.env['ir.actions.report'].search([('model', '=', 'account.move')], limit=1)

    if not report:

        _logger.error("Aucun rapport trouvé pour le modèle account.move")

        return


    pdf_content, _ = self.env['ir.actions.report']._render_qweb_pdf(report.report_name, [nouvelle_facture.id}")


    # Upload to Nextcloud

    response = requests.put(

        url_pdf,

        data=pdf_content,

        auth=(username, password),

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

    )


    if response.status_code not in (200, 201, 204):

        _logger.warning(f"Erreur envoi PDF : {response.status_code} - {response.text}")

    else:

        _logger.info(f"Quittance enregistrée : {pdf_filename} dans {url_quittances}")


except Exception as e:

    _logger.error(f"Erreur lors de la génération ou l'envoi du PDF : {e}")


0
Avatar
Opusti
Avatar
Xavier
Avtor Best Answer

Is there only a way to send a pdf file to any storage?

Edit : Yes! 

Replace the code after # Générer le PDF by : 

# Générer le PDF
        try:
            report = self.env['ir.actions.report'].search([('model', '=', 'account.move')], limit=1)
            if not report:
                _logger.error("Aucun rapport trouvé pour le modèle account.move")
                return

            pdf_content, _ = self.env['ir.actions.report']._render_qweb_pdf(
                report.report_name, nouvelle_facture.ids
            )
            _logger.info(f"PDF généré pour la facture ID {nouvelle_facture.id}")
        except Exception as e:
            _logger.error(f"Erreur lors de la génération du PDF pour facture ID {nouvelle_facture.id} : {e}")
            return
0
Avatar
Opusti
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
Migrating to odoo 13 lost all invoice's pdf Solved
pdf invoices Odoo13.0
Avatar
Avatar
Avatar
3
okt. 21
4306
Is it possible to add the word "PAID" anywhere on the paid invoices when I print them as PDF?
pdf templates invoices
Avatar
Avatar
2
nov. 16
5133
add borders in the pdf generated
pdf invoices purchase_order
Avatar
Avatar
1
mar. 15
4948
Download pdf in a Folder
pdf invoices xmlrpc odoo16
Avatar
0
avg. 24
1855
Invoices or Bills Related to Payment
pdf invoices payments bills
Avatar
0
jun. 23
2359
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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