Skip to content

Commit

Permalink
Renamed MonthlyLog to Membership
Browse files Browse the repository at this point in the history
  • Loading branch information
jsayles committed Jun 30, 2011
1 parent 5e9e74f commit 3913a79
Show file tree
Hide file tree
Showing 20 changed files with 327 additions and 147 deletions.
2 changes: 1 addition & 1 deletion front/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib.auth.models import User

import settings
from staff.models import Bill, Transaction, Member, MonthlyLog, DailyLog, Onboard_Task, Onboard_Task_Completed, ExitTask, ExitTaskCompleted, Neighborhood
from staff.models import Bill, Transaction, Member, Membership, DailyLog, Onboard_Task, Onboard_Task_Completed, ExitTask, ExitTaskCompleted, Neighborhood
import staff.billing as billing

class FrontTestCase(TestCase):
Expand Down
10 changes: 5 additions & 5 deletions members/templates/members/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ <h2>{{ user.get_full_name }}</h2>
{% endif %}
{% if user.username == request.user.username or request.user.is_staff %}
<dl>
<dt>Membership status:</dt><dd>{{ user.profile.membership_type }}{% if user.profile.is_monthly %} at ${{ user.profile.last_monthly_log.rate }}/month{% endif %}</dd>
<dt>Membership status:</dt><dd>{{ user.profile.membership_type }}{% if user.profile.is_monthly %} at ${{ user.profile.last_membership.rate }}/month{% endif %}</dd>
{% if user.profile.is_monthly %}
<dt>Anniversary date:</dt><dd>{{ user.profile.last_monthly_log.start_date|date:"M d, Y" }}</dd>
<dt>Anniversary date:</dt><dd>{{ user.profile.last_membership.start_date|date:"M d, Y" }}</dd>
{% endif %}
{% if request.user.is_staff %}
<dt>Quicklinks:</dt>
Expand Down Expand Up @@ -71,7 +71,7 @@ <h2>Bills</h2>
<tr class="{% cycle 'row-even' 'row-odd' %}">
<td>{{ bill.created|date:"M d, Y" }}</td>
<td>${{ bill.amount }}</td>
<td>{% if bill.monthly_log %}{{ bill.monthly_log.plan }}{% endif %}</td>
<td>{% if bill.membership %}{{ bill.membership.plan }}{% endif %}</td>
<td>

{% if bill.paid_by %}
Expand Down Expand Up @@ -104,7 +104,7 @@ <h2>Bills</h2>
<p>No bills yet!</p>
{% endif %}

{% if user.profile.monthly_logs.all %}
{% if user.profile.memberships.all %}
<h2>Monthly plans</h2>
<table>
<thead>
Expand All @@ -115,7 +115,7 @@ <h2>Monthly plans</h2>
</tr>
</thead>
<tbody>
{% for log in user.profile.monthly_logs.all reversed %}
{% for log in user.profile.memberships.all reversed %}
<tr class="{% cycle 'row-even' 'row-odd' %}">
<td>{{ log.plan }}</td>
<td>{{ log.start_date|date:"M d, Y" }}</td>
Expand Down
2 changes: 1 addition & 1 deletion members/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib.auth.models import User

import settings
from staff.models import Bill, Transaction, Member, MonthlyLog, DailyLog, Onboard_Task, Onboard_Task_Completed, ExitTask, ExitTaskCompleted, Neighborhood
from staff.models import Bill, Transaction, Member, Membership, DailyLog, Onboard_Task, Onboard_Task_Completed, ExitTask, ExitTaskCompleted, Neighborhood
import staff.billing as billing

