Created
April 2, 2018 17:44
-
-
Save jaredk2g/b506a95769ed0ed0a803d5c9cdbe13be to your computer and use it in GitHub Desktop.
Flag invoices on Invoiced that are > 60 days old
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import time | |
import invoiced | |
apiKey = "enter api key here" | |
# Flags open invoices that are > N days old | |
threshold = 60 # days | |
client = invoiced.Client(apiKey, True) | |
endDate = datetime.datetime.now() + datetime.timedelta(-threshold) | |
def loadInvoices(page): | |
return client.Invoice.list( | |
page=page, | |
end_date=time.mktime(endDate.timetuple()), | |
filter={ | |
'paid': 0, | |
'closed': 0, | |
'draft': 0, | |
'needs_attention': 0 | |
}) | |
page = 1 | |
hasMore = True | |
while hasMore: | |
invoices, metadata = loadInvoices(page) | |
if page == 1: | |
print("Found "+str(metadata.total_count)+" invoices that need to be flagged") | |
page += 1 | |
hasMore = metadata.links['self'] != metadata.links['last'] | |
for invoice in invoices: | |
print("Flagging invoice: " +invoice.number) | |
invoice.needs_attention = True | |
invoice.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment