Compare commits

..

2 commits

Author SHA1 Message Date
Enrique Barcelli 9c26ff4376
Remove product code from submission to API
Clean debuging print statements
2023-06-25 00:43:35 +08:00
Enrique Barcelli f728715b55
Calculate Due Date 2023-06-25 00:23:57 +08:00

View file

@ -7,6 +7,7 @@ from config import *
from cachehandler import CacheHandler from cachehandler import CacheHandler
from authhandler import AuthHandler from authhandler import AuthHandler
from api import OpenbravoToBanqupAPI from api import OpenbravoToBanqupAPI
from datetime import timedelta, date
def extract_invoice(document): def extract_invoice(document):
@ -19,27 +20,22 @@ def extract_invoice(document):
response = requests.request("GET", url, headers=headers, data=payload) #extracts invoice header response = requests.request("GET", url, headers=headers, data=payload) #extracts invoice header
print(response.text) #print(response.text)
invoice = json.loads(response.text) invoice = json.loads(response.text)
print (invoice['response']['data'][0]['businessPartner']) #print (invoice['response']['data'][0]['businessPartner'])
lastCalculatedOnDate = invoice['response']['data'][0]['lastCalculatedOnDate']
daysTillDue = invoice['response']['data'][0]['daysTillDue']
dueDate = date(int(lastCalculatedOnDate[0:4]), int(lastCalculatedOnDate[5:7]), int(lastCalculatedOnDate[8:10])) + timedelta(days=daysTillDue)
api = OpenbravoToBanqupAPI(bq_client_id,bq_client_secret) api = OpenbravoToBanqupAPI(bq_client_id,bq_client_secret)
authUrl = api.authHandler.getAuthURL(bq_redirect_uri) authUrl = api.authHandler.getAuthURL(bq_redirect_uri)
webbrowser.open(authUrl) webbrowser.open(authUrl)
response = input('paste response: ') response = input('Paste response: ')
token = api.authHandler.retrieveToken(response, redirectUri=bq_redirect_uri) token = api.authHandler.retrieveToken(response, redirectUri=bq_redirect_uri)
print(token) #print(token)
businessPartner=invoice['response']['data'][0]['businessPartner'] businessPartner=invoice['response']['data'][0]['businessPartner']
debtor_list = api.get('debtors?client_id='+banqup_client_id+'&client_debtor_number='+businessPartner,None,None) debtor_list = api.get('debtors?client_id='+banqup_client_id+'&client_debtor_number='+businessPartner,None,None)
#print(debtor_list)
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'] debtor_id = debtor_list[2]['results'][0]['id']
preferred_channel = debtor_list[2]['results'][0]['preferred_channel'] preferred_channel = debtor_list[2]['results'][0]['preferred_channel']
@ -62,14 +58,14 @@ def extract_invoice(document):
if not first_line: if not first_line:
lines_output = lines_output+',' lines_output = lines_output+','
first_line = False first_line = False
lines_output = lines_output + '{"service_name": "'+linetemp['product']+'","service_description": "'+linetemp['product$_identifier']+'","service_quantity": '+str(linetemp['invoicedQuantity'])+',"service_price": '+str(linetemp['unitPrice'])+',"service_vat": '+'8'+'}' lines_output = lines_output + '{"service_name": "","service_description": "'+linetemp['product$_identifier']+'","service_quantity": '+str(linetemp['invoicedQuantity'])+',"service_price": '+str(linetemp['unitPrice'])+',"service_vat": '+'8'+'}'
lines_output = lines_output+']' lines_output = lines_output+']'
#print(lines_output) #print(lines_output)
payload = json.dumps({ payload = json.dumps({
"sales_invoice_number": invoice['response']['data'][0]['documentNo'], "sales_invoice_number": invoice['response']['data'][0]['documentNo'],
"sales_invoice_date": invoice['response']['data'][0]['invoiceDate']+"T00:00:00Z", "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" "sales_invoice_due_date": str(dueDate)+"T00:00:00Z",
"platform_id": banqup_platform_id, "platform_id": banqup_platform_id,
"debtor_id": debtor_id, "debtor_id": debtor_id,
"currency_code": invoice['response']['data'][0]['currency$_identifier'], "currency_code": invoice['response']['data'][0]['currency$_identifier'],
@ -77,7 +73,7 @@ def extract_invoice(document):
"delivery_channel": preferred_channel, "delivery_channel": preferred_channel,
"invoice_lines": json.loads(lines_output) "invoice_lines": json.loads(lines_output)
}) })
print(payload) #print(payload)
new_invoice = api.post('sales-invoices',json.loads(payload),None,None) new_invoice = api.post('sales-invoices',json.loads(payload),None,None)
print(new_invoice) print(new_invoice)