Skip to content

Commit a4d680f

Browse files
authored
Merge pull request #381 from laf-rge/minor-version
use minorversion 75 by default
2 parents 5efc535 + 04d5563 commit a4d680f

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

quickbooks/client.py

+30-14
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,19 @@ def __new__(cls, **kwargs):
7676
if 'company_id' in kwargs:
7777
instance.company_id = kwargs['company_id']
7878

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)
8792

8893
instance.invoice_link = kwargs.get('invoice_link', False)
8994

@@ -157,8 +162,7 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
157162
if not params:
158163
params = {}
159164

160-
if self.minorversion:
161-
params['minorversion'] = self.minorversion
165+
params['minorversion'] = self.minorversion
162166

163167
if request_id:
164168
params['requestid'] = request_id
@@ -236,10 +240,18 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
236240
return result
237241

238242
def get(self, *args, **kwargs):
239-
return self.make_request("GET", *args, **kwargs)
243+
if 'params' not in kwargs:
244+
kwargs['params'] = {}
245+
if 'minorversion' not in kwargs['params']:
246+
kwargs['params']['minorversion'] = self.MINIMUM_MINOR_VERSION
247+
return self.make_request('GET', *args, **kwargs)
240248

241249
def post(self, *args, **kwargs):
242-
return self.make_request("POST", *args, **kwargs)
250+
if 'params' not in kwargs:
251+
kwargs['params'] = {}
252+
if 'minorversion' not in kwargs['params']:
253+
kwargs['params']['minorversion'] = self.MINIMUM_MINOR_VERSION
254+
return self.make_request('POST', *args, **kwargs)
243255

244256
def process_request(self, request_type, url, headers="", params="", data=""):
245257
if self.session is None:
@@ -252,9 +264,10 @@ def process_request(self, request_type, url, headers="", params="", data=""):
252264

253265
def get_single_object(self, qbbo, pk, params=None):
254266
url = "{0}/company/{1}/{2}/{3}".format(self.api_url, self.company_id, qbbo.lower(), pk)
255-
result = self.get(url, {}, params=params)
267+
if params is None:
268+
params = {}
256269

257-
return result
270+
return self.get(url, {}, params=params)
258271

259272
@staticmethod
260273
def handle_exceptions(results):
@@ -312,6 +325,9 @@ def isvalid_object_name(self, object_name):
312325

313326
def update_object(self, qbbo, request_body, _file_path=None, _file_bytes=None, request_id=None, params=None):
314327
url = "{0}/company/{1}/{2}".format(self.api_url, self.company_id, qbbo.lower())
328+
if params is None:
329+
params = {}
330+
315331
result = self.post(url, request_body, file_path=_file_path, file_bytes=_file_bytes, request_id=request_id, params=params)
316332

317333
return result

tests/unit/test_client.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def test_client_with_deprecated_minor_version(self):
4747
self.assertEqual(self.qb_client.minorversion, 74)
4848
self.assertEqual(len(w), 1)
4949
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
50-
self.assertTrue("Minor Version no longer supported." in str(w[-1].message))
50+
self.assertTrue("Minor Version 74 is no longer supported" in str(w[-1].message))
51+
self.assertTrue("Minimum supported version is 75" in str(w[-1].message))
5152

5253
def test_api_url(self):
5354
qb_client = client.QuickBooks(sandbox=False)
@@ -122,7 +123,7 @@ def test_update_object_with_request_id(self, make_req):
122123
qb_client.update_object("Customer", "request_body", request_id="123")
123124

124125
url = "https://sandbox-quickbooks.api.intuit.com/v3/company/1234/customer"
125-
make_req.assert_called_with("POST", url, "request_body", file_path=None, file_bytes=None, request_id="123", params=None)
126+
make_req.assert_called_with("POST", url, "request_body", file_path=None, file_bytes=None, request_id="123", params={'minorversion': client.QuickBooks.MINIMUM_MINOR_VERSION})
126127

127128
@patch('quickbooks.client.QuickBooks.get')
128129
def test_get_current_user(self, get):
@@ -140,7 +141,8 @@ def test_get_report(self, make_req):
140141

141142
qb_client.get_report("profitandloss", {1: 2})
142143
url = "https://sandbox-quickbooks.api.intuit.com/v3/company/1234/reports/profitandloss"
143-
make_req.assert_called_with("GET", url, params={1: 2})
144+
expected_params = {1: 2, 'minorversion': client.QuickBooks.MINIMUM_MINOR_VERSION}
145+
make_req.assert_called_with("GET", url, params=expected_params)
144146

145147
@patch('quickbooks.client.QuickBooks.make_request')
146148
def test_get_single_object(self, make_req):
@@ -149,7 +151,7 @@ def test_get_single_object(self, make_req):
149151

150152
qb_client.get_single_object("test", 1)
151153
url = "https://sandbox-quickbooks.api.intuit.com/v3/company/1234/test/1"
152-
make_req.assert_called_with("GET", url, {}, params=None)
154+
make_req.assert_called_with("GET", url, {}, params={'minorversion': client.QuickBooks.MINIMUM_MINOR_VERSION})
153155

154156
@patch('quickbooks.client.QuickBooks.make_request')
155157
def test_get_single_object_with_params(self, make_req):
@@ -158,7 +160,7 @@ def test_get_single_object_with_params(self, make_req):
158160

159161
qb_client.get_single_object("test", 1, params={'param':'value'})
160162
url = "https://sandbox-quickbooks.api.intuit.com/v3/company/1234/test/1"
161-
make_req.assert_called_with("GET", url, {}, params={'param':'value'})
163+
make_req.assert_called_with("GET", url, {}, params={'param':'value', 'minorversion': client.QuickBooks.MINIMUM_MINOR_VERSION})
162164

163165
@patch('quickbooks.client.QuickBooks.process_request')
164166
def test_make_request(self, process_request):
@@ -171,7 +173,8 @@ def test_make_request(self, process_request):
171173

172174
process_request.assert_called_with(
173175
"GET", url, data={},
174-
headers={'Content-Type': 'application/json', 'Accept': 'application/json', 'User-Agent': 'python-quickbooks V3 library'}, params={})
176+
headers={'Content-Type': 'application/json', 'Accept': 'application/json', 'User-Agent': 'python-quickbooks V3 library'},
177+
params={'minorversion': client.QuickBooks.MINIMUM_MINOR_VERSION})
175178

176179
def test_handle_exceptions(self):
177180
qb_client = client.QuickBooks()

0 commit comments

Comments
 (0)