A Step-by-Step Guide for Uploading Your Invoice to Odoo using Eden AI API
Tutorial

A Step-by-Step Guide for Uploading Your Invoice to Odoo using Eden AI API

In this article, we'll show you how to integrate Eden AI's Invoice parser API into an Odoo Module to help streamline your financial operations and free up time for more important tasks. The same process applies if you want to include other features like : Image tagging, Explicit content detection, Text analysis and many more AI APIs we offer.

For the tutorial, it's important to have the Odoo server up and running on your machine.

Build AI on Odoo with Eden AI

Eden AI was created for no-coders having difficulties with choosing the right AI provider and/or integrating several APIs. Managing multiple accounts for each app can be a tough job, but with Eden AI, you can connect and manage all your APIs on a single account.

Since some AI providers can be complex to use, we wanted to simplify the “no code” part and make AI available to as many people as possible.

Eden AI allows you to solve multiple AI tasks on Odoo:

Let's practice with Invoice parsing!

Just like Receipt and Resume Parsing, Invoice Parsing is a tool powered by OCR to extract and digitalize meaningful data, Computer Vision to identify structure of the document, and NLP techniques to pin down the fields. Invoice parser technology extracts key information from an invoice (.pdf, .png or .jpg format) such as the invoice ID, total amount due, invoice date, customer name, etc.

Invoice Processing implies the necessity of software and technology to automate the processing and management of invoices. It includes tasks such as capturing invoice data, validating it in comparison to purchase orders, and routing it for approval, payment and archiving. The goal of AI in invoice processing is to improve efficiency, accuracy, and speed in handling invoices without any human intervention.

How to bring invoice parsing to your app using Odoo?

Step 1. Create an Eden AI account

Get started by signing in to Eden AI! Don't have an account? No worries, we're giving away $10 when you register. Once you're in, a world of possibilities opens up, including integrating with platforms like Salesforce.

Step 2: Activate your Invoicing Module

First of all, you need to activate the Invoicing module (technical name: "account"). If you don’t find it in the menu, type “Invoicing” in the search bar above:

Once your invoicing module has been activated, you'll need to customize (or extend) it in order to use the Eden Invoice parser API.

Step 3: Extend your Invoicing Module

Add a module called "invoice_parsing" to your custom add-ons and ensure that you set up the correct folder structure. This should be sufficient for now.

Also add the relevant details in your manifest.py file:

You should now activate your new custom module:

Note: You will have to remove the “Apps” filter in the search bar since we set "application" to False in the manifest.py file.

Step 4: Inheriting the Invoicing Model & View

Refer to the folder structure shared above. In the models directory create these files:

  1. __init__.py
  2. eden_invoicing.py

Similarly, in the views directory create the following file:

  1. eden_invoicing.xml

The folder structure should now look (something) like this:

Additions in the Python File

Paste the following code in your “models/eden_invoicing.py” file:


from odoo import (
   api,
   fields,
   models,
)




class EdenInvoicing(models.Model):
   _name = "account.move"
   _inherit = ['account.move']


@staticmethod
def eden_api_button(self):
   pass

Additions in the XML File

Likewise, paste the following code in the “views/eden_invoicing.xml” file:



 
   
   
     account.move.form.eden.api
     account.move
     
     
       

Basically, in both of these cases we are inheriting the default Odoo invoicing in order to add our changes for integrating Eden’s Invoice Parsing API.

Note: As you can see, the name of the button “eden_api_button” matches with the method name in the python file above it i.e., “def eden_api_button(self):...”

Then, you need to add the path of the view in __manifest__.py and import the model in order to make the changes in the module accessible to Odoo:

Also, add the following lines in the __init__.py file of the invoice_parsing module and models directory respectively:

from.import models

from.import eden_invoicing

Now, go back to your “invoice_parsing” module in the Apps list and upgrade the module again.

Afterward, when you open the Invoicing form view, you will notice the following button:

Eventually, this button (i.e. Eden Parser) will enable us to upload a file and save it as a record on Odoo.

