11from datetime import datetime
22
3+ from quickbooks .objects import AccountBasedExpenseLine , Ref , AccountBasedExpenseLineDetail
34from quickbooks .objects .account import Account
45from quickbooks .objects .bill import Bill
56from quickbooks .objects .billpayment import BillPayment , BillPaymentLine , CheckPayment
@@ -14,12 +15,30 @@ def setUp(self):
1415 self .account_number = datetime .now ().strftime ('%d%H%M' )
1516 self .name = "Test Account {0}" .format (self .account_number )
1617
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 ):
1837 bill_payment = BillPayment ()
1938
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
2342
2443 vendor = Vendor .all (max_results = 1 , qb = self .qb_client )[0 ]
2544 bill_payment .VendorRef = vendor .to_ref ()
@@ -31,14 +50,18 @@ def test_create(self):
3150 ap_account = Account .where ("AccountSubType = 'AccountsPayable'" , qb = self .qb_client )[0 ]
3251 bill_payment .APAccountRef = ap_account .to_ref ()
3352
34- bill = Bill .all (max_results = 1 , qb = self .qb_client )[0 ]
35-
3653 line = BillPaymentLine ()
3754 line .LinkedTxn .append (bill .to_linked_txn ())
3855 line .Amount = 200
3956
4057 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" )
4265
4366 query_bill_payment = BillPayment .get (bill_payment .Id , qb = self .qb_client )
4467
@@ -48,3 +71,16 @@ def test_create(self):
4871
4972 self .assertEqual (len (query_bill_payment .Line ), 1 )
5073 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