Overview
Odoo's accounting module can be extended with Cargoffer OCR. A custom module sends PDF invoices to the OCR API and fills the vendor bill form automatically.
Odoo Python Code
python
import requests
from odoo import models, api
class AccountMove(models.Model):
_inherit = 'account.move'
def action_ocr_extract(self):
self.ensure_one()
api_key = self.env['ir.config_parameter'].sudo().get_param('ocr.api_key')
# Upload PDF
with open(self.invoice_pdf_path, 'rb') as f:
r = requests.post(
'https://ocr.cargoffer.com/api/upload',
headers={'Authorization': f'Bearer {api_key}'},
files={'file': f})
job = r.json()['job']
# Analyze
r = requests.post(
f'https://ocr.cargoffer.com/api/analyze/{job}',
headers={'Authorization': f'Bearer {api_key}'})
data = r.json()
# Fill invoice
inv = data['results'][list(data['results'].keys())[0]]
self.invoice_date = inv.get('issue_date')
self.amount_total = inv.get('totals', {}).get('total')
return True