1+ from datetime import datetime
2+
13from quickbooks .objects .base import CustomerMemo
24from quickbooks .objects .customer import Customer
35from quickbooks .objects .detailline import SalesItemLine , SalesItemLineDetail
46from quickbooks .objects .invoice import Invoice
57from quickbooks .objects .item import Item
8+ from quickbooks .objects .base import EmailAddress
69from tests .integration .test_base import QuickbooksTestCase
710import uuid
811
9- class InvoiceTest (QuickbooksTestCase ):
10- def create_invoice (self , customer , request_id = None ):
11- invoice = Invoice ()
1212
13+ class InvoiceTest (QuickbooksTestCase ):
14+ def create_invoice_line (self ):
1315 line = SalesItemLine ()
1416 line .LineNum = 1
1517 line .Description = "description"
@@ -18,7 +20,11 @@ def create_invoice(self, customer, request_id=None):
1820 item = Item .all (max_results = 1 , qb = self .qb_client )[0 ]
1921
2022 line .SalesItemLineDetail .ItemRef = item .to_ref ()
21- invoice .Line .append (line )
23+ return line
24+
25+ def create_invoice (self , customer , request_id = None ):
26+ invoice = Invoice ()
27+ invoice .Line .append (self .create_invoice_line ())
2228
2329 invoice .CustomerRef = customer .to_ref ()
2430
@@ -86,3 +92,34 @@ def test_void(self):
8692 self .assertEqual (query_invoice .Balance , 0.0 )
8793 self .assertEqual (query_invoice .TotalAmt , 0.0 )
8894 self .assertIn ('Voided' , query_invoice .PrivateNote )
95+
96+ def test_invoice_link (self ):
97+ # Sharable link for the invoice sent to external customers.
98+ # The link is generated only for invoices with online payment enabled and having a valid customer email address.
99+ # Include query param `include=invoiceLink` to get the link back on query response.
100+
101+ # Create test customer
102+ customer_name = datetime .now ().strftime ('%d%H%M%S' )
103+ customer = Customer ()
104+ customer .DisplayName = customer_name
105+ customer .save (qb = self .qb_client )
106+
107+ # Create an invoice with sharable link flags set
108+ invoice = Invoice ()
109+ invoice .CustomerRef = customer .to_ref ()
110+ invoice .DueDate = '2024-12-31'
111+ invoice .AllowOnlineCreditCardPayment = True
112+ invoice .AllowOnlineACHPayment = True
113+ invoice .Line .append (self .create_invoice_line ())
114+
115+ # BillEmail must be set for Sharable link to work!
116+ invoice .BillEmail = EmailAddress ()
117+ invoice .BillEmail .Address = 'test@email.com'
118+
119+ invoice .save (qb = self .qb_client )
120+
121+ # You must add 'include': 'invoiceLink' to the params when doing a query for the invoice
122+ query_invoice = Invoice .get (invoice .Id , qb = self .qb_client , params = {'include' : 'invoiceLink' })
123+
124+ self .assertIsNotNone (query_invoice .InvoiceLink )
125+ self .assertIn ('https' , query_invoice .InvoiceLink )
0 commit comments