Skip to content

Commit

Permalink
Updates and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ej2 committed Aug 24, 2020
1 parent bac499a commit 49fab19
Show file tree
Hide file tree
Showing 17 changed files with 24,212 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

* 0.8.3 (August 24, 2020)
* Fixed issue with CompanyCurrency object
* Added to_ref method to the Term object
* Fixed issues with RefundReceipt
* Added RefundReceiptCheckPayment object to RefundReceipt object
* Added from_json to MetaData

* 0.8.2 (April 22nd, 2020)
* Added PrimaryTaxIdentifier to Customer object
* Fixed issue with PaymentMethod to_ref
Expand Down
19 changes: 19 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
intuit-oauth = "==1.2.3"
rauth = ">=0.7.1"
requests = ">=2.19.1"
simplejson = ">=3.17.0"
six = ">=1.14.0"
nose = "*"
authclient = "*"
coverage = "*"

[requires]
python_version = "3.8"
342 changes: 342 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

23,682 changes: 23,682 additions & 0 deletions get-pip.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion quickbooks/mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from future.moves.urllib.parse import quote

import simplejson as json
try: import simplejson as json
except ImportError: import json

import six
from .utils import build_where_clause, build_choose_clause
from .client import QuickBooks
Expand Down
2 changes: 1 addition & 1 deletion quickbooks/objects/attachable.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def save(self, qb=None):
if not qb:
qb = QuickBooks()

if self.Id and self.Id > 0:
if self.Id and int(self.Id) > 0:
json_data = qb.update_object(self.qbo_object_name, self.to_json(), _file_path=self._FilePath)
else:
json_data = qb.create_object(self.qbo_object_name, self.to_json(), _file_path=self._FilePath)
Expand Down
2 changes: 1 addition & 1 deletion quickbooks/objects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class QuickbooksReadOnlyObject(QuickbooksBaseObject, ReadMixin, ListMixin):


@python_2_unicode_compatible
class MetaData:
class MetaData(FromJsonMixin):
def __init__(self):
self.CreateTime = ""
self.LastUpdatedTime = ""
Expand Down
33 changes: 28 additions & 5 deletions quickbooks/objects/refundreceipt.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
from six import python_2_unicode_compatible

from quickbooks.objects import CreditCardPayment
from .base import Ref, CustomField, QuickbooksManagedObject, \
LinkedTxnMixin, QuickbooksTransactionEntity, LinkedTxn, Address, EmailAddress
LinkedTxnMixin, QuickbooksTransactionEntity, LinkedTxn, Address, EmailAddress, QuickbooksBaseObject, CustomerMemo
from .tax import TxnTaxDetail
from .detailline import DetailLine
from ..mixins import DeleteMixin


@python_2_unicode_compatible
class RefundReceiptCheckPayment(QuickbooksBaseObject):
qbo_object_name = "CheckPayment"

def __init__(self):
super(RefundReceiptCheckPayment, self).__init__()
self.CheckNum = ""
self.Status = ""
self.NameOnAcct = ""
self.AcctNum = ""
self.BankName = ""

def __str__(self):
return self.CheckNum


