-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from jakubczaplicki/credit_card_payment
Add support for CreditCardPayment entity
- Loading branch information
Showing
4 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from six import python_2_unicode_compatible | ||
from .base import Ref, QuickbooksManagedObject, QuickbooksTransactionEntity, LinkedTxnMixin | ||
from ..mixins import DeleteMixin | ||
|
||
|
||
@python_2_unicode_compatible | ||
class CreditCardPayment(DeleteMixin, QuickbooksManagedObject, QuickbooksTransactionEntity, LinkedTxnMixin): | ||
""" | ||
QBO definition: A Represents a financial transaction to record a Credit Card balance payment | ||
in QuickBooks Online. It provides an easy way for users to move money from a Bank account to | ||
a Credit Card account. It is essentially a more limited Transfer form. | ||
Added in QuickBooks Online v1928, Date: February 13, 2020 | ||
https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/creditcardpayment | ||
""" | ||
class_dict = { | ||
"BankAccountRef": Ref, | ||
"CreditCardAccountRef": Ref, | ||
} | ||
|
||
qbo_object_name = "CreditCardPayment" | ||
|
||
def __init__(self): | ||
super(CreditCardPayment, self).__init__() | ||
self.TxnDate = None | ||
self.Amount = 0 | ||
self.PrivateNote = None | ||
|
||
self.BankAccountRef = None | ||
self.CreditCardAccountRef = None | ||
|
||
def __str__(self): | ||
return str(self.Amount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import time | ||
from datetime import datetime | ||
|
||
from quickbooks.objects import Transfer | ||
from quickbooks.objects.account import Account | ||
from quickbooks.objects.creditcardpayment_entity import CreditCardPayment | ||
from tests.integration.test_base import QuickbooksTestCase | ||
|
||
|
||
class CreditCardPaymentEntityTest(QuickbooksTestCase): | ||
def setUp(self): | ||
time.sleep(3) # Used to prevent error code 3001 - The request limit was reached. | ||
super(CreditCardPaymentEntityTest, self).setUp() | ||
|
||
self.account_number = datetime.now().strftime('%d%H%M') | ||
self.name = "Test CreditCardPaymentEntityTest {0}".format(self.account_number) | ||
|
||
def test_create(self): | ||
credit_card_account = Account() | ||
credit_card_account.Name = "Credit Card Account {0}".format(self.account_number) | ||
credit_card_account.AccountType = "Credit Card" | ||
credit_card_account.AccountSubType = "CreditCard" | ||
credit_card_account.save(qb=self.qb_client) | ||
|
||
accounts = Account.where( | ||
"Classification = 'Asset' AND FullyQualifiedName != 'Accounts Receivable (A/R)'", | ||
max_results=1, qb=self.qb_client) | ||
|
||
from_account = accounts[0] | ||
to_account = credit_card_account | ||
|
||
credit_card_payment = CreditCardPayment() | ||
credit_card_payment.Amount = 100 | ||
credit_card_payment.BankAccountRef = from_account.to_ref() | ||
credit_card_payment.CreditCardAccountRef = to_account.to_ref() | ||
|
||
credit_card_payment.save(qb=self.qb_client) | ||
|
||
query_credit_card_payment = CreditCardPayment.get(credit_card_payment.Id, qb=self.qb_client) | ||
|
||
self.assertEquals(query_credit_card_payment.Id, credit_card_payment.Id) | ||
self.assertEquals(query_credit_card_payment.Amount, 100) | ||
self.assertEquals(query_credit_card_payment.BankAccountRef.value, from_account.Id) | ||
self.assertEquals(query_credit_card_payment.CreditCardAccountRef.value, to_account.Id) | ||
|
||
# reset transfer (so the from_account doesn't run out of cash) | ||
# I wonder if we can do a transfer from credit_card_account to a bank_account | ||
transfer = Transfer() | ||
transfer.Amount = 100 | ||
transfer.FromAccountRef = to_account.to_ref() | ||
transfer.ToAccountRef = from_account.to_ref() | ||
|
||
transfer.save(qb=self.qb_client) | ||
|
||
def test_update(self): | ||
credit_card_payment = CreditCardPayment.all(max_results=1, qb=self.qb_client)[0] | ||
credit_card_payment.Amount += 1 | ||
credit_card_payment.save(qb=self.qb_client) | ||
|
||
query_credit_card_payment = CreditCardPayment.get(credit_card_payment.Id, qb=self.qb_client) | ||
|
||
self.assertEquals(query_credit_card_payment.Amount, credit_card_payment.Amount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import unittest | ||
|
||
from quickbooks import QuickBooks | ||
from quickbooks.objects.creditcardpayment_entity import CreditCardPayment | ||
|
||
|
||
class TaxAgencyTests(unittest.TestCase): | ||
def test_unicode(self): | ||
credit_card_payment = CreditCardPayment() | ||
credit_card_payment.Amount = 100 | ||
|
||
self.assertEquals(str(credit_card_payment), "100") | ||
|
||
def test_valid_object_name(self): | ||
obj = CreditCardPayment() | ||
client = QuickBooks() | ||
result = client.isvalid_object_name(obj.qbo_object_name) | ||
|
||
self.assertTrue(result) |