88
99class InvoiceTest (QuickbooksTestCase ):
1010
11- def create_invoice (self , request_id = None ):
11+ def create_invoice (self , customer , request_id = None ):
1212 invoice = Invoice ()
1313
1414 line = SalesItemLine ()
@@ -21,15 +21,16 @@ def create_invoice(self, request_id=None):
2121 line .SalesItemLineDetail .ItemRef = item .to_ref ()
2222 invoice .Line .append (line )
2323
24- customer = Customer .all (max_results = 1 , qb = self .qb_client )[0 ]
2524 invoice .CustomerRef = customer .to_ref ()
2625
2726 invoice .CustomerMemo = CustomerMemo ()
2827 invoice .CustomerMemo .value = "Customer Memo"
2928 invoice .save (qb = self .qb_client , request_id = request_id )
29+ return invoice
3030
3131 def test_create (self ):
32- invoice = self .create_invoice ()
32+ customer = Customer .all (max_results = 1 , qb = self .qb_client )[0 ]
33+ invoice = self .create_invoice (customer )
3334 query_invoice = Invoice .get (invoice .Id , qb = self .qb_client )
3435
3536 self .assertEquals (query_invoice .CustomerRef .name , customer .DisplayName )
@@ -38,16 +39,18 @@ def test_create(self):
3839 self .assertEquals (query_invoice .Line [0 ].Amount , 100.0 )
3940
4041 def test_create_idempotence (self ):
42+ customer = Customer .all (max_results = 1 , qb = self .qb_client )[0 ]
4143 sample_request_id = str (uuid .uuid4 ())
42- invoice = self .create_invoice (request_id = sample_request_id )
43- duplicate_invoice = self .create_invoice (request_id = sample_request_id )
44+ invoice = self .create_invoice (customer , request_id = sample_request_id )
45+ duplicate_invoice = self .create_invoice (customer , request_id = sample_request_id )
4446
4547 # Assert that both returned invoices have the same id
4648 self .assertEquals (invoice .Id , duplicate_invoice .Id )
4749
4850 def test_delete (self ):
51+ customer = Customer .all (max_results = 1 , qb = self .qb_client )[0 ]
4952 # First create an invoice
50- invoice = self .create_invoice ()
53+ invoice = self .create_invoice (customer )
5154
5255 # Then delete
5356 invoice_id = invoice .Id
0 commit comments