|
| 1 | +import time |
| 2 | +from datetime import datetime |
| 3 | + |
| 4 | +from quickbooks.objects import Transfer |
| 5 | +from quickbooks.objects.account import Account |
| 6 | +from quickbooks.objects.creditcardpayment_entity import CreditCardPayment |
| 7 | +from tests.integration.test_base import QuickbooksTestCase |
| 8 | + |
| 9 | + |
| 10 | +class CreditCardPaymentEntityTest(QuickbooksTestCase): |
| 11 | + def setUp(self): |
| 12 | + time.sleep(3) # Used to prevent error code 3001 - The request limit was reached. |
| 13 | + super(CreditCardPaymentEntityTest, self).setUp() |
| 14 | + |
| 15 | + self.account_number = datetime.now().strftime('%d%H%M') |
| 16 | + self.name = "Test CreditCardPaymentEntityTest {0}".format(self.account_number) |
| 17 | + |
| 18 | + def test_create(self): |
| 19 | + credit_card_account = Account() |
| 20 | + credit_card_account.Name = "Credit Card Account {0}".format(self.account_number) |
| 21 | + credit_card_account.AccountType = "Credit Card" |
| 22 | + credit_card_account.AccountSubType = "CreditCard" |
| 23 | + credit_card_account.save(qb=self.qb_client) |
| 24 | + |
| 25 | + accounts = Account.where( |
| 26 | + "Classification = 'Asset' AND FullyQualifiedName != 'Accounts Receivable (A/R)'", |
| 27 | + max_results=1, qb=self.qb_client) |
| 28 | + |
| 29 | + from_account = accounts[0] |
| 30 | + to_account = credit_card_account |
| 31 | + |
| 32 | + credit_card_payment = CreditCardPayment() |
| 33 | + credit_card_payment.Amount = 100 |
| 34 | + credit_card_payment.BankAccountRef = from_account.to_ref() |
| 35 | + credit_card_payment.CreditCardAccountRef = to_account.to_ref() |
| 36 | + |
| 37 | + credit_card_payment.save(qb=self.qb_client) |
| 38 | + |
| 39 | + query_credit_card_payment = CreditCardPayment.get(credit_card_payment.Id, qb=self.qb_client) |
| 40 | + |
| 41 | + self.assertEquals(query_credit_card_payment.Id, credit_card_payment.Id) |
| 42 | + self.assertEquals(query_credit_card_payment.Amount, 100) |
| 43 | + self.assertEquals(query_credit_card_payment.BankAccountRef.value, from_account.Id) |
| 44 | + self.assertEquals(query_credit_card_payment.CreditCardAccountRef.value, to_account.Id) |
| 45 | + |
| 46 | + # reset transfer (so the from_account doesn't run out of cash) |
| 47 | + # I wonder if we can do a transfer from credit_card_account to a bank_account |
| 48 | + transfer = Transfer() |
| 49 | + transfer.Amount = 100 |
| 50 | + transfer.FromAccountRef = to_account.to_ref() |
| 51 | + transfer.ToAccountRef = from_account.to_ref() |
| 52 | + |
| 53 | + transfer.save(qb=self.qb_client) |
| 54 | + |
| 55 | + def test_update(self): |
| 56 | + credit_card_payment = CreditCardPayment.all(max_results=1, qb=self.qb_client)[0] |
| 57 | + credit_card_payment.Amount += 1 |
| 58 | + credit_card_payment.save(qb=self.qb_client) |
| 59 | + |
| 60 | + query_credit_card_payment = CreditCardPayment.get(credit_card_payment.Id, qb=self.qb_client) |
| 61 | + |
| 62 | + self.assertEquals(query_credit_card_payment.Amount, credit_card_payment.Amount) |
0 commit comments