New opensource PDF invoice import module for Odoo

On December 25th 2015, I wrote a blog post to announce a new OCA module to automate the import of PDF invoices in Odoo. The title of this blog post was Akretion's Christmas present for the Odoo community. This module was named account_invoice_import_invoice2data because, to extract the relevant data from the PDF invoice (date, total with tax, total without tax, invoice number, etc.), it used a python library called invoice2data. This module later joined the OCA/edi project on Github. It was released for Odoo v8, and has been ported to higher versions including Odoo v14, the latest version of Odoo. This module is still the main opensource solution to import a simple PDF invoice as vendor bill in Odoo. If you have a structured invoice such as a Factur-X PDF invoice or an UBL invoice, there are specific modules to add support for these formats (account_invoice_import_facturx, account_invoice_import_ubl) that take advantage of the structured data.

At Akretion, we've been using this module for 6 years now and our customers use it too. It works well, but there is one major drawback: when you need to add support for a new vendor, you must write a new template, and this task involves writing regular expressions. In real life, it means that an accountant cannot add support for a new vendor by himself, he needs to ask a software developer to do it. The same thing happens when the layout of the invoices changes: the template often needs to be updated and this requires developer skills.

So far, I considered that investing time to improve this module was not a good investment because all invoices will eventually be available in Factur-X or UBL format in the future, so such a module that imported simple PDF invoices (without any XML file as attachment) would soon be deprecated. I was certainly too optimistic: I have to admit that 99% of the invoices I receive today are still simple PDF invoices.

On July 13th 2021, I made a presentation of my module account_invoice_import_invoice2data to the accountant of a company running on Odoo during an online meeting. The accountant was happy because the module was adressing his needs. Then he told me that he needed to support about 50 suppliers, so I would have to develop up to 50 invoice2data templates. When I hung up the call, I was quite unhappy because I thought: Damn-it, I'll have to develop 50 invoice2data templates: it not difficult... but it's not fun !

I started to wonder how I could avoid this mission to develop 50 invoice2data templates! I started thinking about a new module that would import simple PDF invoices as vendor bills in Odoo with one main requirement: the accountant should be able to add support for a new supplier by himself. No technical skills needed. Fast and easy.

By chance, the day after that online meeting was July 14th, which is the national day in France. My kids were at their scout camp, my wife was on holidays in Normandy and it was a rainy day. So I started developing a new module called account_invoice_import_simple_pdf. I took advantage of my 6 years of experience using the module account_invoice_import_invoice2data and developing invoice2data templates. And I came out with an easy-to-use solution where the accountant can add support for new vendors by himself. And, even for me with my strong experience writting invoice2data templates, it's faster to add support for a new vendor with that new module than writting an invoice2data template! I'm very happy to annonce the release of this new module today: it seems Christmas is in July this year! I hope you will have as much fun using this module than I had developing it... while watching the military parade on the Champs-Élysées! The module is available for Odoo v14 in this pull request.

How does it work? It's quite similar to the invoice2data module. When you import a new simple PDF invoice in Odoo:

  1. Odoo makes a raw text extraction of the PDF. It works very well when the PDF invoice is the original PDF generated by the supplier, but it won't work if the PDF invoice is a scan of a paper invoice because, in that case, the PDF only contains an image.
  2. If the VAT number of the vendor is configured in Odoo and is present in the raw text extraction, Odoo will identify that partner as the vendor. Otherwise, you can configure one or several keywords on the partner form: if all these keywords are present in the raw text extraction, it will identify that partner as the vendor.
  3. Then Odoo will get the value of the fields configured in the Vendor Bill Import tab from the raw text extraction and use that data to create the vendor bill following the setup of the Invoice Import Configuration of that partner.

I made a screencast that showcases the configuration and import of a real invoice of Mooncard, one of my vendors.

Here are some details about the setup on the partner form. In the Vendor Bill Import tab, you must configure:

  • Whether Odoo should analyse only the first page of the invoice or all the pages. For example, my phone bill has several pages: the first page has the main invoice data and the second and following pages have the details of all my phone calls, so I would configure Page Analysis: First page only for my phone vendor.
  • The invoice currency. Leave empty if it's the same as the company currency.
  • The date format, for example : DD MM YYYY, DD Month YYYY, etc.
  • The date separator: slash, dash, dot, space, etc.
  • The decimal separator. Leave empty if it is the same as the decimal separator of the language of the partner, for example coma in French.
  • The thousand separator. Leave empty if it is the same as the thousand separator of the language of the partner, for example space in French.
  • The invoice number format. For example, if the invoice number looks like INV/2021/0042 you would configure it that way:
    1. Fixed char: INV/
    2. Year on 4 digits
    3. Fixed char: /
    4. Digits: min. occurence: 4, max. occurence: 4 (or 5 to be more flexible)
  • The fields extraction rules. You can configure the following fields:
    • Amount Total
    • Total Untaxed
    • Total Tax
    • Invoice Number
    • Invoice Date
    • Due Date
    • Start Date
    • End Date

Note that you should only configure 3 out of the 2 amount fields because Amount Total = Total Untaxed + Total Tax, so with 2 fields Odoo can compute the 3rd one. If the invoice is without VAT, you should only configure the Amount Total field. The Start Date and End Date fields are relevant if you use the OCA module account_invoice_start_end_dates available from the OCA/account-closing project and you want to have the start and end date on the invoice line.

For each field, you must configure an extraction rule such as:

  • First
  • Last
  • 2nd position counting from the start
  • 3rd position counting from the end
  • Min
  • Max
  • 3rd position counting from min
  • 5th position counting from max

For a particular field, you can restrict the scope of the extraction rule by giving a Start String and/or an End String. For example, if you set Total HT as Start String for the field Untaxed Amount and the extraction rule is Min, Odoo will search for the first occurence of Total HT in the raw text extraction and retrieve the minimum amount it finds after that string (in French, "HT" is the abbreviation of "hors taxes" i.e. "without taxes").

For date fields, you can set a specific date format and separator. Let's consider an invoice where the Invoice Date and Due Date are written as 27/07/2021 but the Start Date and End Date are written as July 31, 2021. To support that, configure the date format of the partner with:

  • Date Format: DD MM YYYY
  • Date separator: slash

and, on the Start Date and End Date fields:

  • Specific Date Format: Month DD, YYYY
  • Specific Date Separator: Space (comas and points are ignored in that case).

At the bottom of the Vendor Bill Import tab, you have a test section where you can upload a PDF invoice of that partner and test the setup you made: you will get a clear analysis of the partner matching result and the extraction result for each field. It will help you finalize the configuration until you get a configuration which extracts the right values for each field.

Once the configuration is finished, start the import wizard via to the menu Invoicing > Vendors > Import Vendor Bill, upload the PDF invoice and... enjoy the automatic creation of the vendor bill! Check that the vendor bill has been properly created and confirm it. Note that the PDF is automatically attached to the invoice.

Don't hesitate to contact Akretion is you need to backport this module to the version of Odoo you are using or if you need training or support on the module.

Lumière sur l'auteur

Founder
Alexis de Lattre
Founder - France
Specialist in Odoo and free software
Alexis de Lattre is a co-founder of the French company Anevia, where he held the positions of Managing Director and Financial Director of Production and Logistics and Director of Computer Services. Anevia is a company with 40 employees and specializes in the development and sale of video server...

Esse site usa cookies para melhorar a sua experiência de navegação