Sponsoring UBL Invoice-2

As invoice is “printed” when invoice is posted, report invoice could be added as attachment in the ubl peppol bis 3 file. Here’s an example with a report saved as pdf file (still needs improvements).

Adding a property to convert report in base64 in account_invoice/invoice.py

class Invoice(metaclass=PoolMeta):
    __name__ = 'account.invoice'

    @property
    def base64_report(self):
        if self.invoice_report_cache:
            return (base64.b64encode(self.invoice_report_cache)).decode('ascii')

In edocument_ubl/template/2/Invoice.xml:


<py:if test=“specification == ‘peppol-bis-3’ and this.invoice.base64_report”>
<cac:AdditionalDocumentReference>
<cbc:ID>${this.invoice.number}</cbc:ID>
<cbc:DocumentType>${this.invoice.invoice_report_format}</cbc:DocumentType>
<cac:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode=“application/pdf” filename=“invoice.pdf”>${this.invoice.base64_report}</cbc:EmbeddedDocumentBinaryObject>
</cac:Attachment>
</cac:AdditionalDocumentReference>
</py:if>

For me it is a matter to use the European tax identifier instead of the local tax identifier on the invoice.
Now I do not know how I could enforce this except by removed national identifier from the tax identifiers (but it is not backward compatible).

I seems it should be at least one of <cbc:BuyerReference> or <cac:OrderReference> / <cbc:ID>.
I guess for <cbc:BuyerReference> we could fill with the Invoice.reference if filled.
And for <cac:OrderReference> / <cbc:ID> it should be the origin but the problem is that Tryton may have multiple origins.

The last revision should fix all the comments and include the invoice as additional document.

2 Likes

Thanks Cédric !

One last error when testing peppol-bis-3 file:

[UBL-CR-666] A UBL invoice shall not include an AdditionalDocumentReference simultaneously referring an Invoice Object Identifier and an Attachment

So <cbc:DocumentTypeCode>130</cbc:DocumentTypeCode> is not needed when there is an attachment.

I really do not understand the rule. One more rule that does not make sense for me.

Indeed. Don’t understand too :slight_smile:

As far as I understand despite the documentation for <cbc:DocumentTypeCode> saying that the default value is 130 (which was the reason I set it to this value).
This code 130 seems to indicate that the document is not attached but just providing via the <cbc:ID>.

1 Like