summaryrefslogtreecommitdiff
path: root/doc/_static/extract_api_implementation.py
diff options
context:
space:
mode:
authorVictor Feyens <vfe@odoo.com>2021-04-30 13:24:57 +0000
committerAntoine Vandevenne (anv) <anv@odoo.com>2021-05-04 08:09:20 +0000
commit27bad8c3e32049ec69a588df0558e57a0b928309 (patch)
treeb60e430163d486c8c1fd052738c9854aeb8300f5 /doc/_static/extract_api_implementation.py
parent75a122bbae3a32bfa79da3506179fc63a8bced5d (diff)
[MOV] doc: move documentation to a dedicated repository
In odoo/documentation-user#945, the developer documentation is merged with the user documentation in a single repository and build config. This commit then removes source files for the developer documentation from the odoo/odoo repository. DOC PR: https://github.com/odoo/documentation-user/pull/945 task-2351938 task-2352371 task-2205684 task-2352544 Co-authored-by: Victor Feyens <vfe@odoo.com> Co-authored-by: Antoine Vandevenne <anv@odoo.com>
Diffstat (limited to 'doc/_static/extract_api_implementation.py')
-rw-r--r--doc/_static/extract_api_implementation.py100
1 files changed, 0 insertions, 100 deletions
diff --git a/doc/_static/extract_api_implementation.py b/doc/_static/extract_api_implementation.py
deleted file mode 100644
index bb2a8bca629..00000000000
--- a/doc/_static/extract_api_implementation.py
+++ /dev/null
@@ -1,100 +0,0 @@
-import base64
-import time
-import sys
-import json
-import requests
-
-account_token = "integration_token" # Use your token
-domain_name = "https://iap-extract.odoo.com"
-path_to_pdf = "/path/to/invoice_file"
-
-API_VERSION = 120 # Do not change
-SUCCESS = 0
-NOT_READY = 1
-
-def jsonrpc(path, params):
- payload = {
- 'jsonrpc': '2.0',
- 'method': 'call',
- 'params': params,
- 'id': 0,
- }
- req = requests.post(domain_name+path, json=payload, timeout=10)
- req.raise_for_status()
- resp = req.json()
- return resp
-
-
-with open(path_to_pdf, "rb") as file:
- params = {
- 'account_token': account_token,
- 'version': API_VERSION,
- 'documents': [base64.b64encode(file.read()).decode('ascii')],
- }
-
-response = jsonrpc("/iap/invoice_extract/parse", params)
-print("/parse call status: ", response['result']['status_msg'])
-
-if response['result']['status_code'] != SUCCESS:
- sys.exit(1)
-
-# You received an id that you can use to poll the server to get the result of the ocr when it will be ready
-document_id = response['result']['document_id']
-params = {
- 'version': API_VERSION,
- 'document_ids': [document_id], # you can request the results of multiple documents at once if wanted
-}
-
-response = jsonrpc("/iap/invoice_extract/get_results", params)
-document_id = str(document_id) # /get_results expects a string despite the fact that the returned document_id is a int
-
-while response['result'][document_id]['status_code'] == NOT_READY: # 1 is the status code indicating that the server is still processing the document
- print("Still processing... Retrying in 5 seconds")
- time.sleep(5)
- response = jsonrpc("/iap/invoice_extract/get_results", params)
-
-with open('results.txt', 'w') as outfile:
- json.dump(response, outfile, indent=2)
-print("\nResult saved in results.txt")
-
-if response['result'][document_id]['status_code'] != SUCCESS:
- print(response['result'][document_id]['status_msg']) # if it isn't a success, print the error message
- sys.exit(1)
-
-document_results = response['result'][document_id]['results'][0]
-print("\nTotal:", document_results['total']['selected_value']['content'])
-print("Subtotal:", document_results['subtotal']['selected_value']['content'])
-print("Invoice id:", document_results['invoice_id']['selected_value']['content'])
-print("Date:", document_results['date']['selected_value']['content'])
-print("...\n")
-
-params = {
- 'document_id': document_id,
- 'values': {
- 'total': {'content': 100.0},
- 'subtotal': {'content': 100.0},
- 'global_taxes': {'content': []},
- 'global_taxes_amount': {'content': 0.0},
- 'date': {'content': '2020-09-25'},
- 'due_date': {'content': '2020-09-25'},
- 'invoice_id': {'content': document_results['invoice_id']['selected_value']['content']},
- 'partner': {'content': 'twinnta'},
- 'VAT_Number': {'content': 'BE23252248420'},
- 'currency': {'content': 'USD'},
- 'merged_lines': False,
- 'invoice_lines': {'lines': [{'description': 'Total TVA ',
- 'quantity': 1.0,
- 'unit_price': 100.0,
- 'product': False,
- 'taxes_amount': 0.0,
- 'taxes': [],
- 'subtotal': 100.0,
- 'total': 100.0}]
- }
- }
-}
-response = jsonrpc("/iap/invoice_extract/validate", params)
-if response['result']['status_code'] == SUCCESS:
- print("/validate call status: Success")
-else:
- print("/validate call status: wrong format")