@@ -76,14 +76,19 @@ def __new__(cls, **kwargs):
76
76
if 'company_id' in kwargs :
77
77
instance .company_id = kwargs ['company_id' ]
78
78
79
- if 'minorversion' in kwargs :
80
- instance .minorversion = kwargs ['minorversion' ]
81
-
82
- if instance .minorversion < instance .MINIMUM_MINOR_VERSION :
83
- warnings .warn (
84
- 'Minor Version no longer supported.'
85
- 'See: https://blogs.intuit.com/2025/01/21/changes-to-our-accounting-api-that-may-impact-your-application/' ,
86
- DeprecationWarning )
79
+ # Handle minorversion with default
80
+ instance .minorversion = kwargs .get ('minorversion' , instance .MINIMUM_MINOR_VERSION )
81
+ if 'minorversion' not in kwargs :
82
+ warnings .warn (
83
+ 'No minor version specified. Defaulting to minimum supported version (75). '
84
+ 'Please specify minorversion explicitly when initializing QuickBooks. '
85
+ 'See: https://blogs.intuit.com/2025/01/21/changes-to-our-accounting-api-that-may-impact-your-application/' ,
86
+ DeprecationWarning )
87
+ elif instance .minorversion < instance .MINIMUM_MINOR_VERSION :
88
+ warnings .warn (
89
+ f'Minor Version { instance .minorversion } is no longer supported. Minimum supported version is { instance .MINIMUM_MINOR_VERSION } . '
90
+ 'See: https://blogs.intuit.com/2025/01/21/changes-to-our-accounting-api-that-may-impact-your-application/' ,
91
+ DeprecationWarning )
87
92
88
93
instance .invoice_link = kwargs .get ('invoice_link' , False )
89
94
@@ -152,13 +157,12 @@ def change_data_capture(self, entity_string, changed_since):
152
157
return result
153
158
154
159
def make_request (self , request_type , url , request_body = None , content_type = 'application/json' ,
155
- params = None , file_path = None , request_id = None ):
160
+ params = None , file_path = None , file_bytes = None , request_id = None ):
156
161
157
162
if not params :
158
163
params = {}
159
164
160
- if self .minorversion :
161
- params ['minorversion' ] = self .minorversion
165
+ params ['minorversion' ] = self .minorversion
162
166
163
167
if request_id :
164
168
params ['requestid' ] = request_id
@@ -172,7 +176,7 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
172
176
'User-Agent' : 'python-quickbooks V3 library'
173
177
}
174
178
175
- if file_path :
179
+ if file_path or file_bytes :
176
180
url = url .replace ('attachable' , 'upload' )
177
181
boundary = '-------------PythonMultipartPost'
178
182
headers .update ({
@@ -183,8 +187,11 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
183
187
'Connection' : 'close'
184
188
})
185
189
186
- with open (file_path , 'rb' ) as attachment :
187
- binary_data = str (base64 .b64encode (attachment .read ()).decode ('ascii' ))
190
+ if file_path :
191
+ with open (file_path , 'rb' ) as attachment :
192
+ binary_data = str (base64 .b64encode (attachment .read ()).decode ('ascii' ))
193
+ else :
194
+ binary_data = str (base64 .b64encode (file_bytes ).decode ('ascii' ))
188
195
189
196
content_type = json .loads (request_body )['ContentType' ]
190
197
@@ -233,10 +240,16 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
233
240
return result
234
241
235
242
def get (self , * args , ** kwargs ):
236
- return self .make_request ("GET" , * args , ** kwargs )
243
+ if 'params' not in kwargs :
244
+ kwargs ['params' ] = {}
245
+
246
+ return self .make_request ('GET' , * args , ** kwargs )
237
247
238
248
def post (self , * args , ** kwargs ):
239
- return self .make_request ("POST" , * args , ** kwargs )
249
+ if 'params' not in kwargs :
250
+ kwargs ['params' ] = {}
251
+
252
+ return self .make_request ('POST' , * args , ** kwargs )
240
253
241
254
def process_request (self , request_type , url , headers = "" , params = "" , data = "" ):
242
255
if self .session is None :
@@ -248,10 +261,11 @@ def process_request(self, request_type, url, headers="", params="", data=""):
248
261
request_type , url , headers = headers , params = params , data = data )
249
262
250
263
def get_single_object (self , qbbo , pk , params = None ):
251
- url = "{0}/company/{1}/{2}/{3}/" .format (self .api_url , self .company_id , qbbo .lower (), pk )
252
- result = self .get (url , {}, params = params )
264
+ url = "{0}/company/{1}/{2}/{3}" .format (self .api_url , self .company_id , qbbo .lower (), pk )
265
+ if params is None :
266
+ params = {}
253
267
254
- return result
268
+ return self . get ( url , {}, params = params )
255
269
256
270
@staticmethod
257
271
def handle_exceptions (results ):
@@ -287,11 +301,11 @@ def handle_exceptions(results):
287
301
else :
288
302
raise exceptions .QuickbooksException (message , code , detail )
289
303
290
- def create_object (self , qbbo , request_body , _file_path = None , request_id = None , params = None ):
304
+ def create_object (self , qbbo , request_body , _file_path = None , _file_bytes = None , request_id = None , params = None ):
291
305
self .isvalid_object_name (qbbo )
292
306
293
307
url = "{0}/company/{1}/{2}" .format (self .api_url , self .company_id , qbbo .lower ())
294
- results = self .post (url , request_body , file_path = _file_path , request_id = request_id , params = params )
308
+ results = self .post (url , request_body , file_path = _file_path , file_bytes = _file_bytes , request_id = request_id , params = params )
295
309
296
310
return results
297
311
@@ -307,9 +321,12 @@ def isvalid_object_name(self, object_name):
307
321
308
322
return True
309
323
310
- def update_object (self , qbbo , request_body , _file_path = None , request_id = None , params = None ):
324
+ def update_object (self , qbbo , request_body , _file_path = None , _file_bytes = None , request_id = None , params = None ):
311
325
url = "{0}/company/{1}/{2}" .format (self .api_url , self .company_id , qbbo .lower ())
312
- result = self .post (url , request_body , file_path = _file_path , request_id = request_id , params = params )
326
+ if params is None :
327
+ params = {}
328
+
329
+ result = self .post (url , request_body , file_path = _file_path , file_bytes = _file_bytes , request_id = request_id , params = params )
313
330
314
331
return result
315
332
0 commit comments