Skip to content

Commit 7277aca

Browse files
committed
Merge branch 'main' of https://github.com/learning-unlimited/ESP-Website into main
2 parents 993e15d + 50e4f49 commit 7277aca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+763
-1033
lines changed

esp/esp/accounting/migrations/0002_accounting_data.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from esp.accounting.controllers import GlobalAccountingController, ProgramAccountingController
88
from esp.program.models import Program
9-
from esp.accounting_core.models import Transaction, LineItem
109

1110
class Migration(SchemaMigration):
1211

esp/esp/accounting/migrations/0005_import_data.py

+2-150
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from django.db import models
66
from django import db as django_db
77

8-
from esp.accounting_docs.models import Document
98
from esp.program.models import Program
109
from esp.users.models import ESPUser
1110

@@ -15,154 +14,7 @@
1514

1615
def migrate_program(program):
1716

18-
docs = Document.objects.filter(anchor=program.anchor, doctype=2)
19-
num_uncategorized = 0
20-
num = 0
21-
found_for_program = False
22-
student_dict = {}
23-
24-
# Clear financial data for this program
25-
pac = ProgramAccountingController(program)
26-
pac.clear_all_data()
27-
lineitem_types = {'one': {}, 'multi': {}, 'select': []}
28-
lineitem_choices = {}
29-
30-
# Build a database of each student's financial transactions for the program
31-
for doc in docs:
32-
student_id = doc.user.id
33-
34-
if student_id not in student_dict:
35-
student_dict[student_id] = {
36-
'admission': {},
37-
'finaid_amt': Decimal('0'),
38-
'items': [],
39-
'items_select': [],
40-
'payment': [],
41-
}
42-
lineitems = doc.txn.lineitem_set.all()
43-
"""
44-
if lineitems.count() > 0:
45-
try:
46-
print '\nStudent: %s' % doc.user.name()
47-
except:
48-
print '\nStudent: %s' % doc.user.username
49-
"""
50-
for li in lineitems:
51-
found_for_program = True
52-
base_txt = '[%5d] %s: %.2f' % (li.id, li.text, li.amount)
53-
# if li.anchor.uri == splash.anchor.uri + '/LineItemTypes/Required':
54-
if 'admission' in li.text.lower() or 'cost of attending' in li.text.lower():
55-
base_txt = '(Admission) ' + base_txt
56-
if li.text not in student_dict[student_id]['admission']:
57-
student_dict[student_id]['admission'][li.text] = li.amount.copy_abs()
58-
elif 'financial aid' in li.text.lower():
59-
base_txt = '(Finaid) ' + base_txt
60-
student_dict[student_id]['finaid_amt'] += li.amount
61-
elif 'payment received' in li.text.lower():
62-
base_txt = '(Payment) ' + base_txt
63-
student_dict[student_id]['payment'].append(li.amount.copy_abs())
64-
elif 'expecting on-site payment' in li.text.lower():
65-
base_txt = '(Payment expected) ' + base_txt
66-
student_dict[student_id]['payment'].append(li.amount.copy_abs())
67-
elif 'BuyMultiSelect' in li.anchor.uri:
68-
base_txt = '(Select: field "%s", choice "%s") ' % (li.anchor.name, li.text) + base_txt
69-
student_dict[student_id]['items_select'].append((li.anchor.name, li.text, li.amount.copy_abs()))
70-
if li.anchor.name not in lineitem_types['select']:
71-
lineitem_types['select'].append(li.anchor.name)
72-
lineitem_choices[li.anchor.name] = []
73-
if (li.text, li.amount.copy_abs()) not in lineitem_choices[li.anchor.name]:
74-
lineitem_choices[li.anchor.name].append((li.text, li.amount.copy_abs()))
75-
elif 'BuyMany' in li.anchor.uri or 'shirt' in li.text.lower():
76-
base_txt = '(Multi: field "%s") ' % (li.anchor.name) + base_txt
77-
student_dict[student_id]['items'].append((li.text, li.amount.copy_abs()))
78-
if li.text not in lineitem_types['multi']:
79-
lineitem_types['multi'][li.text] = li.amount.copy_abs()
80-
elif 'BuyOne' in li.anchor.uri or 'lunch' in li.text.lower() or 'dinner' in li.text.lower() or 'photo' in li.text.lower():
81-
base_txt = '(Single: field "%s") ' % (li.anchor.name) + base_txt
82-
student_dict[student_id]['items'].append((li.text, li.amount.copy_abs()))
83-
if li.text not in lineitem_types['one']:
84-
lineitem_types['one'][li.text] = li.amount.copy_abs()
85-
else:
86-
num_uncategorized += 1
87-
print 'WARNING: Uncategorized line item: %s' % base_txt
88-
# raise Exception('Uncategorized line item: %s' % base_txt)
89-
90-
num += 1
91-
# print '-- %s' % base_txt
92-
"""
93-
if student_dict[student_id]['finaid_amt'] > 0:
94-
print student_dict[student_id]
95-
elif len(student_dict[student_id]['items_multi']) > 0:
96-
print student_dict[student_id]
97-
"""
98-
99-
if found_for_program:
100-
num_programs = 1
101-
else:
102-
num_programs = 0
103-
104-
# Populate line item types for the program
105-
optional_items = []
106-
for item in lineitem_types['one']:
107-
optional_items.append((item, lineitem_types['one'][item], 1))
108-
for item in lineitem_types['multi']:
109-
optional_items.append((item, lineitem_types['multi'][item], 10))
110-
select_items = []
111-
for item in lineitem_types['select']:
112-
select_items.append((item, lineitem_choices[item]))
113-
114-
# print optional_items
115-
# print select_items
116-
pac.setup_accounts()
117-
pac.setup_lineitemtypes(0.0, optional_items, select_items)
118-
119-
# Create new transfer records for this student
120-
for student_id in student_dict:
121-
user = ESPUser.objects.get(id=student_id)
122-
iac = IndividualAccountingController(program, user)
123-
rec = student_dict[student_id]
124-
125-
# Admission fee
126-
admission_total_cost = 0
127-
for key in rec['admission']:
128-
admission_total_cost += rec['admission'][key]
129-
if admission_total_cost > 0:
130-
initial_transfer = iac.add_required_transfers()[0]
131-
initial_transfer.amount_dec = admission_total_cost
132-
initial_transfer.save()
133-
134-
# Financial aid
135-
if rec['finaid_amt'] > 0:
136-
if rec['finaid_amt'] >= admission_total_cost:
137-
iac.grant_full_financial_aid()
138-
else:
139-
iac.set_finaid_params(rec['finaid_amt'], None)
140-
141-
# Optional items
142-
prefs = []
143-
for item in rec['items']:
144-
prefs.append((item[0], 1, item[1]))
145-
for item in rec['items_select']:
146-
prefs.append((item[0], 1, item[2]))
147-
iac.apply_preferences(prefs)
148-
149-
# Payments
150-
for payment in rec['payment']:
151-
iac.submit_payment(payment)
152-
153-
try:
154-
attended_ids = program.students()['attended'].values_list('id', flat=True)
155-
156-
# Execute transfers for the students that are marked as attended
157-
pac.execute_pending_transfers(ESPUser.objects.filter(id__in=attended_ids))
158-
159-
# Clear transfers for the students that are marked as not attended
160-
pac.remove_pending_transfers(ESPUser.objects.exclude(id__in=attended_ids))
161-
except:
162-
print 'Unable to determine which students attended the program; all transfers remain unexecuted'
163-
164-
print 'Converted %d line items for %s; %d uncategorized' % (num, program.niceName(), num_uncategorized)
165-
return num_programs
17+
return 0
16618

