1
1
from datetime import datetime
2
2
3
+ from quickbooks .objects import AccountBasedExpenseLine , Ref , AccountBasedExpenseLineDetail
3
4
from quickbooks .objects .account import Account
4
5
from quickbooks .objects .bill import Bill
5
6
from quickbooks .objects .billpayment import BillPayment , BillPaymentLine , CheckPayment
@@ -14,12 +15,30 @@ def setUp(self):
14
15
self .account_number = datetime .now ().strftime ('%d%H%M' )
15
16
self .name = "Test Account {0}" .format (self .account_number )
16
17
17
- def test_create (self ):
18
+ def create_bill (self , amount ):
19
+ bill = Bill ()
20
+ line = AccountBasedExpenseLine ()
21
+ line .Amount = amount
22
+ line .DetailType = "AccountBasedExpenseLineDetail"
23
+
24
+ account_ref = Ref ()
25
+ account_ref .type = "Account"
26
+ account_ref .value = 1
27
+ line .AccountBasedExpenseLineDetail = AccountBasedExpenseLineDetail ()
28
+ line .AccountBasedExpenseLineDetail .AccountRef = account_ref
29
+ bill .Line .append (line )
30
+
31
+ vendor = Vendor .all (max_results = 1 , qb = self .qb_client )[0 ]
32
+ bill .VendorRef = vendor .to_ref ()
33
+
34
+ return bill .save (qb = self .qb_client )
35
+
36
+ def create_bill_payment (self , bill , amount , private_note , pay_type ):
18
37
bill_payment = BillPayment ()
19
38
20
- bill_payment .PayType = "Check"
21
- bill_payment .TotalAmt = 200
22
- bill_payment .PrivateNote = "Private Note"
39
+ bill_payment .PayType = pay_type
40
+ bill_payment .TotalAmt = amount
41
+ bill_payment .PrivateNote = private_note
23
42
24
43
vendor = Vendor .all (max_results = 1 , qb = self .qb_client )[0 ]
25
44
bill_payment .VendorRef = vendor .to_ref ()
@@ -31,14 +50,18 @@ def test_create(self):
31
50
ap_account = Account .where ("AccountSubType = 'AccountsPayable'" , qb = self .qb_client )[0 ]
32
51
bill_payment .APAccountRef = ap_account .to_ref ()
33
52
34
- bill = Bill .all (max_results = 1 , qb = self .qb_client )[0 ]
35
-
36
53
line = BillPaymentLine ()
37
54
line .LinkedTxn .append (bill .to_linked_txn ())
38
55
line .Amount = 200
39
56
40
57
bill_payment .Line .append (line )
41
- bill_payment .save (qb = self .qb_client )
58
+ return bill_payment .save (qb = self .qb_client )
59
+
60
+ def test_create (self ):
61
+ # create new bill for testing, reusing the same bill will cause Line to be empty
62
+ # and the new bill payment will be voided automatically
63
+ bill = self .create_bill (amount = 200 )
64
+ bill_payment = self .create_bill_payment (bill , 200 , "Private Note" , "Check" )
42
65
43
66
query_bill_payment = BillPayment .get (bill_payment .Id , qb = self .qb_client )
44
67
@@ -48,3 +71,16 @@ def test_create(self):
48
71
49
72
self .assertEqual (len (query_bill_payment .Line ), 1 )
50
73
self .assertEqual (query_bill_payment .Line [0 ].Amount , 200.0 )
74
+
75
+ def test_void (self ):
76
+ bill = self .create_bill (amount = 200 )
77
+ bill_payment = self .create_bill_payment (bill , 200 , "Private Note" , "Check" )
78
+ query_payment = BillPayment .get (bill_payment .Id , qb = self .qb_client )
79
+ self .assertEqual (query_payment .TotalAmt , 200.0 )
80
+ self .assertNotIn ('Voided' , query_payment .PrivateNote )
81
+
82
+ bill_payment .void (qb = self .qb_client )
83
+ query_payment = BillPayment .get (bill_payment .Id , qb = self .qb_client )
84
+
85
+ self .assertEqual (query_payment .TotalAmt , 0.0 )
86
+ self .assertIn ('Voided' , query_payment .PrivateNote )
0 commit comments