diff --git a/akauntingpy/api.py b/akauntingpy/api.py index 0751404..0051160 100644 --- a/akauntingpy/api.py +++ b/akauntingpy/api.py @@ -2,15 +2,9 @@ import requests import json from requests.auth import HTTPBasicAuth 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): """ Akaunting interface. @@ -64,20 +58,21 @@ class Client(object): errors = [] for key in response_['errors']: errors.append(RemoveFromString(["",""], - response_['errors'][key][0]) + " (" + key + ")") + response_['errors'][key][0]) + + " (" + key + ")") raise exceptions.InvalidData(response_['message'] + "\n" + "\n".join(errors)) - elif response.status_code != 200 and response.status_code != 201: - raise exceptions.Error(response_['message']) + # elif response.status_code != 200 and response.status_code != 201: + # raise exceptions.Error(response_['message']) return response_ def ping(self): data = self.call(endpoint="ping") return data - def get_accounts(self, params=None): - data = self.call(endpoint="accounts", params=params) + def get_accounts(self, **params): + data = self.call(endpoint="accounts") return data['data'] @@ -86,6 +81,7 @@ class Client(object): account_id=None, # Account ID to assign category_id=None, # Category ID to assign contact_id=None, # Contact ID/Client to assign + description=None, # Description paid_at=None, # Date of expense/transfer or income reference=None, # Reference for the payment payment_method=None, # Payment method @@ -109,6 +105,7 @@ class Client(object): currency_code=currency_code, currency_rate=currency_rate, amount=amount, + description=description, **params ) return data \ No newline at end of file diff --git a/akauntingpy/helpers.py b/akauntingpy/helpers.py new file mode 100644 index 0000000..36c7df0 --- /dev/null +++ b/akauntingpy/helpers.py @@ -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 \ No newline at end of file