A Step-by-Step Guide for Uploading Your Invoice to Odoo using EdenAI API
Tags: ai, api, invoiceparser, odoo
Published: 2023-08-08 08:10:20

_In this article, we'll show you how to integrate Eden AI's [Invoice parser API](https://www.edenai.co/feature/ocr-invoice-parsing-apis) 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](https://www.edenai.co/feature/object-detection-apis), [Explicit content detection](https://www.edenai.co/feature/explicit-content-detection-apis), [Text analysis](https://www.edenai.co/technologies/text?referral=integrate-invoice-parser-bubble) 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:

- [Document parsing:](https://www.edenai.co/feature/ocr-apis) extracting text from images and [parsing invoice](https://www.edenai.co/feature/ocr-invoice-parsing-apis), [receipt](https://www.edenai.co/feature/ocr-receipt-parsing-apis) or [resume](https://www.edenai.co/feature/ocr-resume-parser-apis) to extract data
- [Computer vision:](https://www.edenai.co/technologies/image) [detect faces](https://www.edenai.co/feature/face-detection-apis), [objects](https://www.edenai.co/feature/object-detection-apis), logos, [explicit content](https://www.edenai.co/feature/explicit-content-detection-apis), etc.
- Text analysis: [sentiment analysis](https://www.edenai.co/feature/sentiment-analysis-apis), [keyword extraction](https://www.edenai.co/feature/keyword-extraction-apis), [summarization](https://www.edenai.co/feature/summarization-apis), etc.
- ‍[Machine Translation](https://www.edenai.co/post/best-machine-translation-apis)
- ‍[Speech recognition](https://www.edenai.co/post/which-speech-recognition-api-to-choose-for-your-project) & Speech generation
‍

‍

## **Let's practice with [Invoice parsing](https://www.edenai.co/feature/ocr-invoice-parsing-apis)!**
‍Just like [Receipt](https://www.edenai.co/post/top-10-ocr-receipt-parser-api?referral=integrate-invoice-parser-bubble) and [Resume](https://www.edenai.co/post/top-10-ocr-resume-parser-api?referral=integrate-invoice-parser-bubble) Parsing, Invoice Parsing is a tool powered by [OCR](https://www.edenai.co/post/analyze-easily-document-files-with-ai-optical-character-recognition-ocr?referral=integrate-invoice-parser-bubble) to extract and digitalize meaningful data, [Computer Vision](https://www.edenai.co/post/best-computer-vision-apis?referral=integrate-invoice-parser-bubble) to identify structure of the document, and [NLP](https://www.edenai.co/post/best-natural-language-processing-apis?referral=integrate-invoice-parser-bubble) 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.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qk1osfoxtbcrg1zn0rsh.png)



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.

‍
[**Try Eden AI for FREE**](https://app.edenai.run/user/register?referral=a-step-by-step-guide-for-uploading-your-invoice-to-odoo-using-edenai-api)

‍

## **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](https://app.edenai.run/user/register?referral=a-step-by-step-guide-for-uploading-your-invoice-to-odoo-using-edenai-api)! 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.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/upesph824vxxts1swbas.png)


‍[**Get your API key for FREE**](https://app.edenai.run/user/register?referral=a-step-by-step-guide-for-uploading-your-invoice-to-odoo-using-edenai-api)





**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:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/357c9uy442qm7qzvyk9m.png)


‍

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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8bwebfvhoexatojr4d7.png)
‍

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

```
{
   'name' : 'EdenAI',
   'version' : '1',
   'summary': 'Invoices & Payments',
   'description': """
       Module for Eden AI Invoicing API Tutorial
   """,
   'category': 'Accounting/Accounting',
   'depends' : ['account'],
   'data': [


   ],
   'installable': True,
   'application': False,
   'license': 'LGPL-3',
}

```


You should now activate your new custom module:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jw5qvktsku7185ju9o6r.png)



‍**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:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5xh07ftnwvcon43w6hjo.png)


‍


**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:

```
<odoo>
 <data>
   <!-- Define a new view that will inherit the target view -->
   <record id="eden_invoicing_view" model="ir.ui.view">
     <field name="name">account.move.form.eden.api</field>
     <field name="model">account.move</field>
     <field name="inherit_id" ref="account.view_move_form"/>
     <field name="arch" type="xml">
       <header>
         <button name="eden_api_button" string="Eden Parser" class="btn-primary" type="object"/>
       </header>
     </field>
   </record>
 </data>
</odoo>

```

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:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/snyq8mfzcgzl820d33nv.png)


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:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evp8svqijpg8lpoqtq9p.png)

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”**.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/btruogsphtidifs4lzts.png)


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)
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09rq205cl96n6f4m5ddn.png)


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:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4j5wvuhptptx1maa7jzg.png)


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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0vmust3y7wxnp339nq50.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/syht1ukqzn87hdhf413h.png)


**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.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6w8swk17gyfyf8hrkt0s.png)
 

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:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pfyd92jivlecdd3kirf1.png)



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:



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g65n89p6diokaez705gk.png)



**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](https://www.edenai.co/post/a-step-by-step-guide-to-bring-ai-to-your-app-using-zapier?referral=integrate-invoice-parser-bubble), [Zapier](https://www.edenai.co/post/a-step-by-step-guide-to-bring-ai-to-your-app-using-zapier?referral=integrate-invoice-parser-bubble), [Google App Script](https://www.edenai.co/post/a-step-by-step-guide-to-integrating-ai-in-your-app-with-google-app-script?referral=integrate-invoice-parser-bubble), [Retool](https://www.edenai.co/post/a-step-by-step-guide-to-implementing-ai-in-your-app-using-retool?referral=integrate-invoice-parser-bubble), [Make](https://www.edenai.co/post/how-to-integrate-invoice-parsing-into-your-application-using-make?referral=integrate-invoice-parser-bubble), [Dataiku](https://www.edenai.co/post/a-step-by-step-guide-to-bring-ai-to-your-app-using-daitaku-dss?referral=integrate-invoice-parser-bubble), [IFTTT](https://www.edenai.co/post/a-step-by-step-guide-to-implementing-ai-in-your-app-using-ifttt?referral=integrate-invoice-parser-bubble), and [n8n](https://www.edenai.co/post/a-step-by-step-guide-to-implementing-ai-in-your-app-with-n8n?referral=integrate-invoice-parser-bubble)._

‍

[**Create your Account on Eden AI**](https://app.edenai.run/user/register?referral=integrate-invoice-parser-bubble)