Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Re: Invoice Factur-X, l10n_fr_account_invoice_facturx

by
Le Filament, Rémi Cazenave
- 09/02/2024 13:08:02
Sorry, I made a mistake in my previous answer, the module from Odoo to be removed is of course account_facturx and not account_e-invoice_generate (which is the one from OCA)
Le 09/02/2024 à 11:57, Rémi CAZENAVE - Le Filament a écrit :

Hi Cedric,

You do not mention which modules you are using to generate Factur-X and send to Chorus, so I would assume you use OCA ones from l10n-france repository.

There is a known discrepancy between Odoo modules and OCA ones regarding factur-x generation.

Normally, if you installed factur-x and Chorus ones from OCA l10n-france directory, you should have also installed account_e-invoice_generate from OCA EDI repository (https://github.com/OCA/edi/blob/12.0/account_e-invoice_generate).

The README of that module mentions the following which is probably the cause of your issue (https://github.com/OCA/edi/blob/12.0/account_e-invoice_generate/README.rst#installation) :

The project OCA/edi provides modules to generate UBL and Factur-X invoices. This solution designed by OCA is an alternative to the solution provided by Odoo S.A. in the official addons (Community version), it is not a solution built above it.
As a consequence, before installing this module, you should uninstall the module account_facturx of Odoo S.A. The module account_facturx is an auto-install module, so it is probably installed by default on your Odoo.
If you want to generate Factur-X invoices, you should install the OCA module account_invoice_factur-x available on OCA/edi.

Do you have both account_e-invoice_generate and account_facturx installed ?

If so you should remove the one from Odoo (account_facturx). Be careful however that Odoo module account_facturx is auto-installable so it may reinstall on its own if you do not pay attention. This module may help in overcoming this behaviour : https://github.com/OCA/server-tools/tree/12.0/module_change_auto_install


Best Regards,

Rémi


Le 09/02/2024 à 11:37, DEBARD Cédric a écrit :
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

_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe

Reference