How to create a report that is in XML format for compliance with electronic invoice laws

Machine-readable invoices are more and more requested by companies, and it is already a hard requirement for several years when contracting a public institution in Germany, e.g. a University. In other words, it is not possible to sell goods or services to a German public institution if you can’t send an invoice in a specific XML format, called “XRechnung”. They don’t even want to see a PDF anymore. The XML file can be send to them by email attachment.

Currently, Tryton only supports Relatorio-based invoices, which according to my understanding creates office documents, not XML-formatted text files.

If I want to implement an invoice that is in XML-format, how would the general approach be like?

You would usually go with raw Genshi templating (the xml manipulation library that relatorio uses under the hood).

Basically:

from genshi.template import MarkupTemplate
template = MarkupTemplate("insert xml template here")
result = template.generate(**context).render('xml')

You could then create a model to store the templates, and a wizard to trigger the generation.

We have UN/CEFACT edocument.I guess check what xml standard Xreichnung is using.

In Romania we have for example CIUS-RO which can use both UN/CEFACT and UBL but the UN/CEFACT was deprecated. I guess the CIUS-DE are rules on top of the edocument.

That’s amazing! XRechnung is based on the european standard UN/CEFACT, and extends it a bit to follow German law, e.g. some fields that are optional in UN/CEFACT are obligatory in XRechnung.

I activated the edocument_uncefact module but couldn’t figure out how to create an XML file. On the invoice tab I still can only print to ODT. The search box doesn’t show anything for cefact. Can someone provide me a hint how to get to the XML file from here?

You can create a custom module that extends _execute method of the invoice report.
The following code is incomplete, but it might give you an idea:

class InvoiceReport(Report):
    __name__ = 'account.invoice'

    @classmethod
    def _execute(cls, records, header, data, action):
        ...code to generate payload...
        return 'xml', payload

The module was designed initially to work with modules like account_fr_chorus for full automation.
Now it should be possible to extend the module to provide a way to directly retrieve the generated XML.

@dotbit, @ced, that sounds great, I’ll start making a German XRechnung module then based on edocument_uncefact .

I still have to figure out a couple things though, for example some fields might be obligatory for XRechnung that are optional on the default invoice form (field BT-10 comes to my mind).

But I assume there is a way to modify the backend form and form validation from the existing module API.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.