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?