Skip to content
Open
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
8 changes: 7 additions & 1 deletion quickbooks/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class QuickBooks(object):
verifier_token = None
invoice_link = False
use_decimal = False
include_custom_fields = False

sandbox_api_url_v3 = "https://sandbox-quickbooks.api.intuit.com/v3"
api_url_v3 = "https://quickbooks.api.intuit.com/v3"
Expand Down Expand Up @@ -98,6 +99,8 @@ def __new__(cls, **kwargs):
if 'use_decimal' in kwargs:
instance.use_decimal = kwargs.get('use_decimal')

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

return instance

def _start_session(self):
Expand Down Expand Up @@ -163,7 +166,10 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
params = {}

params['minorversion'] = self.minorversion


if self.include_custom_fields:
params['include'] = 'enhancedAllCustomFields'

if request_id:
params['requestid'] = request_id

Expand Down
24 changes: 19 additions & 5 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,23 @@ 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'},
headers={'Content-Type': 'application/json', 'Accept': 'application/json', 'User-Agent': 'python-quickbooks V3 library'},
params={'minorversion': client.QuickBooks.MINIMUM_MINOR_VERSION})

@patch('quickbooks.client.QuickBooks.process_request')
def test_make_request_without_custom_fields(self, process_request):
process_request.return_value = MockResponseJson()

qb_client = client.QuickBooks(include_custom_fields=True)
qb_client.company_id = "1234"
url = "https://sandbox-quickbooks.api.intuit.com/v3/company/1234/test/1/"
qb_client.make_request("GET", url, request_body=None, content_type='application/json')

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

def test_handle_exceptions(self):
qb_client = client.QuickBooks()
error_data = {
Expand Down Expand Up @@ -247,11 +261,11 @@ def test_make_request_file_closed(self, process_request):
process_request.return_value = MockResponseJson()
with patch('builtins.open', mock_open(read_data=b'file content')) as mock_file:
qb_client = client.QuickBooks(auth_client=self.auth_client)
qb_client.make_request('POST',
'https://sandbox-quickbooks.api.intuit.com/v3/company/COMPANY_ID/attachable',
request_body='{"ContentType": "text/plain"}',
qb_client.make_request('POST',
'https://sandbox-quickbooks.api.intuit.com/v3/company/COMPANY_ID/attachable',
request_body='{"ContentType": "text/plain"}',
file_path=file_path)

mock_file.assert_called_once_with(file_path, 'rb')
mock_file.return_value.__enter__.return_value.read.assert_called_once()
mock_file.return_value.__exit__.assert_called_once()
Expand Down