Added setuptools_scm to requirements

This commit is contained in:
2022-05-27 23:00:35 +12:00
parent 6a03577605
commit e0e803f1a7
9 changed files with 85 additions and 37 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

15
.idea/akaunting-py.iml generated Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
<excludeFolder url="file://$MODULE_DIR$/.pytest_cache" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (akaunting-py)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/akaunting-py.iml" filepath="$PROJECT_DIR$/.idea/akaunting-py.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -1,19 +1,18 @@
from importlib.metadata import version, PackageNotFoundError
from unittest.mock import seal
import requests import requests
import json
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from akauntingpy.helpers import *
from akauntingpy import exceptions
from setuptools_scm import get_version from setuptools_scm import get_version
from akauntingpy import exceptions
from akauntingpy.helpers import *
__version__ = get_version(root='..', relative_to=__file__) __version__ = get_version(root='..', relative_to=__file__)
class Client(object): class Client(object):
""" """
Akaunting interface. Akaunting interface.
""" """
def __init__( def __init__(
self, self,
url, url,
@@ -38,18 +37,18 @@ class Client(object):
self.default_params = {'company_id': company_id} self.default_params = {'company_id': company_id}
self.currency_code = currency_code self.currency_code = currency_code
self.currency_rate = currency_rate self.currency_rate = currency_rate
def call(self, method="get", endpoint=None, def call(self, method="get", endpoint=None,
**params) -> dict(): **params) -> dict():
response = None response = None
response = requests.request(method=method, response = requests.request(method=method,
url=self.url + "/" + endpoint, url=self.url + "/" + endpoint,
headers=self.headers, headers=self.headers,
auth=self.authentication, auth=self.authentication,
params=MergeDict(self.default_params, params) params=MergeDict(self.default_params, params)
) )
print(response) print(response)
response_ = response.json() response_ = response.json()
print(response_) print(response_)
@@ -59,23 +58,23 @@ class Client(object):
elif response.status_code == 422: elif response.status_code == 422:
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]) response_['errors'][key][0])
+ " (" + key + ")") + " (" + 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): def get_accounts(self, **params):
data = self.call(endpoint="accounts", **params) data = self.call(endpoint="accounts", **params)
if params.get('search', False): if params.get('search', False):
# Check if there is an account returned # Check if there is an account returned
if data['meta']['pagination'].get('count') == 0: if data['meta']['pagination'].get('count') == 0:
@@ -83,33 +82,33 @@ class Client(object):
raise exceptions.AccountNotFound("Sorry, account not found matching search parameters: %s".format( raise exceptions.AccountNotFound("Sorry, account not found matching search parameters: %s".format(
params.get('search') params.get('search')
)) ))
return data['data'] return data['data']
def create_transaction(self, def create_transaction(self,
type='income', # Payment method type type='income', # Payment method type
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 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
currency_code=None, # Currency code currency_code=None, # Currency code
currency_rate=None,# Currency rate currency_rate=None, # Currency rate
amount=None, # Amount received/paid amount=None, # Amount received/paid
**params # Any additional parameters **params # Any additional parameters
): ):
if currency_code is None: if currency_code is None:
# Set default value from class # Set default value from class
currency_code = self.currency_code currency_code = self.currency_code
if currency_rate is None: if currency_rate is None:
# Set default value from class # Set default value from class
currency_rate = self.currency_rate currency_rate = self.currency_rate
data = self.call(endpoint="transactions", data = self.call(endpoint="transactions",
method="POST", method="POST",
search="type:" + type, search="type:" + type,
type=type, type=type,
account_id=account_id, account_id=account_id,
@@ -124,4 +123,4 @@ class Client(object):
description=description, description=description,
**params **params
) )
return data return data

View File

@@ -1,4 +1,5 @@
requests ~= 2.27.0 requests ~= 2.27.0
requests-mock ~= 1.9.3 requests-mock ~= 1.9.3
pytest ~= 7.1.2 pytest ~= 7.1.2
pytest-cov ~= 3.0.0 pytest-cov ~= 3.0
setuptools-scm ~= 6.4.2

View File

@@ -20,6 +20,7 @@ setup(
packages=find_packages(), packages=find_packages(),
install_requires=[ install_requires=[
'requests >= 2.21.0', 'requests >= 2.21.0',
'setuptools-scm >= 6.4.2'
], ],
classifiers=[ classifiers=[
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',