Skip to content

Commit

Permalink
Merge pull request #202 from jakubczaplicki/credit_card_payment
Browse files Browse the repository at this point in the history
Add support for CreditCardPayment entity
  • Loading branch information
ej2 authored Oct 11, 2020
2 parents acfe638 + d162a3c commit 885fcfa
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion quickbooks/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class QuickBooks(object):
"Item", "JournalEntry", "Payment", "PaymentMethod",
"Purchase", "PurchaseOrder", "RefundReceipt",
"SalesReceipt", "TaxAgency", "TaxCode", "TaxService/Taxcode", "TaxRate", "Term",
"TimeActivity", "Transfer", "Vendor", "VendorCredit"
"TimeActivity", "Transfer", "Vendor", "VendorCredit", "CreditCardPayment",
]

__instance = None
Expand Down
34 changes: 34 additions & 0 deletions quickbooks/objects/creditcardpayment_entity.py
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)
62 changes: 62 additions & 0 deletions tests/integration/test_creditcardpayment_entity.py
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)
19 changes: 19 additions & 0 deletions tests/unit/objects/test_creditcardpayment_entity.py
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)

0 comments on commit 885fcfa

Please sign in to comment.