2023-06-21 12:19:08 +00:00
|
|
|
import requests
|
2023-06-21 15:31:02 +00:00
|
|
|
import json
|
|
|
|
import sys
|
2023-06-21 12:19:08 +00:00
|
|
|
from config import *
|
|
|
|
|
2023-06-21 15:31:02 +00:00
|
|
|
document = str(sys.argv[1])
|
|
|
|
|
|
|
|
url = ob_api_url+"Invoice?_where=documentNo='"+document+"'&_noActiveFilter=false"
|
2023-06-21 12:19:08 +00:00
|
|
|
|
|
|
|
payload = {}
|
|
|
|
headers = {
|
|
|
|
'Authorization': 'Basic '+userpass_b64
|
|
|
|
}
|
|
|
|
|
2023-06-21 15:31:02 +00:00
|
|
|
response = requests.request("GET", url, headers=headers, data=payload) #extracts invoice header
|
|
|
|
|
|
|
|
print(response.text)
|
|
|
|
invoice = json.loads(response.text)
|
|
|
|
#print (invoice['response']['data'][0]['client'])
|
|
|
|
|
|
|
|
url = ob_api_url+"InvoiceLine?_where=invoice='"+invoice['response']['data'][0]['id']+"'&_noActiveFilter=false"
|
2023-06-21 12:19:08 +00:00
|
|
|
|
2023-06-21 15:31:02 +00:00
|
|
|
response = requests.request("GET", url, headers=headers, data=payload) #extracts invoice lines
|
2023-06-21 12:19:08 +00:00
|
|
|
print(response.text)
|
|
|
|
|
2023-06-21 15:31:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
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"
|
2023-06-21 15:43:43 +00:00
|
|
|
"platform_id": banqup_platform_id,
|
2023-06-21 15:31:02 +00:00
|
|
|
"debtor_id": 136328, #needs to be fetch from database using the "client_debtor_number"
|
|
|
|
"currency_code": invoice['response']['data'][0]['currency$_identifier'],
|
2023-06-21 15:43:43 +00:00
|
|
|
"client_id": banqup_client_id,
|
2023-06-21 15:31:02 +00:00
|
|
|
"delivery_channel": "openpeppol",
|
|
|
|
"invoice_lines": [
|
|
|
|
{
|
|
|
|
"service_name": "161218",
|
|
|
|
"service_description": "Cavendish Banana 18.8Kg BOX",
|
|
|
|
"service_quantity": 10,
|
|
|
|
"service_price": 1.75,
|
|
|
|
"service_vat": 8
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
print(payload)
|