@python_2_unicode_compatible
class RefundReceipt(DeleteMixin, QuickbooksManagedObject, QuickbooksTransactionEntity, LinkedTxnMixin):
"""
Expand All @@ -22,6 +40,9 @@ class RefundReceipt(DeleteMixin, QuickbooksManagedObject, QuickbooksTransactionE
"ClassRef": Ref,
"BillEmail": EmailAddress,
"PaymentMethodRef": Ref,
"CheckPayment": RefundReceiptCheckPayment,
"CreditCardPayment": CreditCardPayment,
"CustomerMemo": CustomerMemo,
}

list_dict = {
Expand All @@ -41,17 +62,16 @@ def __init__(self):
self.DocNumber = ""
self.TotalAmt = 0
self.ApplyTaxAfterDiscount = False
self.PrintStatus = ""
self.PrintStatus = "NotSet"
self.Balance = 0
self.PaymentRefNum = ""
self.TxnDate = ""
self.ExchangeRate = 1
self.PrivateNote = ""
self.CustomerMemo = ""

self.PaymentRefNum = ""
self.PaymentType = ""
self.CheckPayment = ""
self.CreditCardPayment = ""

self.TxnSource = None
self.GlobalTaxCalculation = "TaxExcluded"

Expand All @@ -65,6 +85,9 @@ def __init__(self):
self.ClassRef = None
self.BillEmail = None
self.PaymentMethodRef = None
self.CheckPayment = None
self.CreditCardPayment = None
self.CustomerMemo = None

self.CustomField = []
self.Line = []
Expand Down
12 changes: 11 additions & 1 deletion quickbooks/objects/term.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from six import python_2_unicode_compatible
from .base import QuickbooksManagedObject, QuickbooksTransactionEntity
from .base import QuickbooksManagedObject, QuickbooksTransactionEntity, Ref


@python_2_unicode_compatible
Expand Down Expand Up @@ -29,3 +29,13 @@ def __init__(self):

def __str__(self):
return self.Name

def to_ref(self):
ref = Ref()

ref.name = self.Name
ref.type = self.qbo_object_name
ref.value = self.Id

return ref

1 change: 1 addition & 0 deletions tests/integration/test_attachable.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def test_create_file(self):
attachable.ContentType = 'text/plain'

attachable.save(qb=self.qb_client)

query_attachable = Attachable.get(attachable.Id, qb=self.qb_client)

self.assertEquals(query_attachable.AttachableRef[0].EntityRef.value, vendor.Id)
1 change: 1 addition & 0 deletions tests/integration/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def setUp(self):
)

self.qb_client = QuickBooks(
minorversion=53,
auth_client=self.auth_client,
refresh_token=os.environ.get('REFRESH_TOKEN'),
company_id=os.environ.get('COMPANY_ID'),
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/test_companycurrency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from quickbooks.objects import Customer
from quickbooks.objects.companycurrency import CompanyCurrency
from tests.integration.test_base import QuickbooksTestCase


class CompanyCurrencyTest(QuickbooksTestCase):
def test_get_all(self):
currencies = CompanyCurrency.all(qb=self.qb_client)
self.assertGreater(len(currencies), 0)

def test_get(self):
currency = CompanyCurrency.get(id=1, qb=self.qb_client)
self.assertEqual(currency.Name, 'Canadian Dollar')
2 changes: 2 additions & 0 deletions tests/integration/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_create(self):
item.Type = "Inventory"
item.TrackQtyOnHand = True
item.QtyOnHand = 10
item.Sku = "SKU123123"
item.InvStartDate = "2015-01-01"

item.IncomeAccountRef = self.income_account.to_ref()
Expand All @@ -38,6 +39,7 @@ def test_create(self):
self.assertEquals(query_item.Id, item.Id)
self.assertEquals(query_item.Name, self.name)
self.assertEquals(query_item.Type, "Inventory")
self.assertEquals(query_item.Sku, "SKU123123")
self.assertEquals(query_item.TrackQtyOnHand, True)
self.assertEquals(query_item.QtyOnHand, 10)
self.assertEquals(query_item.IncomeAccountRef.value, self.income_account.Id)
Expand Down
39 changes: 39 additions & 0 deletions tests/integration/test_payment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from datetime import datetime

from quickbooks.objects import Customer, PaymentMethod
from quickbooks.objects.account import Account
from quickbooks.objects.payment import Payment

from tests.integration.test_base import QuickbooksTestCase


class PaymentTest(QuickbooksTestCase):
def setUp(self):
super(PaymentTest, self).setUp()

self.account_number = datetime.now().strftime('%d%H%M')
self.name = "Test Account {0}".format(self.account_number)

def test_getall(self):
payments = Payment.all(max_results=5, qb=self.qb_client)

self.assertEqual(len(payments), 5)
self.assertNotEqual(payments[0].Id, 0)

def test_create(self):
payment = Payment()
payment.TotalAmt = 140.0

customer = Customer.all(max_results=1, qb=self.qb_client)[0]
payment.CustomerRef = customer.to_ref()

payment_method = PaymentMethod.all(max_results=1, qb=self.qb_client)[0]

payment.PaymentMethodRef = payment_method.to_ref()
payment.save(qb=self.qb_client)

query_payment = Payment.get(payment.Id, qb=self.qb_client)

self.assertEqual(query_payment.CustomerRef.name, customer.DisplayName)
self.assertEqual(query_payment.TotalAmt, 140.0)
self.assertEqual(query_payment.PaymentMethodRef.value, payment_method.Id)
51 changes: 51 additions & 0 deletions tests/integration/test_refundreceipt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from datetime import datetime

from quickbooks.objects import RefundReceipt, DetailLine, CustomerMemo, SalesItemLineDetail, \
Account, Item
from quickbooks.objects.refundreceipt import RefundReceiptCheckPayment
from tests.integration.test_base import QuickbooksTestCase


class PaymentTest(QuickbooksTestCase):
def setUp(self):
super(PaymentTest, self).setUp()

self.account_number = datetime.now().strftime('%d%H%M')
self.name = "Test Account {0}".format(self.account_number)

def test_create(self):
refund_receipt = RefundReceipt()
refund_receipt.DocNumber = "DocNum123"
refund_receipt.TotalAmt = 100
refund_receipt.Balance = 100
refund_receipt.PrivateNote = "Private Note"
refund_receipt.PaymentType = "Check"

memo = CustomerMemo()
memo.value = "Customer Memo"
refund_receipt.CustomerMemo = memo

refund_receipt.CheckPayment = RefundReceiptCheckPayment()
refund_receipt.CheckPayment.CheckNum = "1001"
refund_receipt.CheckPayment.NameOnAcct = "John Smith"
refund_receipt.CheckPayment.AcctNum = "0000000000"
refund_receipt.CheckPayment.BankName = "Bank"

item = Item.all(max_results=1, qb=self.qb_client)[0]
line = DetailLine()
line.DetailType = "SalesItemLineDetail"
line.Amount = 200
line.SalesItemLineDetail = SalesItemLineDetail()
line.SalesItemLineDetail.ItemRef = item.to_ref()
refund_receipt.Line.append(line)

account = Account.where("Name = 'checking'", max_results=1, qb=self.qb_client)[0]
refund_receipt.DepositToAccountRef = account.to_ref()

refund_receipt.save(qb=self.qb_client)

query_refund_receipt = RefundReceipt.get(refund_receipt.Id, qb=self.qb_client)

self.assertEqual(query_refund_receipt.DocNumber, refund_receipt.DocNumber)
self.assertEqual(query_refund_receipt.Line[0].Amount, 200)
self.assertEqual(refund_receipt.DepositToAccountRef.value, account.Id)
11 changes: 11 additions & 0 deletions tests/unit/objects/test_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ def test_valid_object_name(self):
result = client.isvalid_object_name(obj.qbo_object_name)

self.assertTrue(result)

def test_to_ref(self):
term = Term()
term.Name = "test"
term.Id = 100

ref = term.to_ref()

self.assertEquals(ref.name, "test")
self.assertEquals(ref.type, "Term")
self.assertEquals(ref.value, 100)
2 changes: 0 additions & 2 deletions tests/unit/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

from quickbooks.objects import Bill, Invoice

from intuitlib.client import AuthClient
from quickbooks.client import QuickBooks
from tests.integration.test_base import QuickbooksUnitTestCase

try:
Expand Down

0 comments on commit 49fab19

Please sign in to comment.