You've already forked akaunting-py
Moved helper functions
This commit is contained in:
@@ -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(["<strong>","</strong>"],
|
||||
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
|
||||
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