You've already forked akaunting-py
Added create transfer
This commit is contained in:
@@ -116,8 +116,29 @@ class Client(object):
|
||||
reference=reference,
|
||||
currency_code=currency_code,
|
||||
currency_rate=currency_rate,
|
||||
amount=amount,
|
||||
amount=EnsurePositiveInteger(amount),
|
||||
description=description,
|
||||
**params
|
||||
)
|
||||
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=from_account_id,
|
||||
to_account_id=to_account_id,
|
||||
transferred_at=transferred_at,
|
||||
payment_method=payment_method,
|
||||
amount=EnsurePositiveInteger(amount),
|
||||
**params
|
||||
)
|
||||
return data
|
||||
@@ -6,4 +6,7 @@ def MergeDict(dict1, dict2):
|
||||
def RemoveFromString(items, string):
|
||||
for item in items:
|
||||
string = string.replace(item, '')
|
||||
return string
|
||||
return string
|
||||
|
||||
def EnsurePositiveInteger(number):
|
||||
return float(number) if float(number) > 0 else (float(number) * -1)
|
||||
17
data/CreateTransferSuccess.json
Normal file
17
data/CreateTransferSuccess.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"data":{
|
||||
"id":2,
|
||||
"company_id":1,
|
||||
"from_account":"Some Account",
|
||||
"from_account_id":1,
|
||||
"to_account":"Some Account New",
|
||||
"to_account_id":2,
|
||||
"paid_at":"2022-05-16T11:57:51+12:00",
|
||||
"amount":100,
|
||||
"amount_formatted":"$100.00",
|
||||
"currency_code":"NZD",
|
||||
"created_by":1,
|
||||
"created_at":"2022-05-16T11:57:51+12:00",
|
||||
"updated_at":"2022-05-16T11:57:51+12:00"
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ class TestAPI:
|
||||
|
||||
def test_create_transaction_expense_success(self, setUp, requests_mock):
|
||||
c = setUp
|
||||
requests_mock.post(c.url + "/transactions",
|
||||
requests_mock.post(c.url + "/transactions?search=type%3Aexpense&type=expense&account_id=3&category_id=4&paid_at=2022-05-16&payment_method=Bank+Transfer¤cy_code=NZD¤cy_rate=1&amount=100.0&description=Some+expenditures&company_id=1",
|
||||
json=RetrieveJSONFromFile("data/CreateTransactionExpenseSuccess.json"),
|
||||
status_code=201)
|
||||
data = c.create_transaction(transaction_type="expense",
|
||||
@@ -158,3 +158,19 @@ class TestAPI:
|
||||
category_id="4",
|
||||
description="Some expenditures"
|
||||
)
|
||||
|
||||
|
||||
def test_create_transfer_success(self, setUp, requests_mock):
|
||||
c = setUp
|
||||
requests_mock.post(c.url + "/transfers",
|
||||
json=RetrieveJSONFromFile("data/CreateTransferSuccess.json"),
|
||||
status_code=201)
|
||||
data = c.create_transfer( amount=100.00,
|
||||
account_id=3,
|
||||
paid_at="2022-05-16",
|
||||
currency_rate=1,
|
||||
currency_code="NZD",
|
||||
payment_method="Bank Transfer",
|
||||
category_id="4",
|
||||
description="Some expenditures"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user