Hi, we already have a small modul and script to create/copy PDF-File after an Invoice is confirmed.
But we are unable to find the right place to get this triggered.
We made a Folder in addons, created the files and also the script. Modul is shown in odoo apps and enabled. But it looks like it never triggers.
Maybe someone can give a hint?
Thank you!
import os
from io import BytesIO
import smbprotocol.connection
import logging
from odoo import models, api
_logger = logging.getLogger(__name__)
SMB_HOST = 'IP-of-server' # IP-Address
SMB_PORT = 445 # Port
SMB_USERNAME = 'user' # SMB-Benutzername
SMB_PASSWORD = 'somePass' # SMB-Passwort
SMB_SHARE = 'aShare' # share
def save_pdf_invoice(pdf_content, file_name):
_logger.info(f"Saving PDF invoice {file_name} to SMB server")
try:
with smbprotocol.connection.Connection(username=SMB_USERNAME, password=SMB_PASSWORD,
hostname=SMB_HOST, port=SMB_PORT) as connection:
with connection.connect_share(SMB_SHARE) as share:
with share.create_file(file_name) as file:
file.write(pdf_content)
except Exception as e:
_logger.error(f"Error saving PDF invoice {file_name}: {e}")
class AccountMove(models.Model):
_inherit = 'account.move'
@api.model
def _post_validate(self):
res = super(AccountMove, self)._post_validate()
for move in self:
if move.type == 'out_invoice' and move.state == 'posted':
pdf_content = move._render_pdf() # Annahme: Hier wird die PDF-Rechnung generiert
file_name = f'invoice_{move.id}.pdf'
save_pdf_invoice(pdf_content, file_name)
import pdb; pdb.set_trace() # Debugger
return res