콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
1682 화면

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



아바타
취소
베스트 답변

Hey, sounds like you're deep in the weeds with that invoice triger! I've been there. First off, you're on the right track with getting your modle recognized in odoo, so nice one. But if it's not triggering, the method you've linked to, `_post_validate`, might be where the snag is. It’s supposed to trigger when an invoice is validated, but odoo’s workflow or tweaks can really mess things up sometimes.


Check if the invoice actually hits the "posted" state. If there's an error earlier in the chain, `_post_validate` might not fire up like you expected. Also, make sure your module loads correctly; odoo’s logging could give you a hint if it’s reaching your method. And pdb's your friend - seriously, pop a breakpoint to see if it hits.


Still stuck? Try running the function outside odoo's lifecycle. A simple button action to call your PDF save function might help pinpoint the issue, confirming if the SMB part is cool. Make sure your share isn’t blocked by network or permission hiccups. Hope this helps to untangle stuff!

아바타
취소
관련 게시물 답글 화면 활동
2
4월 24
2237
2
4월 24
2319
1
9월 25
396
2
6월 25
1733
3
2월 25
3443