Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Invoice Factur-X, l10n_fr_account_invoice_facturx

by
EMC2, Cedric DEBARD
- 09/02/2024 11:34:35
Hello all,

I've got questions about the factur-x generation xml file attached to the pdf. I'm working on the Odoo 12 version.

When i print my PDF report or use the "Send to Chorus" button, at the begining of the process a factur-x xml flux in well generated and is valid against the xsd schema. But at the the end of the process the _post_pdf method base IrActionsReport class (server\odoo\addons\account_facturx\models\ir_actions_report.py) is called. 

==== CODE =======
@api.multi
    def _post_pdf(self, save_in_attachment, pdf_content=None, res_ids=None):
        # OVERRIDE
        if self.model == 'account.invoice' and res_ids and len(res_ids) == 1:
            invoice = self.env['account.invoice'].browse(res_ids)
            if invoice.type in ('out_invoice', 'out_refund') and invoice.state != 'draft':
                xml_content = invoice._export_as_facturx_xml()

                # Add attachment.
                reader_buffer = io.BytesIO(pdf_content)
                reader = PdfFileReader(reader_buffer)
                writer = PdfFileWriter()
                writer.cloneReaderDocumentRoot(reader)
                writer.addAttachment('factur-x.xml', xml_content)
                buffer = io.BytesIO()
                writer.write(buffer)
                pdf_content = buffer.getvalue()

                reader_buffer.close()
                buffer.close()
        return super(IrActionsReport, self)._post_pdf(save_in_attachment, pdf_content=pdf_content, res_ids=res_ids)
=================

As you can see, if the invoice is not in the 'draft' sale, the xml flux is re-generated according to another method invoice._export_as_facturx_xml() and attached to the PDF as factur-x.xml. And this factur-x xml content is not valid against the xsd schema. (see next)

==== COMMAND =======

"C:\DATA\Odoo 12.0\python\python.exe" "C:\DATA\Odoo 12.0\python\Scripts\facturx-xmlcheck" factur-x.xml

==== RESULT COMMAND =======

024-02-09 11:13:16,872 [INFO] Flavor is factur-x (autodetected)
2024-02-09 11:13:16,873 [INFO] Level is en16931 (autodetected)
2024-02-09 11:13:16,885 [ERROR] The XML file is invalid against the XML Schema Definition
2024-02-09 11:13:16,885 [ERROR] XSD Error: Element '{urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100}SpecifiedLineTradeAgreement': Missing child element(s). Expected is ( {urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100}NetPriceProductTradePrice )., line 40
2024-02-09 11:13:16,886 [ERROR] The Factur-x XML file is not valid against the official XML Schema Definition. Here is the error, which may give you an idea on the cause of the problem: Element '{urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100}SpecifiedLineTradeAgreement': Missing child element(s). Expected is ( {urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100}NetPriceProductTradePrice )., line 40.

=================

My final question is that when i "Send to Chorus", the invoice is rejected by the Chorus platform. I don't know why. I just can suppose that it comes from the fact that the xml flux is not valid.

Thanks to all to your help, hints. 

Cedric

Follow-Ups