Skip to content

Commit d831d7a

Browse files
committed
Clean up mixins and objects.
1 parent 723e070 commit d831d7a

18 files changed

Lines changed: 172 additions & 280 deletions

quickbooks/__init__.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +0,0 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# Author: Pavel Reznikov <pashka.reznikov@gmail.com>
4-
# Created: 14-10-15
5-
#
6-
# Id: $Id$
7-
8-
from quickbooks import *
9-
from massage import *
10-
from reference import *
11-
from report import *

quickbooks/mixins.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ def to_json(self):
99
class FromJsonMixin(object):
1010
class_dict = {}
1111

12-
def from_json(self, json_data):
12+
@classmethod
13+
def from_json(cls, json_data):
14+
obj = cls()
1315
for key in json_data:
14-
if key in self.class_dict:
15-
obj = self.class_dict[key]()
16-
obj.from_json(json_data[key])
17-
setattr(self, key, obj)
16+
if key in obj.class_dict:
17+
sub_obj = obj.class_dict[key]()
18+
sub_obj.from_json(json_data[key])
19+
setattr(obj, key, sub_obj)
1820
else:
19-
setattr(self, key, json_data[key])
21+
setattr(obj, key, json_data[key])
22+
23+
return obj
2024

2125

22-
class ReadMixin:
26+
class ReadMixin(object):
2327
qbo_object_name = ""
2428

2529
@classmethod
@@ -28,13 +32,10 @@ def get(cls, id):
2832
qb = QuickBooks()
2933

3034
json_data = qb.get_single_object(cls.qbo_object_name, pk=id)
31-
obj = cls()
32-
obj.from_json(json_data[cls.qbo_object_name])
33-
34-
return obj
35+
return cls.from_json(json_data[cls.qbo_object_name])
3536

3637

37-
class CreateMixin:
38+
class CreateMixin(object):
3839
qbo_object_name = ""
3940

4041
@classmethod
@@ -43,14 +44,10 @@ def create(cls):
4344
qb = QuickBooks()
4445

4546
json_data = qb.create_object(cls.qbo_object_name, cls.to_json())
46-
47-
obj = cls()
48-
obj.from_json(json_data[cls.qbo_object_name])
49-
50-
return obj
47+
return cls.from_json(json_data[cls.qbo_object_name])
5148

5249

53-
class UpdateMixin:
50+
class UpdateMixin(object):
5451
qbo_object_name = ""
5552

5653
def update(self):
@@ -61,7 +58,7 @@ def update(self):
6158
return self
6259

6360

64-
class ListMixin:
61+
class ListMixin(object):
6562
qbo_object_name = ""
6663

6764
@classmethod
@@ -73,11 +70,8 @@ def all(cls):
7370
json_data = qb.get_all(cls.qbo_object_name)
7471

7572
obj_list = []
76-
7773
for item_json in json_data["QueryResponse"][cls.qbo_object_name]:
78-
obj = cls()
79-
obj.from_json(item_json)
80-
obj_list.append(obj)
74+
obj_list.append(cls.from_json(item_json))
8175

8276
return obj_list
8377

@@ -90,8 +84,6 @@ def filter(cls, **kwargs):
9084

9185
obj_list = []
9286
for item_json in json_data["QueryResponse"][cls.qbo_object_name]:
93-
obj = cls()
94-
obj.from_json(item_json)
95-
obj_list.append(obj)
87+
obj_list.append(cls.from_json(item_json))
9688

9789
return obj_list

quickbooks/objects.py

Lines changed: 0 additions & 106 deletions
This file was deleted.

quickbooks/objects/__init__.py

Whitespace-only changes.

quickbooks/objects/account.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ class Account(QuickbooksBaseObject):
1414

1515
qbo_object_name = "Account"
1616

17-
Name = ""
18-
SubAccount = False
19-
FullyQualifiedName = ""
20-
Active = True
21-
Classification = ""
22-
AccountType = ""
23-
AccountSubType = ""
24-
CurrentBalance = 0
25-
CurrentBalanceWithSubAccounts = 0
26-
CurrencyRef = None
17+
def __init__(self):
18+
self.Name = ""
19+
self.SubAccount = False
20+
self.FullyQualifiedName = ""
21+
self.Active = True
22+
self.Classification = ""
23+
self.AccountType = ""
24+
self.AccountSubType = ""
25+
self.CurrentBalance = 0
26+
self.CurrentBalanceWithSubAccounts = 0
27+
self.CurrencyRef = None
2728

2829
def __unicode__(self):
2930
return self.FullyQualifiedName

quickbooks/objects/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from mixins import ToJsonMixin, FromJsonMixin, ReadMixin, CreateMixin, ListMixin, UpdateMixin
1+
from ..mixins import ToJsonMixin, FromJsonMixin, ReadMixin, CreateMixin, ListMixin, UpdateMixin
22

