From 26cdb8d55e6777d33f8c5560f2bc931022467b6d Mon Sep 17 00:00:00 2001 From: Enrique Barcelli Date: Sat, 24 Jun 2023 20:43:35 +0800 Subject: [PATCH] Generate full invoice json for invoice creatinon in Banqup --- README.md | 1 + extract_invoice.py | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a92781..c45ff45 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ to the Banqup API of Unifiedpost. * Python installed on the machine running this application * Credentials for accessing an Openbravo 3+ instance running with the REST API enabled * Credentials for accessing the Banqup API by Unifiedpost +* Add the businessPartner id to the customer code or client_debtor_number at the Banqup portal **How to run this application** diff --git a/extract_invoice.py b/extract_invoice.py index 51d34da..0a69e80 100644 --- a/extract_invoice.py +++ b/extract_invoice.py @@ -1,7 +1,12 @@ import requests +from requests_oauthlib import OAuth2Session import json import sys +import webbrowser from config import * +from cachehandler import CacheHandler +from authhandler import AuthHandler +from api import OpenbravoToBanqupAPI def extract_invoice(document): @@ -18,6 +23,27 @@ def extract_invoice(document): invoice = json.loads(response.text) print (invoice['response']['data'][0]['businessPartner']) + api = OpenbravoToBanqupAPI(bq_client_id,bq_client_secret) + authUrl = api.authHandler.getAuthURL(bq_redirect_uri) + webbrowser.open(authUrl) + response = input('paste response: ') + token = api.authHandler.retrieveToken(response, redirectUri=bq_redirect_uri) + print(token) + businessPartner=invoice['response']['data'][0]['businessPartner'] + debtor_list = api.get('debtors?client_id='+banqup_client_id+'&client_debtor_number='+businessPartner,None,None) + + print(debtor_list) + print(debtor_list[0]) + print(debtor_list[1]) + print(debtor_list[2]) + print(debtor_list[2]['results']) + print(debtor_list[2]['results'][0]) + print(debtor_list[2]['results'][0]['id']) + print(debtor_list[2]['results'][0]['preferred_channel']) + + debtor_id = debtor_list[2]['results'][0]['id'] + preferred_channel = debtor_list[2]['results'][0]['preferred_channel'] + url = ob_api_url+"InvoiceLine?_where=invoice='"+invoice['response']['data'][0]['id']+"'&_noActiveFilter=false" response = requests.request("GET", url, headers=headers, data=payload) #extracts invoice lines @@ -45,7 +71,7 @@ def extract_invoice(document): "sales_invoice_date": invoice['response']['data'][0]['invoiceDate']+"T00:00:00Z", "sales_invoice_due_date": "2023-06-17T00:00:00Z", #needs to be replaced by invoiceDate+"daysTillDue" "platform_id": banqup_platform_id, - "debtor_id": 136328, #needs to be fetch from database using the "client_debtor_number" + "debtor_id": debtor_id, "currency_code": invoice['response']['data'][0]['currency$_identifier'], "client_id": banqup_client_id, "delivery_channel": "openpeppol",