However, from now on, we’ll direct our focus on the API itself.

Step 5: Integrate Eden-AI API in Odoo

1. Write the API script

The next step is to integrate the Eden-AI API with the button we created in the last section. The goal here is to trigger the Eden AI API on the click of that button.

First, create a file in the models directory with the name “eden_ai_api.py”.

In the newly created file, copy the following code:


import requests
import json

def main():
   headers = {
       "Authorization": "Bearer Your-API-Key"
   }

   url = "https://api.edenai.run/v2/ocr/invoice_parser"
   data = {"providers": "affinda, mindee", "language": "en"}
   files = {'file': open("/path/to/invoice.pdf", 'rb')}

   response = requests.post(url, data=data, files=files, headers=headers)

   result = json.loads(response.text)
   print(result['mindee']['extracted_data'])
   return result['mindee']['extracted_data']

if __name__ == '__main__':
   main()

After pasting the provided code, it's essential to replace the placeholder "Your-API-Key" with your actual API key, and also update the path to your file by replacing "/path/to/invoice.pdf" with the correct file path.

2. Call the API script in Model Method

Now, going back to the "eden_invoicing.py" file, call the "main" function from the above script. Go back to the "eden_api_button" method that we defined above. Modify the method to this:


@staticmethod
def eden_api_button(self):
   a_dict = eden_ai_api.main()
   print(a_dict)

Now that you have called the "eden_ai_api" script in your button method, restart your server and upgrade your custom module from the Apps menu. Finally, return to the location where the button was initially placed to continue with the next steps:

Click the “EDEN PARSER” button and check your logs in PyCharm, you will see a dictionary printed:

The screenshot below shows that your invoice has been successfully parsed by the Eden-AI invoice parsing API:

3. Upload File to Odoo

While this tutorial does everything through the backend, you can also add functionality to upload a file directly and automate the invoice uploading process. However, this will require extensive knowledge of JavaScript and Odoo’s Owl framework.

Here’s a summary of the steps you need to follow in order to be able to upload file from device:

  1. Inherit the owl component with the class name: “account.ListView.Buttons”. You can find it in the static directory of the accounts module in Odoo source code (i.e.,odoo/addons/account/static/src/bills_upload/…). You’ll find it to be an inherited list, that you will inherit further.

      

        2. Next, you need to create a component called Eden File Uploader, and provide all the definitions. In this case, you will be extending the base “FileUploader”             Component functionality. You can find a sample code snippet in the same file:

      

      3. Finally, you need to integrate your Eden AI API processes with the button. For this, you may or may-not need to use pure JavaScript depending on the flow of your           process. A sample button is also provided in the same file:

Note: These code snippets will only act as a base for your own custom buttons and API functionality. You may have to work with controllers and pure JS too.

Eden AI API Conversion

In case you didn’t understand what happened above, note the following points:

  1. Eden AI API parsed the document provided in your local machine and fetched all the relevant data.
  2. The data was stored in JSON format. This works for all the providers that work with Eden AI API. You’ll note that keys of all kinds of information are available with the API. The values that were not provided in the invoice are null.
  3. This JSON data was then converted into a Python dictionary by the script we wrote in the eden_ai_api.py file.
  4. Finally, this script was integrated with an Odoo button (we created initially).

For now, this was just a simple flow of how integration with EdenAI API shall work. You can extend this flow to generate reports or automate your accounting/invoicing pipelines.

In this tutorial we have successfully integrated the EdenAI API with Odoo. You can use this API for different purposes like automating and streamlining your invoicing pipelines. Eden AI’s invoice parsing API will help you in swift parsing and transfer of data between modules in Odoo.

If you're interesting in more integration tools, have a look at our step-by-step tutorials on how to bring AI to your application with Power Apps, Zapier, Google App Script, Retool, Make, Dataiku, IFTTT, and n8n.

Related Posts

Try Eden AI for free.

You can directly start building now. If you have any questions, feel free to schedule a call with us!

Get startedContact sales