33

44
class QuickbooksBaseObject(ToJsonMixin, FromJsonMixin, ReadMixin, CreateMixin, ListMixin, UpdateMixin):

quickbooks/objects/budget.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ class Budget(QuickbooksBaseObject):
1414

1515
qbo_object_name = "Budget"
1616

17-
Name = ""
18-
StartDate = ""
19-
EndDate = ""
20-
BudgetType = ""
21-
BudgetEntryType = ""
22-
Active = True
17+
def __init__(self):
18+
self.Name = ""
19+
self.StartDate = ""
20+
self.EndDate = ""
21+
self.BudgetType = ""
22+
self.BudgetEntryType = ""
23+
self.Active = True
2324

24-
BudgetDetail = None
25+
self.BudgetDetail = None
2526

2627
def __unicode__(self):
2728
return self.Name
@@ -33,11 +34,12 @@ class BudgetDetail(QuickbooksBaseObject, ToJsonMixin, FromJsonMixin):
3334
"CustomerRef": Ref
3435
}
3536

36-
BudgetDate = ""
37-
Amount = 0
37+
def __init__(self):
38+
self.BudgetDate = ""
39+
self.Amount = 0
3840

39-
AccountRef = None
40-
CustomerRef = None
41+
self.AccountRef = None
42+
self.CustomerRef = None
4143

4244
def __unicode__(self):
4345
return self.Amount

quickbooks/objects/customer.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,36 @@ class Customer(QuickbooksBaseObject):
2828

2929
qbo_object_name = "Customer"
3030

31-
Title = ""
32-
GivenName = ""
33-
MiddleName = ""
34-
FamilyName = ""
35-
Suffix = ""
36-
FullyQualifiedName = ""
37-
CompanyName = ""
38-
DisplayName = ""
39-
PrintOnCheckName = ""
40-
Notes = ""
41-
Active = True
42-
Job = False
43-
BillWithParent = False
44-
Taxable = True
45-
Balance = 0
46-
BalanceWithJobs = 0
47-
PreferredDeliveryMethod = ""
48-
ResaleNum = ""
31+
def __init__(self):
32+
self.Title = ""
33+
self.GivenName = ""
34+
self.MiddleName = ""
35+
self.FamilyName = ""
36+
self.Suffix = ""
37+
self.FullyQualifiedName = ""
38+
self.CompanyName = ""
39+
self.DisplayName = ""
40+
self.PrintOnCheckName = ""
41+
self.Notes = ""
42+
self.Active = True
43+
self.Job = False
44+
self.BillWithParent = False
45+
self.Taxable = True
46+
self.Balance = 0
47+
self.BalanceWithJobs = 0
48+
self.PreferredDeliveryMethod = ""
49+
self.ResaleNum = ""
4950

50-
BillAddr = None
51-
ShipAddr = None
52-
PrimaryPhone = None
53-
Mobile = None
54-
Fax = None
55-
PrimaryEmailAddr = None
56-
WebAddr = None
57-
DefaultTaxCodeRef = None
58-
SalesTermRef = None
59-
PaymentMethodRef = None
51+
self.BillAddr = None
52+
self.ShipAddr = None
53+
self.PrimaryPhone = None
54+
self.Mobile = None
55+
self.Fax = None
56+
self.PrimaryEmailAddr = None
57+
self.WebAddr = None
58+
self.DefaultTaxCodeRef = None
59+
self.SalesTermRef = None
60+
self.PaymentMethodRef = None
6061

6162
def __unicode__(self):
6263
return self.DisplayName

quickbooks/objects/department.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ class Department(QuickbooksBaseObject):
1313

1414
qbo_object_name = "Department"
1515

16-
Name = ""
17-
SubDepartment = False
18-
FullyQualifiedName = ""
19-
Active = True
16+
def __init__(self):
17+
self.Name = ""
18+
self.SubDepartment = False
19+
self.FullyQualifiedName = ""
20+
self.Active = True
2021

2122
def __unicode__(self):
2223
return self.FullyQualifiedName

quickbooks/objects/employee.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ class Employee(QuickbooksBaseObject):
1212

1313
qbo_object_name = "Employee"
1414

15-
SSN = ""
16-
BillableTime = ""
17-
GivenName = ""
18-
FamilyName = ""
19-
DisplayName = ""
20-
PrintOnCheckName = ""
21-
Active = True
15+
def __init__(self):
16+
self.SSN = ""
17+
self.BillableTime = ""
18+
self.GivenName = ""
19+
self.FamilyName = ""
20+
self.DisplayName = ""
21+
self.PrintOnCheckName = ""
22+
self.Active = True
2223

23-
PrimaryAddr = None
24+
self.PrimaryAddr = None
2425

2526
def __unicode__(self):
2627
return self.DisplayName

0 commit comments

Comments
 (0)