Compare commits
2 commits
9aa316f0a9
...
9c26ff4376
Author | SHA1 | Date | |
---|---|---|---|
Enrique Barcelli | 9c26ff4376 | ||
Enrique Barcelli | f728715b55 |
|
@ -7,6 +7,7 @@ from config import *
|
|||
from cachehandler import CacheHandler
|
||||
from authhandler import AuthHandler
|
||||
from api import OpenbravoToBanqupAPI
|
||||
from datetime import timedelta, date
|
||||
|
||||
def extract_invoice(document):
|
||||
|
||||
|
@ -19,27 +20,22 @@ def extract_invoice(document):
|
|||
|
||||
response = requests.request("GET", url, headers=headers, data=payload) #extracts invoice header
|
||||
|
||||
print(response.text)
|
||||
#print(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)
|
||||
authUrl = api.authHandler.getAuthURL(bq_redirect_uri)
|
||||
webbrowser.open(authUrl)
|
||||
response = input('paste response: ')
|
||||
response = input('Paste response: ')
|
||||
token = api.authHandler.retrieveToken(response, redirectUri=bq_redirect_uri)
|
||||
print(token)
|
||||
#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'])
|
||||
#print(debtor_list)
|
||||
|
||||
debtor_id = debtor_list[2]['results'][0]['id']
|
||||
preferred_channel = debtor_list[2]['results'][0]['preferred_channel']
|
||||
|
@ -62,14 +58,14 @@ def extract_invoice(document):
|
|||
if not first_line:
|
||||
lines_output = lines_output+','
|
||||
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+']'
|
||||
#print(lines_output)
|
||||
|
||||
payload = json.dumps({
|
||||
"sales_invoice_number": invoice['response']['data'][0]['documentNo'],
|
||||
"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,
|
||||
"debtor_id": debtor_id,
|
||||
"currency_code": invoice['response']['data'][0]['currency$_identifier'],
|
||||
|
@ -77,7 +73,7 @@ def extract_invoice(document):
|
|||
"delivery_channel": preferred_channel,
|
||||
"invoice_lines": json.loads(lines_output)
|
||||
})
|
||||
print(payload)
|
||||
#print(payload)
|
||||
|
||||
new_invoice = api.post('sales-invoices',json.loads(payload),None,None)
|
||||
print(new_invoice)
|
||||
|
|
Loading…
Reference in a new issue