-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALMA_update_status_paid.py
48 lines (41 loc) · 1.65 KB
/
ALMA_update_status_paid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python3
import csv
import requests
import xmltodict
# configs
apikey = 'YOUR_API_KEY'
# get list of invoices with status "waiting to be paid"
r = requests.get(f"https://api-na.hosted.exlibrisgroup.com/almaws/v1/acq/invoices?invoice_workflow_status=Ready to be Paid&view=brief&limit=100&apikey={apikey}")
invoices_xml = r.text
invoices = xmltodict.parse(invoices_xml, dict_constructor=dict)
# parse invoice list
for invoice in invoices['invoices']['invoice']:
invoice_number = invoice['number']
invoice_alma_id = invoice['id']
# search for a match in PeopleSoft transaction file
with open('Transactions.csv', newline="") as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
# skip header
next(reader)
# parse rows
for row in reader:
document_id = row[6]
invoice_id = row[8]
date_posted = row[9]
actuals = row[13]
# update invoice to status "Paid" if found
payload = f"""
<invoice>
<payment>
<voucher_date>{date_posted}</voucher_date>
<voucher_amount>{actuals}</voucher_amount>
<voucher_currency desc="US Dollar">USD</voucher_currency>
<voucher_number>{document_id}</voucher_number>
</payment>
</invoice>
"""
if invoice_id == invoice_number:
# post paid invoice
url = f"https://api-na.hosted.exlibrisgroup.com/almaws/v1/acq/invoices/{invoice_alma_id}?op=paid&apikey={apikey}"
headers = {'Content-Type': 'application/xml', 'charset':'UTF-8'}
r = requests.post(url, data=payload.encode('utf-8'), headers=headers)