1
+ from datetime import datetime
2
+
1
3
from quickbooks .objects .base import CustomerMemo
2
4
from quickbooks .objects .customer import Customer
3
5
from quickbooks .objects .detailline import SalesItemLine , SalesItemLineDetail
4
6
from quickbooks .objects .invoice import Invoice
5
7
from quickbooks .objects .item import Item
8
+ from quickbooks .objects .base import EmailAddress
6
9
from tests .integration .test_base import QuickbooksTestCase
7
10
import uuid
8
11
9
- class InvoiceTest (QuickbooksTestCase ):
10
- def create_invoice (self , customer , request_id = None ):
11
- invoice = Invoice ()
12
12
13
+ class InvoiceTest (QuickbooksTestCase ):
14
+ def create_invoice_line (self ):
13
15
line = SalesItemLine ()
14
16
line .LineNum = 1
15
17
line .Description = "description"
@@ -18,7 +20,11 @@ def create_invoice(self, customer, request_id=None):
18
20
item = Item .all (max_results = 1 , qb = self .qb_client )[0 ]
19
21
20
22
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 ())
22
28
23
29
invoice .CustomerRef = customer .to_ref ()
24
30
@@ -86,3 +92,34 @@ def test_void(self):
86
92
self .assertEqual (query_invoice .Balance , 0.0 )
87
93
self .assertEqual (query_invoice .TotalAmt , 0.0 )
88
94
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 = '[email protected] '
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