16719
class Migration(SchemaMigration):
16820

@@ -323,4 +175,4 @@ def backwards(self, orm):
323175
}
324176
}
325177

326-
complete_apps = ['accounting']
178+
complete_apps = ['accounting']

esp/esp/accounting_core/AUTHORS

-3
This file was deleted.

esp/esp/accounting_core/admin.py

-53
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# -*- coding: utf-8 -*-
2+
import datetime
3+
from south.db import db
4+
from south.v2 import SchemaMigration
5+
from django.db import models
6+
7+
8+
class Migration(SchemaMigration):
9+
10+
def forwards(self, orm):
11+
# Adding model 'LineItemType'
12+
db.create_table('accounting_core_lineitemtype', (
13+
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
14+
('text', self.gf('django.db.models.fields.TextField')()),
15+
('amount', self.gf('django.db.models.fields.DecimalField')(default='0.0', max_digits=9, decimal_places=2)),
16+
('anchor', self.gf('django.db.models.fields.related.ForeignKey')(related_name='accounting_lineitemtype', null=True, to=orm['datatree.DataTree'])),
17+
('finaid_amount', self.gf('django.db.models.fields.DecimalField')(default='0.0', max_digits=9, decimal_places=2)),
18+
('finaid_anchor', self.gf('django.db.models.fields.related.ForeignKey')(related_name='accounting_finaiditemtype', null=True, to=orm['datatree.DataTree'])),
19+
))
20+
db.send_create_signal('accounting_core', ['LineItemType'])
21+
22+
# Adding model 'Balance'
23+
db.create_table('accounting_core_balance', (
24+
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
25+
('anchor', self.gf('django.db.models.fields.related.ForeignKey')(related_name='balance', to=orm['datatree.DataTree'])),
26+
('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='balance', to=orm['auth.User'])),
27+
('timestamp', self.gf('django.db.models.fields.DateTimeField')()),
28+
('amount', self.gf('django.db.models.fields.DecimalField')(max_digits=16, decimal_places=2)),
29+
('past', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['accounting_core.Balance'], null=True)),
30+
('_order', self.gf('django.db.models.fields.IntegerField')(default=0)),
31+
))
32+
db.send_create_signal('accounting_core', ['Balance'])
33+
34+
# Adding model 'Transaction'
35+
db.create_table('accounting_core_transaction', (
36+
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
37+
('timestamp', self.gf('django.db.models.fields.DateTimeField')()),
38+
('text', self.gf('django.db.models.fields.TextField')()),
39+
('complete', self.gf('django.db.models.fields.BooleanField')(default=False)),
40+
))
41+
db.send_create_signal('accounting_core', ['Transaction'])
42+
43+
# Adding model 'LineItem'
44+
db.create_table('accounting_core_lineitem', (
45+
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
46+
('transaction', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['accounting_core.Transaction'])),
47+
('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='accounting_lineitem', to=orm['auth.User'])),
48+
('anchor', self.gf('django.db.models.fields.related.ForeignKey')(related_name='accounting_lineitem', to=orm['datatree.DataTree'])),
49+
('amount', self.gf('django.db.models.fields.DecimalField')(max_digits=9, decimal_places=2)),
50+
('text', self.gf('django.db.models.fields.TextField')()),
51+
('li_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['accounting_core.LineItemType'])),
52+
('posted_to', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['accounting_core.Balance'], null=True, blank=True)),
53+
))
54+
db.send_create_signal('accounting_core', ['LineItem'])
55+
56+
57+
def backwards(self, orm):
58+
# Deleting model 'LineItemType'
59+
db.delete_table('accounting_core_lineitemtype')
60+
61+
# Deleting model 'Balance'
62+
db.delete_table('accounting_core_balance')
63+
64+
# Deleting model 'Transaction'
65+
db.delete_table('accounting_core_transaction')
66+
67+
# Deleting model 'LineItem'
68+
db.delete_table('accounting_core_lineitem')
69+
70+
71+
models = {
72+
'accounting_core.balance': {
73+
'Meta': {'ordering': "('_order',)", 'object_name': 'Balance'},
74+
'_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
75+
'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '16', 'decimal_places': '2'}),
76+
'anchor': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'balance'", 'to': "orm['datatree.DataTree']"}),
77+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
78+
'past': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounting_core.Balance']", 'null': 'True'}),
79+
'timestamp': ('django.db.models.fields.DateTimeField', [], {}),
80+
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'balance'", 'to': "orm['auth.User']"})
81+
},
82+
'accounting_core.lineitem': {
83+
'Meta': {'object_name': 'LineItem'},
84+
'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '9', 'decimal_places': '2'}),
85+
'anchor': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'accounting_lineitem'", 'to': "orm['datatree.DataTree']"}),
86+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
87+
'li_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounting_core.LineItemType']"}),
88+
'posted_to': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounting_core.Balance']", 'null': 'True', 'blank': 'True'}),
89+
'text': ('django.db.models.fields.TextField', [], {}),
90+
'transaction': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounting_core.Transaction']"}),
91+
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'accounting_lineitem'", 'to': "orm['auth.User']"})
92+
},
93+
'accounting_core.lineitemtype': {
94+
'Meta': {'object_name': 'LineItemType'},
95+
'amount': ('django.db.models.fields.DecimalField', [], {'default': "'0.0'", 'max_digits': '9', 'decimal_places': '2'}),
96+
'anchor': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'accounting_lineitemtype'", 'null': 'True', 'to': "orm['datatree.DataTree']"}),
97+
'finaid_amount': ('django.db.models.fields.DecimalField', [], {'default': "'0.0'", 'max_digits': '9', 'decimal_places': '2'}),
98+
'finaid_anchor': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'accounting_finaiditemtype'", 'null': 'True', 'to': "orm['datatree.DataTree']"}),
99+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
100+
'text': ('django.db.models.fields.TextField', [], {})
101+
},
102+
'accounting_core.transaction': {
103+
'Meta': {'object_name': 'Transaction'},
104+
'complete': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
105+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
106+
'text': ('django.db.models.fields.TextField', [], {}),
107+
'timestamp': ('django.db.models.fields.DateTimeField', [], {})
108+
},
109+
'auth.group': {
110+
'Meta': {'object_name': 'Group'},
111+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
112+
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
113+
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
114+
},
115+
'auth.permission': {
116+
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
117+
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
118+
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
119+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
120+
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
121+
},
122+
'auth.user': {
123+
'Meta': {'object_name': 'User'},
124+
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
125+
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
126+
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
127+
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
128+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
129+
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
130+
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
131+
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
132+
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
133+
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
134+
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
135+
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
136+
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
137+
},
138+
'contenttypes.contenttype': {
139+
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
140+
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
141+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
142+
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
143+
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
144+
},
145+
'datatree.datatree': {
146+
'Meta': {'unique_together': "(('name', 'parent'),)", 'object_name': 'DataTree'},
147+
'friendly_name': ('django.db.models.fields.TextField', [], {}),
148+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
149+
'lock_table': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
150+
'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
151+
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'child_set'", 'null': 'True', 'to': "orm['datatree.DataTree']"}),
152+
'range_correct': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
153+
'rangeend': ('django.db.models.fields.IntegerField', [], {}),
154+
'rangestart': ('django.db.models.fields.IntegerField', [], {}),
155+
'uri': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
156+
'uri_correct': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
157+
}
158+
}
159+
160+
complete_apps = ['accounting_core']

0 commit comments

Comments
 (0)