Add delete_invoice functionality
This commit is contained in:
parent
c88a1b199d
commit
123eded3c6
11
api.py
11
api.py
|
@ -61,10 +61,13 @@ class OpenbravoToBanqupAPI:
|
||||||
self.authHandler.checkHeaderTokens()
|
self.authHandler.checkHeaderTokens()
|
||||||
response = self.doRequest(method, url, data, headers, files)
|
response = self.doRequest(method, url, data, headers, files)
|
||||||
|
|
||||||
if 'json' in response.headers['Content-Type']:
|
if response.status_code != 204:
|
||||||
respContent = response.json()
|
if 'json' in response.headers['Content-Type']:
|
||||||
elif 'pdf' in response.headers['Content-Type']:
|
respContent = response.json()
|
||||||
respContent = response.content
|
elif 'pdf' in response.headers['Content-Type']:
|
||||||
|
respContent = response.content
|
||||||
|
else:
|
||||||
|
respContent = ''
|
||||||
|
|
||||||
return response.status_code, response.headers, respContent
|
return response.status_code, response.headers, respContent
|
||||||
|
|
||||||
|
|
35
delete_invoice.py
Normal file
35
delete_invoice.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import requests
|
||||||
|
from requests_oauthlib import OAuth2Session
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import webbrowser
|
||||||
|
from config import *
|
||||||
|
from cachehandler import CacheHandler
|
||||||
|
from authhandler import AuthHandler
|
||||||
|
from api import OpenbravoToBanqupAPI
|
||||||
|
from datetime import timedelta, date
|
||||||
|
|
||||||
|
def delete_invoice(document):
|
||||||
|
|
||||||
|
api = OpenbravoToBanqupAPI(bq_client_id,bq_client_secret)
|
||||||
|
authUrl = api.authHandler.getAuthURL(bq_redirect_uri)
|
||||||
|
webbrowser.open(authUrl)
|
||||||
|
response = input('Paste response: ')
|
||||||
|
token = api.authHandler.retrieveToken(response, redirectUri=bq_redirect_uri)
|
||||||
|
#print(token)
|
||||||
|
invoice_list = api.get('sales-invoices?client_id='+banqup_client_id+'&sales_invoice_number='+document,None,None)
|
||||||
|
if not invoice_list[2]['results']:
|
||||||
|
print('***********************')
|
||||||
|
print('The invoice number provided does not exist in the Banqup portal.')
|
||||||
|
print('Please verify and try again.')
|
||||||
|
print('***********************')
|
||||||
|
return
|
||||||
|
invoice_id = str(invoice_list[2]['results'][0]['id'])
|
||||||
|
#print(invoice_id)
|
||||||
|
payload = json.dumps({})
|
||||||
|
invoice_action = api.delete('sales-invoices/'+invoice_id,json.loads(payload),None)
|
||||||
|
print(invoice_action)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
delete_invoice(str(sys.argv[1]))
|
Loading…
Reference in a new issue