Skip to content

Commit aa6db2a

Browse files
committed
Added tests for invoice and billpayment.
1 parent 219a953 commit aa6db2a

File tree

6 files changed

+112
-17
lines changed

6 files changed

+112
-17
lines changed

quickbooks/objects/bill.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class Bill(QuickbooksManagedObject, QuickbooksTransactionEntity, LinkedTxnMixin)
9898

9999
list_dict = {
100100
"Line": BillLine,
101-
"LinkedTxn": LinkedTxn
102101
}
103102

104103
qbo_object_name = "Bill"
@@ -127,3 +126,11 @@ def __init__(self):
127126

128127
def __str__(self):
129128
return str(self.Balance)
129+
130+
def to_linked_txn(self):
131+
linked_txn = LinkedTxn()
132+
linked_txn.TxnId = self.Id
133+
linked_txn.TxnType = "Bill"
134+
linked_txn.TxnLineId = 1
135+
136+
return linked_txn

quickbooks/objects/billpayment.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CheckPayment(QuickbooksBaseObject):
1313

1414
def __init__(self):
1515
super(CheckPayment, self).__init__()
16-
self.PrintStatus = ""
16+
self.PrintStatus = "NotSet"
1717
self.BankAccountRef = None
1818

1919
def __str__(self):
@@ -80,10 +80,9 @@ def __init__(self):
8080
super(BillPayment, self).__init__()
8181
self.PayType = ""
8282
self.TotalAmt = 0
83-
self.TxnDate = ""
8483
self.PrivateNote = ""
8584
self.DocNumber = ""
86-
self.ProcessBillPayment = False
85+
#self.ProcessBillPayment = False
8786

8887
self.VendorRef = None
8988
self.CheckPayment = None

tests/integration_tests/test_bill.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
from datetime import datetime
2-
import os
31
import unittest
4-
from quickbooks.client import QuickBooks
5-
from quickbooks.objects.bill import Bill, BillLine, AccountBasedExpenseLineDetail
2+
from datetime import datetime
3+
64
from quickbooks.objects.base import Ref
5+
from quickbooks.objects.bill import Bill, BillLine, AccountBasedExpenseLineDetail
76
from quickbooks.objects.vendor import Vendor
87

98

10-
class AccountTest(unittest.TestCase):
9+
class BillTest(unittest.TestCase):
1110
def setUp(self):
12-
QuickBooks(
13-
sandbox=True,
14-
consumer_key=os.environ.get('CONSUMER_KEY'),
15-
consumer_secret=os.environ.get('CONSUMER_SECRET'),
16-
access_token=os.environ.get('ACCESS_TOKEN'),
17-
access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'),
18-
company_id=os.environ.get('COMPANY_ID')
19-
)
2011

2112
self.account_number = datetime.now().strftime('%d%H%M')
2213
self.name = "Test Account {0}".format(self.account_number)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import unittest
2+
from datetime import datetime
3+
4+
from quickbooks.objects.creditcardpayment import CreditCardPayment
5+
from quickbooks.objects.account import Account
6+
from quickbooks.objects.bill import Bill
7+
from quickbooks.objects.billpayment import BillPayment, BillPaymentLine
8+
from quickbooks.objects.base import Ref
9+
from quickbooks.objects.vendor import Vendor
10+
11+
12+
class BillPaymentTest(unittest.TestCase):
13+
def setUp(self):
14+
15+
self.account_number = datetime.now().strftime('%d%H%M')
16+
self.name = "Test Account {0}".format(self.account_number)
17+
18+
def test_create(self):
19+
bill_payment = BillPayment()
20+
21+
bill_payment.PayType = "CreditCard"
22+
bill_payment.TotalAmt = 200
23+
bill_payment.PrivateNote = "Private Note"
24+
25+
vendor = Vendor.all(max_results=1)[0]
26+
bill_payment.VendorRef = vendor.to_ref()
27+
28+
bill_payment.CreditCardPayment = CreditCardPayment()
29+
30+
#account = Account.all(max_results=1)[0]
31+
#bill_payment.CreditCardPayment.CCAccountRef = account.to_ref()
32+
33+
ap_account = Account.where("AccountSubType = 'AccountsPayable'")[0]
34+
bill_payment.APAccountRef = ap_account.to_ref()
35+
36+
bill = Bill.all(max_results=1)[0]
37+
38+
line = BillPaymentLine()
39+
line.LinkedTxn.append(bill.to_linked_txn())
40+
line.Amount = 200
41+
42+
bill_payment.Line.append(line)
43+
bill_payment.save()
44+
45+
query_bill_payment = BillPayment.get(bill_payment.Id)
46+
47+
self.assertEquals(query_bill_payment.PayType, "Check")
48+
self.assertEquals(query_bill_payment.TotalAmt, 200.0)
49+
self.assertEquals(query_bill_payment.PrivateNote,"Private Note")
50+
51+
self.assertEquals(len(query_bill_payment.Line), 1)
52+
self.assertEquals(query_bill_payment.Line[0].Amount, 200.0)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import unittest
2+
3+
from quickbooks.objects.customer import Customer
4+
from quickbooks.objects.detailline import SaleItemLine, SalesItemLineDetail
5+
from quickbooks.objects.invoice import Invoice
6+
from quickbooks.objects.item import Item
7+
from quickbooks.objects.base import CustomerMemo
8+
9+
10+
class InvoiceTest(unittest.TestCase):
11+
def test_create(self):
12+
invoice = Invoice()
13+
14+
line = SaleItemLine()
15+
line.LineNum = 1
16+
line.Description = "description"
17+
line.Amount = 100
18+
line.SalesItemLineDetail = SalesItemLineDetail()
19+
item = Item.all(max_results=1)[0]
20+
21+
line.SalesItemLineDetail.ItemRef = item.to_ref()
22+
invoice.Line.append(line)
23+
24+
customer = Customer.all(max_results=1)[0]
25+
invoice.CustomerRef = customer.to_ref()
26+
27+
invoice.CustomerMemo = CustomerMemo()
28+
invoice.CustomerMemo.value = "Customer Memo"
29+
invoice.save()
30+
31+
query_invoice = Invoice.get(invoice.Id)
32+
33+
self.assertEquals(query_invoice.CustomerRef.name, customer.DisplayName)
34+
self.assertEquals(query_invoice.CustomerMemo.value, "Customer Memo")
35+
self.assertEquals(query_invoice.Line[0].Description, "description")
36+
self.assertEquals(query_invoice.Line[0].Amount, 100.0)

tests/unit/objects/test_bill.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ def test_unicode(self):
1818

1919
self.assertEquals(str(bill), "1000")
2020

21+
def test_to_LinkedTxn(self):
22+
bill = Bill()
23+
bill.Id = 10
24+
25+
linked_txn = bill.to_linked_txn()
26+
27+
self.assertEquals(linked_txn.TxnId, bill.Id)
28+
self.assertEquals(linked_txn.TxnType, "Bill")
29+
self.assertEquals(linked_txn.TxnLineId, 1)
30+
2131

2232
class BillLineTests(unittest.TestCase):
2333
def test_unicode(self):

0 commit comments

Comments
 (0)