class MembersTestCase(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion scripts/dumpFixture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ echo ""
echo "RUN THE PSEUDONOMIZER FIRST!"
echo ""
./manage.py dumpdata auth.User auth.Group --indent 1 > staff/fixtures/base.json
./manage.py dumpdata staff.Member staff.HowHeard staff.Industry staff.Neighborhood staff.DailyLog staff.MonthlyLog --indent 1 > staff/fixtures/staff.json
./manage.py dumpdata staff.Member staff.HowHeard staff.Industry staff.Neighborhood staff.DailyLog staff.Membership --indent 1 > staff/fixtures/staff.json
6 changes: 3 additions & 3 deletions staff/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TransactionAdmin(StyledAdmin):
class BillAdmin(StyledAdmin):
list_display = ('created', 'member', 'amount')
search_fields = ('member__user__first_name', 'member__user__last_name')
raw_id_fields = ('monthly_log', 'dropins', 'guest_dropins')
raw_id_fields = ('membership', 'dropins', 'guest_dropins')
admin.site.register(Bill, BillAdmin)

admin.site.unregister(User)
Expand All @@ -42,10 +42,10 @@ class DailyLogAdmin(StyledAdmin):
search_fields = ('member__user__first_name', 'member__user__last_name', 'guest_of__user__first_name', 'guest_of__user__last_name')
admin.site.register(DailyLog, DailyLogAdmin)

class MonthlyLogAdmin(StyledAdmin):
class MembershipAdmin(StyledAdmin):
list_display = ('member', 'start_date', 'end_date')
search_fields = ('member__user__first_name', 'member__user__last_name')
admin.site.register(MonthlyLog, MonthlyLogAdmin)
admin.site.register(Membership, MembershipAdmin)

# Copyright 2010 Office Nomads LLC (http://www.officenomads.com/) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

54 changes: 27 additions & 27 deletions staff/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import traceback

import settings
from models import Bill, BillingLog, Member, MonthlyLog, DailyLog
from models import Bill, BillingLog, Member, Membership, DailyLog
from django.db.models import Count
from django.core.exceptions import ObjectDoesNotExist

class Day:
"""All of the daily_logs, monthly_logs, and (optionally) a bill associated with this day of a Run."""
"""All of the daily_logs, memberships, and (optionally) a bill associated with this day of a Run."""
def __init__(self, date):
self.date = date
self.monthly_log = None
self.membership = None
self.daily_log = None
self.guest_daily_logs = []
self.bill = None

def is_monthly_log_end_date(self): return self.monthly_log and self.monthly_log.end_date and self.monthly_log.end_date == self.date
def is_membership_end_date(self): return self.membership and self.membership.end_date and self.membership.end_date == self.date

def is_monthly_log_anniversary(self): return self.monthly_log and self.monthly_log.is_anniversary_day(self.date)
def is_membership_anniversary(self): return self.membership and self.membership.is_anniversary_day(self.date)

def __repr__(self):
return 'Day %s' % self.date
Expand All @@ -35,16 +35,16 @@ def __init__(self, member, start_date, end_date, filter_closed_logs=True):
self.populate_days()
self.populate_daily_logs()
self.populate_guest_daily_logs()
self.populate_monthly_logs()
self.populate_memberships()

def non_member_daily_logs(self):
"""Returns a tuple (daily_logs, guest_daily_logs) [each sorted ascending by date] in this run which are not covered by a monthly log, including guest daily logs"""
"""Returns a tuple (daily_logs, guest_daily_logs) [each sorted ascending by date] in this run which are not covered by a membership, including guest daily logs"""
reversed_days = [day for day in self.days]
reversed_days.reverse()
daily_logs = []
guest_daily_logs = []
for day in reversed_days:
if day.monthly_log: break # assume that this and the days before this are covered by the monthly log
if day.membership: break # assume that this and the days before this are covered by the membership
if day.daily_log != None: daily_logs.append(day.daily_log)
for gdl in day.guest_daily_logs: guest_daily_logs.append(gdl)

Expand All @@ -57,15 +57,15 @@ def has_guest_daily_logs(self):
if len(day.guest_daily_logs) > 0: return True
return False

def populate_monthly_logs(self):
for log in MonthlyLog.objects.filter(member=self.member).order_by('start_date'):
def populate_memberships(self):
for log in Membership.objects.filter(member=self.member).order_by('start_date'):
if log.end_date and log.end_date < self.start_date: continue
if log.start_date > self.end_date: continue
for i in range(0, len(self.days)):
if self.days[i].date >= log.start_date:
if log.end_date == None or self.days[i].date <= log.end_date:
if self.days[i].monthly_log: print 'Duplicate monthly log! %s' % log
self.days[i].monthly_log = log
if self.days[i].membership: print 'Duplicate membership! %s' % log
self.days[i].membership = log

def populate_guest_daily_logs(self):
daily_logs = DailyLog.objects.filter(guest_of=self.member, payment="Bill").filter(visit_date__gte=self.start_date).filter(visit_date__lte=self.end_date)
Expand Down Expand Up @@ -95,10 +95,10 @@ def populate_days(self):

def print_info(self):
for day in self.days:
if day.daily_log or day.is_monthly_log_end_date() or day.is_monthly_log_anniversary() or len(day.guest_daily_logs) > 0:
if day.daily_log or day.is_membership_end_date() or day.is_membership_anniversary() or len(day.guest_daily_logs) > 0:
if day.daily_log: print '\tDaily log: %s' % day.daily_log.visit_date
if day.is_monthly_log_end_date(): print '\t%s end: %s' % (day.monthly_log.plan, day.date)
if day.is_monthly_log_anniversary(): print '\t%s monthly anniversary: %s' % (day.monthly_log.plan, day.date)
if day.is_membership_end_date(): print '\t%s end: %s' % (day.membership.plan, day.date)
if day.is_membership_anniversary(): print '\t%s monthly anniversary: %s' % (day.membership.plan, day.date)
if len(day.guest_daily_logs) > 0: print '\tGuest logs: %s' % day.guest_daily_logs

def __repr__(self):
Expand Down Expand Up @@ -128,9 +128,9 @@ def run_billing(bill_time=datetime.now()):
start_date = bill_date - timedelta(days=62)
if start_date < settings.BILLING_START_DATE: start_date = settings.BILLING_START_DATE
run = Run(member, start_date, bill_date)
for day_index in range(0, len(run.days)): # look for days on which we should bill for a monthly log
for day_index in range(0, len(run.days)): # look for days on which we should bill for a membership
day = run.days[day_index]
if day.is_monthly_log_anniversary() or day.is_monthly_log_end_date(): # calculate a member bill
if day.is_membership_anniversary() or day.is_membership_end_date(): # calculate a member bill
bill_dropins = []
bill_guest_dropins = []
recent_days = run.days[0:day_index + 1]
Expand All @@ -142,30 +142,30 @@ def run_billing(bill_time=datetime.now()):
for guest_daily_log in recent_day.guest_daily_logs: bill_guest_dropins.append(guest_daily_log)
# now calculate the bill amount
bill_amount = 0
monthly_fee = day.monthly_log.rate
if day.is_monthly_log_end_date(): monthly_fee = 0
monthly_fee = day.membership.rate
if day.is_membership_end_date(): monthly_fee = 0

if day.monthly_log.plan == 'Basic':
if day.membership.plan == 'Basic':
billable_dropin_count = max(0, len(bill_dropins) - settings.BASIC_DROPIN_COUNT)
bill_amount = monthly_fee + (billable_dropin_count * settings.BASIC_DROPIN_FEE) + (len(bill_guest_dropins) * settings.BASIC_DROPIN_FEE)
elif day.monthly_log.plan == 'PT5':
elif day.membership.plan == 'PT5':
billable_dropin_count = max(0, len(bill_dropins) - settings.PT5_DROPIN_COUNT)
bill_amount = monthly_fee + (billable_dropin_count * settings.PT5_DROPIN_FEE) + (len(bill_guest_dropins) * settings.PT5_DROPIN_FEE)
elif day.monthly_log.plan == 'PT10':
elif day.membership.plan == 'PT10':
billable_dropin_count = max(0, len(bill_dropins) - settings.PT10_DROPIN_COUNT)
bill_amount = monthly_fee + (billable_dropin_count * settings.PT10_DROPIN_FEE) + (len(bill_guest_dropins) * settings.PT10_DROPIN_FEE)
elif day.monthly_log.plan == 'PT15':
elif day.membership.plan == 'PT15':
billable_dropin_count = max(0, len(bill_dropins) - settings.PT15_DROPIN_COUNT)
bill_amount = monthly_fee + (billable_dropin_count * settings.PT15_DROPIN_FEE) + (len(bill_guest_dropins) * settings.PT15_DROPIN_FEE)
elif day.monthly_log.plan == 'Regular':
elif day.membership.plan == 'Regular':
bill_amount = monthly_fee + (len(bill_guest_dropins) * settings.REGULAR_GUEST_DROPIN_FEE)
elif day.monthly_log.plan == 'Resident':
billable_guest_dropin_count = max(0, len(bill_guest_dropins) - max(settings.RESIDENT_GUEST_DROPIN_COUNT, day.monthly_log.guest_dropins))
elif day.membership.plan == 'Resident':
billable_guest_dropin_count = max(0, len(bill_guest_dropins) - max(settings.RESIDENT_GUEST_DROPIN_COUNT, day.membership.guest_dropins))
bill_amount = monthly_fee + (billable_guest_dropin_count * settings.RESIDENT_GUEST_DROPIN_FEE)

if bill_amount == 0: continue

day.bill = Bill(created=day.date, amount=bill_amount, member=member, paid_by=day.monthly_log.guest_of, monthly_log=day.monthly_log)
day.bill = Bill(created=day.date, amount=bill_amount, member=member, paid_by=day.membership.guest_of, membership=day.membership)
day.bill.save()
bill_count += 1
day.bill.dropins = [dropin.id for dropin in bill_dropins]
Expand Down
4 changes: 2 additions & 2 deletions staff/management/commands/pseudonymize_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def capitalize_name(self, name): return '%s%s' % (name[0].upper(), ''.join([c.lo


def handle_noargs(self, **options):
from staff.models import Member, Transaction, DailyLog, MonthlyLog
from staff.models import Member, Transaction, DailyLog, Membership
from django.core.files import File
pseudonymous_image = open('media/BlankIcon150x150.jpg', 'r')

for log in MonthlyLog.objects.all():
for log in Membership.objects.all():
if log.note != None and len(log.note) > 0:
log.note = 'Some admin note here.'
log.save()
Expand Down
6 changes: 3 additions & 3 deletions staff/migrations/0002_auto__add_field_dailylog_created.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def backwards(self, orm):
'guest_dropins': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'guest_bills'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['staff.DailyLog']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'member': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'bills'", 'to': "orm['staff.Member']"}),
'monthly_log': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.MonthlyLog']", 'null': 'True', 'blank': 'True'}),
'membership': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.MonthlyLog']", 'null': 'True', 'blank': 'True'}),
'new_member_deposit': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'paid_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'guest_bills'", 'null': 'True', 'to': "orm['staff.Member']"})
},
Expand Down Expand Up @@ -129,13 +129,13 @@ def backwards(self, orm):
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'}),
'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'})
},
'staff.monthlylog': {
'staff.membership': {
'Meta': {'ordering': "['start_date']", 'object_name': 'MonthlyLog'},
'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'guest_dropins': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'guest_of': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'monthly_guests'", 'null': 'True', 'to': "orm['staff.Member']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'member': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'monthly_logs'", 'to': "orm['staff.Member']"}),
'member': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'memberships'", 'to': "orm['staff.Member']"}),
'note': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
'plan': ('django.db.models.fields.CharField', [], {'max_length': '8'}),
'rate': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
Expand Down
Loading

0 comments on commit 3913a79

Please sign in to comment.