Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Repented of Transaction having an __init__()

  • Loading branch information...
commit e840fed6347daa94f0ceb85fabef9d2138461605 1 parent e661cdb
Brandon Rhodes authored August 19, 2012
3  publican/engine/models.py
@@ -24,9 +24,6 @@ class Transaction(types.Transaction, models.Model):
24 24
     amount = models.DecimalField(max_digits=20, decimal_places=2)
25 25
     comment = models.TextField(blank=True)
26 26
 
27  
-    def __init__(self, *args, **kw):
28  
-        models.Model.__init__(self, *args, **kw)
29  
-
30 27
 
31 28
 class Company(company.Company):
32 29
     ein='38-0218963'
53  publican/engine/tests/sample.py
@@ -12,10 +12,11 @@
12 12
 def build_company():
13 13
     """Create a sample `Company` with pre-loaded test data."""
14 14
 
15  
-    def A(type):
16  
-        a = Account()
17  
-        a.type = type
18  
-        return a
  15
+    def make(cls, **kw):
  16
+        thing = cls()
  17
+        for k, v in kw.iteritems():
  18
+            setattr(thing, k, v)
  19
+        return thing
19 20
 
20 21
     def F(region, name, period, date):
21 22
         form = get_form(region, name)
@@ -23,8 +24,6 @@ def F(region, name, period, date):
23 24
         f.date = date
24 25
         return f
25 26
 
26  
-    T = Transaction
27  
-
28 27
     b = Company(
29 28
         ein='38-0218963',
30 29
         name='Crazy R Software',
@@ -32,12 +31,11 @@ def F(region, name, period, date):
32 31
         )
33 32
 
34 33
     b.today = Date(2012, 8, 20)  # override, so tests are predictable!
35  
-    print b.today
36 34
 
37  
-    business = A('business')
38  
-    alice = A('employee')
39  
-    bob = A('employee')
40  
-    carol = A('consultant')
  35
+    business = make(Account, type='business')
  36
+    alice = make(Account, type='employee')
  37
+    bob = make(Account, type='employee')
  38
+    carol = make(Account, type='consultant')
41 39
 
42 40
     business.id, alice.id, bob.id, carol.id = range(4)
43 41
 
@@ -48,18 +46,29 @@ def F(region, name, period, date):
48 46
         F('us', '941', Quarter(2012, 1), Date(2012, 4, 15)),
49 47
         ]
50 48
 
51  
-    b._transactions = [
52  
-        T(Date(2011, 11, 29), business, alice, Decimal(1400)),
53  
-        T(Date(2011, 12, 29), business, alice, Decimal(2200)),
54  
-
55  
-        T(Date(2012, 1, 29), business, alice, Decimal(2200)),
56  
-        T(Date(2012, 1, 29), business, bob, Decimal(900)),
57  
-        T(Date(2012, 1, 29), bob, business, Decimal(99)), # reimbursement
58  
-        T(Date(2012, 2, 29), business, carol, Decimal(1000)),
59  
-        T(Date(2012, 2, 29), business, alice, Decimal(2200)),
60  
-        T(Date(2012, 3, 29), business, alice, Decimal(2200)),
  49
+    T = Transaction
61 50
 
62  
-        T(Date(2012, 4, 29), business, alice, Decimal(2200)),
  51
+    b._transactions = [
  52
+        make(T, date=Date(2011, 11, 29), debit_account=business,
  53
+             credit_account=alice, amount=Decimal(1400)),
  54
+        make(T, date=Date(2011, 12, 29), debit_account=business,
  55
+             credit_account=alice, amount=Decimal(2200)),
  56
+
  57
+        make(T, date=Date(2012, 1, 29), debit_account=business,
  58
+             credit_account=alice, amount=Decimal(2200)),
  59
+        make(T, date=Date(2012, 1, 29), debit_account=business,
  60
+             credit_account=bob, amount=Decimal(900)),
  61
+        make(T, date=Date(2012, 1, 29), debit_account=bob,
  62
+             credit_account=business, amount=Decimal(99)), # reimbursement
  63
+        make(T, date=Date(2012, 2, 29), debit_account=business,
  64
+             credit_account=carol, amount=Decimal(1000)),
  65
+        make(T, date=Date(2012, 2, 29), debit_account=business,
  66
+             credit_account=alice, amount=Decimal(2200)),
  67
+        make(T, date=Date(2012, 3, 29), debit_account=business,
  68
+             credit_account=alice, amount=Decimal(2200)),
  69
+
  70
+        make(T, date=Date(2012, 4, 29), debit_account=business,
  71
+             credit_account=alice, amount=Decimal(2200)),
63 72
         ]
64 73
 
65 74
     return b
14  publican/engine/types.py
@@ -29,6 +29,8 @@
29 29
    saved for real when the application is up and running.
30 30
 
31 31
 """
  32
+from .kit import zero
  33
+
32 34
 class Account(object):
33 35
     """An account in our system of double-entry bookkeeping.
34 36
 
@@ -51,10 +53,8 @@ class Transaction(object):
51 53
     "invoice #24" or "for rebuilding my model classes".
52 54
 
53 55
     """
54  
-    def __init__(self, date, debit_account, credit_account, amount,
55  
-                 comment=''):
56  
-        self.date = date
57  
-        self.debit_account = debit_account
58  
-        self.credit_account = credit_account
59  
-        self.amount = amount
60  
-        self.comment = comment
  56
+    date = None
  57
+    debit_account = None
  58
+    credit_account = None
  59
+    amount = zero
  60
+    comment = u''
6  publican/frontend/views.py
@@ -5,7 +5,6 @@
5 5
 from django.shortcuts import render_to_response
6 6
 
7 7
 from publican.engine.kit import Interval, Month, dollars, cents, get_period
8  
-#from publican.engine.tests.sample import company
9 8
 from publican.forms import registry
10 9
 
11 10
 
@@ -100,11 +99,12 @@ def filing(request, region, name, period_name):
100 99
 
101 100
 def _get_company(request):
102 101
     """Return a `Company` facade for the current user's data."""
  102
+    if False:
  103
+        from publican.engine.tests.sample import company
  104
+        return company
103 105
     from ..engine.models import CompanyUser, Company
104 106
     cu = CompanyUser.objects.get(user=request.user)
105  
-    print cu
106 107
     account = cu.company
107  
-    print account
108 108
     return Company(account)
109 109
 
110 110
 def _display_month(filing):

0 notes on commit e840fed

Please sign in to comment.
Something went wrong with that request. Please try again.