You've already forked akaunting-py
v1.0.3
This commit is contained in:
@@ -4,7 +4,7 @@ from requests.auth import HTTPBasicAuth
|
||||
from akauntingpy import exceptions
|
||||
from akauntingpy.helpers import *
|
||||
|
||||
__version__ = "1.0.2"
|
||||
__version__ = "1.0.3"
|
||||
|
||||
|
||||
class Client(object):
|
||||
@@ -18,16 +18,21 @@ class Client(object):
|
||||
username,
|
||||
password,
|
||||
company_id,
|
||||
ssl_verify=True,
|
||||
currency_code="NZD",
|
||||
currency_rate="1.0"):
|
||||
"""
|
||||
Create a new instance.
|
||||
Args:
|
||||
url (str): The URL to the Akaunting api.
|
||||
username (str): The username of the Akaunting credentials.
|
||||
password (str): The password of the Akaunting credentials.
|
||||
url (str): The URL to the Akaunting api. ** required **
|
||||
username (str): The username of the Akaunting credentials. ** required **
|
||||
password (str): The password of the Akaunting credentials. ** required **
|
||||
company_id (str): The company ID from Akaunting
|
||||
currency_code (str): The currency code. default is NZD
|
||||
currency_rate (str): The currency rate. default is "1.0"
|
||||
"""
|
||||
self.url = url
|
||||
self.ssl_verify = ssl_verify
|
||||
self.authentication = HTTPBasicAuth(username, password)
|
||||
self.headers = {
|
||||
'User-Agent': 'AkauntingPy v' + __version__,
|
||||
@@ -44,7 +49,8 @@ class Client(object):
|
||||
url=self.url + "/" + endpoint,
|
||||
headers=self.headers,
|
||||
auth=self.authentication,
|
||||
params=MergeDict(self.default_params, params)
|
||||
params=MergeDict(self.default_params, params),
|
||||
verify=self.ssl_verify
|
||||
)
|
||||
|
||||
response_ = response.json()
|
||||
@@ -73,17 +79,45 @@ class Client(object):
|
||||
|
||||
if params.get('search', False):
|
||||
# Check if there is an account returned
|
||||
if data['meta']['pagination'].get('count') == 0:
|
||||
# No account found
|
||||
raise exceptions.AccountNotFound("Sorry, account not found matching search parameters: %s".format(
|
||||
params.get('search')
|
||||
))
|
||||
try:
|
||||
if data['meta']['pagination'].get('count') == 0:
|
||||
# No account found
|
||||
raise exceptions.AccountNotFound("Sorry, account not found matching search parameters: %s".format(
|
||||
params.get('search')
|
||||
))
|
||||
except KeyError as e:
|
||||
# New API 3.0
|
||||
if data['meta']['total'] == 0:
|
||||
raise exceptions.AccountNotFound("Sorry, account not found matching search parameters: %s".format(
|
||||
params.get('search')
|
||||
))
|
||||
|
||||
return data['data']
|
||||
|
||||
def get_contact(self, **params):
|
||||
data = self.call(endpoint="contacts", **params)
|
||||
print(data)
|
||||
if params.get('search', False):
|
||||
try:
|
||||
# Check if there is an account returned
|
||||
if data['meta']['pagination'].get('count') == 0:
|
||||
# No account found
|
||||
raise exceptions.AccountNotFound("Sorry, contact not found matching search parameters: %s".format(
|
||||
params.get('search')
|
||||
))
|
||||
except KeyError as e:
|
||||
# New API 3.0
|
||||
if data['meta']['total'] == 0:
|
||||
raise exceptions.AccountNotFound("Sorry, contact not found matching search parameters: %s".format(
|
||||
params.get('search')
|
||||
))
|
||||
|
||||
return data['data']
|
||||
|
||||
def create_transaction(self,
|
||||
transaction_type='income', # Payment method type
|
||||
account_id=None, # Account ID to assign
|
||||
number="NULL", # Transaction number
|
||||
category_id=None, # Category ID to assign
|
||||
contact_id=None, # Contact ID/Client to assign
|
||||
description=None, # Description
|
||||
@@ -106,6 +140,7 @@ class Client(object):
|
||||
data = self.call(endpoint="transactions",
|
||||
method="POST",
|
||||
search="type:" + transaction_type,
|
||||
number=number,
|
||||
type=transaction_type,
|
||||
account_id=account_id,
|
||||
category_id=category_id,
|
||||
@@ -121,18 +156,17 @@ class Client(object):
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
def create_transfer(self,
|
||||
from_account_id=None, # Account ID to create transfer from
|
||||
to_account_id=None, # Account ID to create transfer to
|
||||
transferred_at=None, # Date of expense/transfer or income
|
||||
payment_method="Bank Transfer", # Payment method
|
||||
amount=None, # Amount received/paid
|
||||
**params # Any additional parameters
|
||||
):
|
||||
|
||||
data = self.call(endpoint="transfers",
|
||||
method="POST",
|
||||
from_account_id=None, # Account ID to create transfer from
|
||||
to_account_id=None, # Account ID to create transfer to
|
||||
transferred_at=None, # Date of expense/transfer or income
|
||||
payment_method="Bank Transfer", # Payment method
|
||||
amount=None, # Amount received/paid
|
||||
**params # Any additional parameters
|
||||
):
|
||||
|
||||
data = self.call(endpoint="transfers",
|
||||
method="POST",
|
||||
from_account_id=from_account_id,
|
||||
to_account_id=to_account_id,
|
||||
transferred_at=transferred_at,
|
||||
@@ -140,4 +174,4 @@ class Client(object):
|
||||
amount=EnsurePositiveInteger(amount),
|
||||
**params
|
||||
)
|
||||
return data
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user