Skip to content

Commit

Permalink
Merge pull request #363 from ej2/0.9.10
Browse files Browse the repository at this point in the history
0.9.10
  • Loading branch information
ej2 authored Aug 7, 2024
2 parents 6943dec + 99bd245 commit 045cded
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 117 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

* 0.9.10 (August 7, 2024)
* Update intuit-oauth dependency
* Fix issues with Invoice Sharable Link
* Added optional params to get

* 0.9.9 (July 9, 2024)
* Removed simplejson
* Added use_decimal option (See PR: https://github.com/ej2/python-quickbooks/pull/356 for details)
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pytest-cov = "*"

[packages]
urllib3 = ">=2.1.0"
intuit-oauth = "==1.2.5"
intuit-oauth = "==1.2.6"
requests = ">=2.31.0"
requests_oauthlib = ">=1.3.1"
setuptools = "*"
303 changes: 208 additions & 95 deletions Pipfile.lock

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,23 @@ One example is `include=allowduplicatedocnum` on the Purchase object. You can ad

purchase.save(qb=self.qb_client, params={'include': 'allowduplicatedocnum'})

Other operations
Sharable Invoice Link
----------------
Add Sharable link for an invoice sent to external customers (minorversion must be set to 36 or greater):
To add a sharable link for an invoice, make sure the AllowOnlineCreditCardPayment is set to True and BillEmail is set to a invalid email address:

invoice.invoice_link = true
invoice.AllowOnlineCreditCardPayment = True
invoice.BillEmail = EmailAddress()
invoice.BillEmail.Address = '[email protected]'

When you query the invoice include the following params (minorversion must be set to 36 or greater):

Void an invoice:
invoice = Invoice.get(id, qb=self.qb_client, params={'include': 'invoiceLink'})


Void an invoice
----------------
Call `void` on any invoice with an Id:

invoice = Invoice()
invoice.Id = 7
invoice.void(qb=client)
Expand Down
7 changes: 2 additions & 5 deletions quickbooks/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
if request_id:
params['requestid'] = request_id

if self.invoice_link:
params['include'] = 'invoiceLink'

if not request_body:
request_body = {}

Expand Down Expand Up @@ -242,9 +239,9 @@ def process_request(self, request_type, url, headers="", params="", data=""):
return self.session.request(
request_type, url, headers=headers, params=params, data=data)

def get_single_object(self, qbbo, pk):
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, {})
result = self.get(url, {}, params=params)

return result

Expand Down
4 changes: 2 additions & 2 deletions quickbooks/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ class ReadMixin(object):
qbo_json_object_name = ""

@classmethod
def get(cls, id, qb=None):
def get(cls, id, qb=None, params=None):
if not qb:
qb = QuickBooks()

json_data = qb.get_single_object(cls.qbo_object_name, pk=id)
json_data = qb.get_single_object(cls.qbo_object_name, pk=id, params=params)

if cls.qbo_json_object_name != '':
return cls.from_json(json_data[cls.qbo_json_object_name])
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
intuit-oauth==1.2.4
intuit-oauth==1.2.6
requests_oauthlib>=1.3.1
requests>=2.31.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def read(*parts):
return fp.read()


VERSION = (0, 9, 9)
VERSION = (0, 9, 10)
version = '.'.join(map(str, VERSION))

setup(
Expand All @@ -31,7 +31,7 @@ def read(*parts):

install_requires=[
'setuptools',
'intuit-oauth==1.2.5',
'intuit-oauth==1.2.6',
'requests_oauthlib>=1.3.1',
'requests>=2.31.0',
'python-dateutil',
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
)

self.qb_client = QuickBooks(
minorversion=69,
minorversion=73,
auth_client=self.auth_client,
refresh_token=os.environ.get('REFRESH_TOKEN'),
company_id=os.environ.get('COMPANY_ID'),
Expand Down
45 changes: 41 additions & 4 deletions tests/integration/test_invoice.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from datetime import datetime

from quickbooks.objects.base import CustomerMemo
from quickbooks.objects.customer import Customer
from quickbooks.objects.detailline import SalesItemLine, SalesItemLineDetail
from quickbooks.objects.invoice import Invoice
from quickbooks.objects.item import Item
from quickbooks.objects.base import EmailAddress
from tests.integration.test_base import QuickbooksTestCase
import uuid

class InvoiceTest(QuickbooksTestCase):
def create_invoice(self, customer, request_id=None):
invoice = Invoice()

class InvoiceTest(QuickbooksTestCase):
def create_invoice_line(self):
line = SalesItemLine()
line.LineNum = 1
line.Description = "description"
Expand All @@ -18,7 +20,11 @@ def create_invoice(self, customer, request_id=None):
item = Item.all(max_results=1, qb=self.qb_client)[0]

line.SalesItemLineDetail.ItemRef = item.to_ref()
invoice.Line.append(line)
return line

def create_invoice(self, customer, request_id=None):
invoice = Invoice()
invoice.Line.append(self.create_invoice_line())

invoice.CustomerRef = customer.to_ref()

Expand Down Expand Up @@ -86,3 +92,34 @@ def test_void(self):
self.assertEqual(query_invoice.Balance, 0.0)
self.assertEqual(query_invoice.TotalAmt, 0.0)
self.assertIn('Voided', query_invoice.PrivateNote)

def test_invoice_link(self):
# Sharable link for the invoice sent to external customers.
# The link is generated only for invoices with online payment enabled and having a valid customer email address.
# Include query param `include=invoiceLink` to get the link back on query response.

# Create test customer
customer_name = datetime.now().strftime('%d%H%M%S')
customer = Customer()
customer.DisplayName = customer_name
customer.save(qb=self.qb_client)

# Create an invoice with sharable link flags set
invoice = Invoice()
invoice.CustomerRef = customer.to_ref()
invoice.DueDate = '2024-12-31'
invoice.AllowOnlineCreditCardPayment = True
invoice.AllowOnlineACHPayment = True
invoice.Line.append(self.create_invoice_line())

# BillEmail must be set for Sharable link to work!
invoice.BillEmail = EmailAddress()
invoice.BillEmail.Address = '[email protected]'

invoice.save(qb=self.qb_client)

# You must add 'include': 'invoiceLink' to the params when doing a query for the invoice
query_invoice = Invoice.get(invoice.Id, qb=self.qb_client, params={'include': 'invoiceLink'})

self.assertIsNotNone(query_invoice.InvoiceLink)
self.assertIn('https', query_invoice.InvoiceLink)
11 changes: 10 additions & 1 deletion tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,16 @@ 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, {})
make_req.assert_called_with("GET", url, {}, params=None)

@patch('quickbooks.client.QuickBooks.make_request')
def test_get_single_object_with_params(self, make_req):
qb_client = client.QuickBooks(auth_client=self.auth_client)
qb_client.company_id = "1234"

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'})

@patch('quickbooks.client.QuickBooks.process_request')
def test_make_request(self, process_request):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class ReadMixinTest(QuickbooksUnitTestCase):
@patch('quickbooks.mixins.QuickBooks.get_single_object')
def test_get(self, get_single_object):
Department.get(1)
get_single_object.assert_called_once_with("Department", pk=1)
get_single_object.assert_called_once_with("Department", pk=1, params=None)

def test_get_with_qb(self):
with patch.object(self.qb_client, 'get_single_object') as get_single_object:
Expand Down

0 comments on commit 045cded

Please sign in to comment.