Skip to content

use minorversion 75 by default #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions quickbooks/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,19 @@ def __new__(cls, **kwargs):
if 'company_id' in kwargs:
instance.company_id = kwargs['company_id']

if 'minorversion' in kwargs:
instance.minorversion = kwargs['minorversion']

if instance.minorversion < instance.MINIMUM_MINOR_VERSION:
warnings.warn(
'Minor Version no longer supported.'
'See: https://blogs.intuit.com/2025/01/21/changes-to-our-accounting-api-that-may-impact-your-application/',
DeprecationWarning)
# Handle minorversion with default
instance.minorversion = kwargs.get('minorversion', instance.MINIMUM_MINOR_VERSION)
if 'minorversion' not in kwargs:
warnings.warn(
'No minor version specified. Defaulting to minimum supported version (75). '
'Please specify minorversion explicitly when initializing QuickBooks. '
'See: https://blogs.intuit.com/2025/01/21/changes-to-our-accounting-api-that-may-impact-your-application/',
DeprecationWarning)
elif instance.minorversion < instance.MINIMUM_MINOR_VERSION:
warnings.warn(
f'Minor Version {instance.minorversion} is no longer supported. Minimum supported version is {instance.MINIMUM_MINOR_VERSION}. '
'See: https://blogs.intuit.com/2025/01/21/changes-to-our-accounting-api-that-may-impact-your-application/',
DeprecationWarning)

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

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

if self.minorversion:
params['minorversion'] = self.minorversion
params['minorversion'] = self.minorversion

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

def get(self, *args, **kwargs):
return self.make_request("GET", *args, **kwargs)
if 'params' not in kwargs:
kwargs['params'] = {}
if 'minorversion' not in kwargs['params']:
kwargs['params']['minorversion'] = self.MINIMUM_MINOR_VERSION
return self.make_request('GET', *args, **kwargs)

def post(self, *args, **kwargs):
return self.make_request("POST", *args, **kwargs)
if 'params' not in kwargs:
kwargs['params'] = {}
if 'minorversion' not in kwargs['params']:
kwargs['params']['minorversion'] = self.MINIMUM_MINOR_VERSION
return self.make_request('POST', *args, **kwargs)

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

def get_single_object(self, qbbo, pk, params=None):
url = "{0}/company/{1}/{2}/{3}".format(self.api_url, self.company_id, qbbo.lower(), pk)
result = self.get(url, {}, params=params)
if params is None:
params = {}

return result
return self.get(url, {}, params=params)

@staticmethod
def handle_exceptions(results):
Expand Down Expand Up @@ -312,6 +325,9 @@ def isvalid_object_name(self, object_name):

def update_object(self, qbbo, request_body, _file_path=None, _file_bytes=None, request_id=None, params=None):
url = "{0}/company/{1}/{2}".format(self.api_url, self.company_id, qbbo.lower())
if params is None:
params = {}

result = self.post(url, request_body, file_path=_file_path, file_bytes=_file_bytes, request_id=request_id, params=params)

return result
Expand Down
15 changes: 9 additions & 6 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def test_client_with_deprecated_minor_version(self):
self.assertEqual(self.qb_client.minorversion, 74)
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
self.assertTrue("Minor Version no longer supported." in str(w[-1].message))
self.assertTrue("Minor Version 74 is no longer supported" in str(w[-1].message))
self.assertTrue("Minimum supported version is 75" in str(w[-1].message))

def test_api_url(self):
qb_client = client.QuickBooks(sandbox=False)
Expand Down Expand Up @@ -122,7 +123,7 @@ def test_update_object_with_request_id(self, make_req):
qb_client.update_object("Customer", "request_body", request_id="123")

url = "https://sandbox-quickbooks.api.intuit.com/v3/company/1234/customer"
make_req.assert_called_with("POST", url, "request_body", file_path=None, file_bytes=None, request_id="123", params=None)
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})

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

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

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

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

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

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

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

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

def test_handle_exceptions(self):
qb_client = client.QuickBooks()
Expand Down