You've already forked akaunting-py
Moved helper functions
This commit is contained in:
@@ -2,15 +2,9 @@ import requests
|
|||||||
import json
|
import json
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
from akauntingpy import exceptions
|
from akauntingpy import exceptions
|
||||||
|
from akauntingpy.helpers import *
|
||||||
|
|
||||||
def MergeDict(dict1, dict2):
|
|
||||||
dict2.update(dict1)
|
|
||||||
return dict2
|
|
||||||
|
|
||||||
def RemoveFromString(items, string):
|
|
||||||
for item in items:
|
|
||||||
string = string.replace(item, '')
|
|
||||||
return string
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
"""
|
"""
|
||||||
Akaunting interface.
|
Akaunting interface.
|
||||||
@@ -64,20 +58,21 @@ class Client(object):
|
|||||||
errors = []
|
errors = []
|
||||||
for key in response_['errors']:
|
for key in response_['errors']:
|
||||||
errors.append(RemoveFromString(["<strong>","</strong>"],
|
errors.append(RemoveFromString(["<strong>","</strong>"],
|
||||||
response_['errors'][key][0]) + " (" + key + ")")
|
response_['errors'][key][0])
|
||||||
|
+ " (" + key + ")")
|
||||||
raise exceptions.InvalidData(response_['message'] +
|
raise exceptions.InvalidData(response_['message'] +
|
||||||
"\n" +
|
"\n" +
|
||||||
"\n".join(errors))
|
"\n".join(errors))
|
||||||
elif response.status_code != 200 and response.status_code != 201:
|
# elif response.status_code != 200 and response.status_code != 201:
|
||||||
raise exceptions.Error(response_['message'])
|
# raise exceptions.Error(response_['message'])
|
||||||
return response_
|
return response_
|
||||||
|
|
||||||
def ping(self):
|
def ping(self):
|
||||||
data = self.call(endpoint="ping")
|
data = self.call(endpoint="ping")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_accounts(self, params=None):
|
def get_accounts(self, **params):
|
||||||
data = self.call(endpoint="accounts", params=params)
|
data = self.call(endpoint="accounts")
|
||||||
|
|
||||||
return data['data']
|
return data['data']
|
||||||
|
|
||||||
@@ -86,6 +81,7 @@ class Client(object):
|
|||||||
account_id=None, # Account ID to assign
|
account_id=None, # Account ID to assign
|
||||||
category_id=None, # Category ID to assign
|
category_id=None, # Category ID to assign
|
||||||
contact_id=None, # Contact ID/Client to assign
|
contact_id=None, # Contact ID/Client to assign
|
||||||
|
description=None, # Description
|
||||||
paid_at=None, # Date of expense/transfer or income
|
paid_at=None, # Date of expense/transfer or income
|
||||||
reference=None, # Reference for the payment
|
reference=None, # Reference for the payment
|
||||||
payment_method=None, # Payment method
|
payment_method=None, # Payment method
|
||||||
@@ -109,6 +105,7 @@ class Client(object):
|
|||||||
currency_code=currency_code,
|
currency_code=currency_code,
|
||||||
currency_rate=currency_rate,
|
currency_rate=currency_rate,
|
||||||
amount=amount,
|
amount=amount,
|
||||||
|
description=description,
|
||||||
**params
|
**params
|
||||||
)
|
)
|
||||||
return data
|
return data
|
||||||
9
akauntingpy/helpers.py
Normal file
9
akauntingpy/helpers.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
def MergeDict(dict1, dict2):
|
||||||
|
dict2.update(dict1)
|
||||||
|
return dict2
|
||||||
|
|
||||||
|
def RemoveFromString(items, string):
|
||||||
|
for item in items:
|
||||||
|
string = string.replace(item, '')
|
||||||
|
return string
|
||||||
Reference in New Issue
Block a user