From 3913a79dad6fecc852329a1688554036258c2619 Mon Sep 17 00:00:00 2001 From: Jacob Sayles Date: Wed, 29 Jun 2011 18:34:59 -0700 Subject: [PATCH] Renamed MonthlyLog to Membership --- front/tests.py | 2 +- members/templates/members/user.html | 10 +- members/tests.py | 2 +- scripts/dumpFixture.sh | 2 +- staff/admin.py | 6 +- staff/billing.py | 54 +++--- staff/management/commands/pseudonymize_db.py | 4 +- .../0002_auto__add_field_dailylog_created.py | 6 +- staff/migrations/0004_rename_monthlylog.py | 180 ++++++++++++++++++ staff/models.py | 82 ++++---- staff/templates/staff/bill_table.frag | 6 +- staff/templates/staff/bills.html | 4 +- staff/templates/staff/member_activity.html | 6 +- staff/templates/staff/member_detail.html | 8 +- .../templates/staff/member_transactions.html | 6 +- .../staff/search_and_quicklinks.frag | 2 +- staff/templates/staff/signup.html | 2 +- staff/templates/staff/stats_monthly.html | 4 +- staff/tests.py | 52 ++--- staff/views.py | 36 ++-- 20 files changed, 327 insertions(+), 147 deletions(-) create mode 100644 staff/migrations/0004_rename_monthlylog.py diff --git a/front/tests.py b/front/tests.py index d14c8256d..17acb8a4e 100644 --- a/front/tests.py +++ b/front/tests.py @@ -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): diff --git a/members/templates/members/user.html b/members/templates/members/user.html index 4db68f5c4..5875ea9c4 100644 --- a/members/templates/members/user.html +++ b/members/templates/members/user.html @@ -16,9 +16,9 @@

{{ user.get_full_name }}

{% endif %} {% if user.username == request.user.username or request.user.is_staff %}
-
Membership status:
{{ user.profile.membership_type }}{% if user.profile.is_monthly %} at ${{ user.profile.last_monthly_log.rate }}/month{% endif %}
+
Membership status:
{{ user.profile.membership_type }}{% if user.profile.is_monthly %} at ${{ user.profile.last_membership.rate }}/month{% endif %}
{% if user.profile.is_monthly %} -
Anniversary date:
{{ user.profile.last_monthly_log.start_date|date:"M d, Y" }}
+
Anniversary date:
{{ user.profile.last_membership.start_date|date:"M d, Y" }}
{% endif %} {% if request.user.is_staff %}
Quicklinks:
@@ -71,7 +71,7 @@

Bills

{{ bill.created|date:"M d, Y" }} ${{ bill.amount }} - {% if bill.monthly_log %}{{ bill.monthly_log.plan }}{% endif %} + {% if bill.membership %}{{ bill.membership.plan }}{% endif %} {% if bill.paid_by %} @@ -104,7 +104,7 @@

Bills

No bills yet!

{% endif %} - {% if user.profile.monthly_logs.all %} + {% if user.profile.memberships.all %}

Monthly plans

@@ -115,7 +115,7 @@

Monthly plans

- {% for log in user.profile.monthly_logs.all reversed %} + {% for log in user.profile.memberships.all reversed %} diff --git a/members/tests.py b/members/tests.py index abc1cc7ce..dcabdebf3 100644 --- a/members/tests.py +++ b/members/tests.py @@ -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): diff --git a/scripts/dumpFixture.sh b/scripts/dumpFixture.sh index acc811c18..ef92987e9 100755 --- a/scripts/dumpFixture.sh +++ b/scripts/dumpFixture.sh @@ -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 diff --git a/staff/admin.py b/staff/admin.py index 332d7c8f3..c237ddb64 100644 --- a/staff/admin.py +++ b/staff/admin.py @@ -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) @@ -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. diff --git a/staff/billing.py b/staff/billing.py index 0b1bee4ba..2b4ae1927 100644 --- a/staff/billing.py +++ b/staff/billing.py @@ -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 @@ -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) @@ -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) @@ -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): @@ -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] @@ -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] diff --git a/staff/management/commands/pseudonymize_db.py b/staff/management/commands/pseudonymize_db.py index 245e0ced0..2e87de116 100644 --- a/staff/management/commands/pseudonymize_db.py +++ b/staff/management/commands/pseudonymize_db.py @@ -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() diff --git a/staff/migrations/0002_auto__add_field_dailylog_created.py b/staff/migrations/0002_auto__add_field_dailylog_created.py index 3d3ee03f1..5c09bcbea 100644 --- a/staff/migrations/0002_auto__add_field_dailylog_created.py +++ b/staff/migrations/0002_auto__add_field_dailylog_created.py @@ -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']"}) }, @@ -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'}), diff --git a/staff/migrations/0004_rename_monthlylog.py b/staff/migrations/0004_rename_monthlylog.py new file mode 100644 index 000000000..a3b82482e --- /dev/null +++ b/staff/migrations/0004_rename_monthlylog.py @@ -0,0 +1,180 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Renaming model 'MonthlyLog' to 'Membership' + db.rename_table('staff_monthlylog', 'staff_membership') + + # Changing field 'Bill.monthly_log' + db.rename_column('staff_bill', 'monthly_log_id', 'membership_id') + + def backwards(self, orm): + + # Renaming model 'Membership', 'MonthlyLog' + db.rename_table('staff_membership', 'staff_monthlylog') + + # Changing field 'Bill.monthly_log' + db.rename_column('staff_bill', 'membership_id', 'monthly_log_id') + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'staff.bill': { + 'Meta': {'object_name': 'Bill'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '7', 'decimal_places': '2'}), + 'created': ('django.db.models.fields.DateField', [], {}), + 'dropins': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'bills'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['staff.DailyLog']"}), + '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']"}), + 'membership': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.Membership']", 'null': 'True', 'blank': 'True'}), + 'new_member_deposit': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'paid_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'guest_bills'", 'null': 'True', 'to': "orm['staff.Member']"}) + }, + 'staff.billinglog': { + 'Meta': {'object_name': 'BillingLog'}, + 'ended': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'note': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'started': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'successful': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}) + }, + 'staff.dailylog': { + 'Meta': {'object_name': 'DailyLog'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2011, 6, 29, 17, 42, 52, 364234)', 'auto_now_add': 'True', 'blank': 'True'}), + 'guest_of': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'guest_of'", 'null': 'True', 'to': "orm['staff.Member']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'member': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'daily_logs'", 'to': "orm['staff.Member']"}), + 'note': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': "'True'"}), + 'payment': ('django.db.models.fields.CharField', [], {'max_length': '5'}), + 'visit_date': ('django.db.models.fields.DateField', [], {}) + }, + 'staff.exittask': { + 'Meta': {'object_name': 'ExitTask'}, + 'description': ('django.db.models.fields.CharField', [], {'max_length': '512'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'order': ('django.db.models.fields.SmallIntegerField', [], {}) + }, + 'staff.exittaskcompleted': { + 'Meta': {'object_name': 'ExitTaskCompleted'}, + 'completed_date': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'member': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.Member']"}), + 'task': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.ExitTask']"}) + }, + 'staff.howheard': { + 'Meta': {'object_name': 'HowHeard'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}) + }, + 'staff.industry': { + 'Meta': {'object_name': 'Industry'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}) + }, + 'staff.member': { + 'Meta': {'object_name': 'Member'}, + 'company_name': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}), + 'email2': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), + 'gender': ('django.db.models.fields.CharField', [], {'max_length': '1', 'null': 'True', 'blank': 'True'}), + 'has_kids': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}), + 'howHeard': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.HowHeard']", 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'industry': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.Industry']", 'null': 'True', 'blank': 'True'}), + 'last_modified': ('django.db.models.fields.DateField', [], {'auto_now': 'True', 'blank': 'True'}), + 'neighborhood': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.Neighborhood']", 'null': 'True', 'blank': 'True'}), + 'notes': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'phone': ('django.contrib.localflavor.us.models.PhoneNumberField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}), + 'phone2': ('django.contrib.localflavor.us.models.PhoneNumberField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}), + 'photo': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'promised_followup': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'self_employed': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}), + '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.membership': { + 'Meta': {'object_name': 'Membership'}, + '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']"}), + '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'}), + 'start_date': ('django.db.models.fields.DateField', [], {}) + }, + 'staff.neighborhood': { + 'Meta': {'object_name': 'Neighborhood'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}) + }, + 'staff.onboard_task': { + 'Meta': {'object_name': 'Onboard_Task'}, + 'description': ('django.db.models.fields.CharField', [], {'max_length': '512'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'monthly_only': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'order': ('django.db.models.fields.SmallIntegerField', [], {}) + }, + 'staff.onboard_task_completed': { + 'Meta': {'unique_together': "(('member', 'task'),)", 'object_name': 'Onboard_Task_Completed'}, + 'completed_date': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'member': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.Member']"}), + 'task': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.Onboard_Task']"}) + }, + 'staff.transaction': { + 'Meta': {'object_name': 'Transaction'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '7', 'decimal_places': '2'}), + 'bills': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'transactions'", 'symmetrical': 'False', 'to': "orm['staff.Bill']"}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'member': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['staff.Member']"}), + 'note': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'status': ('django.db.models.fields.CharField', [], {'default': "'open'", 'max_length': '10'}) + } + } + + complete_apps = ['staff'] diff --git a/staff/models.py b/staff/models.py index dce5438e4..e45adf1af 100755 --- a/staff/models.py +++ b/staff/models.py @@ -20,7 +20,7 @@ ('Waved', 'Payment Waved'), ) -MONTHLY_PLAN_CHOICES = ( +MEMBERSHIP_CHOICES = ( ('Basic', 'Basic'), ('PT5', 'Part Time 5'), ('PT10', 'Part Time 10'), @@ -50,7 +50,7 @@ class Bill(models.Model): member = models.ForeignKey('Member', blank=False, null=False, related_name="bills") amount = models.DecimalField(max_digits=7, decimal_places=2) created = models.DateField(blank=False, null=False) - monthly_log = models.ForeignKey('MonthlyLog', blank=True, null=True) + membership = models.ForeignKey('Membership', blank=True, null=True) dropins = models.ManyToManyField('DailyLog', blank=True, null=True, related_name='bills') guest_dropins = models.ManyToManyField('DailyLog', blank=True, null=True, related_name='guest_bills') new_member_deposit = models.BooleanField(default=False, blank=False, null=False) @@ -111,21 +111,21 @@ class Meta: class MemberManager(models.Manager): def member_count(self, active_only): if active_only: - return Member.objects.filter(monthly_logs__start_date__isnull=False, monthly_logs__end_date__isnull=True).count(); + return Member.objects.filter(memberships__start_date__isnull=False, memberships__end_date__isnull=True).count(); else: return Member.objects.all().count() def active_members(self): - unending = Q(monthly_logs__end_date__isnull=True) - future_ending = Q(monthly_logs__end_date__gt=date.today()) - return Member.objects.exclude(monthly_logs__isnull=True).filter(unending | future_ending).distinct() + unending = Q(memberships__end_date__isnull=True) + future_ending = Q(memberships__end_date__gt=date.today()) + return Member.objects.exclude(memberships__isnull=True).filter(unending | future_ending).distinct() - def members_by_monthly_log_type(self, monthly_log_type): - return [log.member for log in MonthlyLog.objects.filter(plan=monthly_log_type).filter(Q(end_date__isnull=True) | Q(end_date__gt=date.today())).distinct().order_by('member__user__first_name')] + def members_by_membership_type(self, membership_type): + return [log.member for log in Membership.objects.filter(plan=membership_type).filter(Q(end_date__isnull=True) | Q(end_date__gt=date.today())).distinct().order_by('member__user__first_name')] def members_by_neighborhood(self, hood, active_only=True): if active_only: - return Member.objects.filter(neighborhood=hood).filter(monthly_logs__isnull=False).filter(Q(monthly_logs__end_date__isnull=True) | Q(monthly_logs__end_date__gt=date.today())).distinct() + return Member.objects.filter(neighborhood=hood).filter(memberships__isnull=False).filter(Q(memberships__end_date__isnull=True) | Q(memberships__end_date__gt=date.today())).distinct() else: return Member.objects.filter(neighborhood=hood) @@ -200,11 +200,11 @@ def last_bill(self): if len(bills) == 0: return None return bills[0] - def last_monthly_log(self): - """Returns the latest monthly log, even if it has an end date, or None if none exists""" - monthly_logs = MonthlyLog.objects.filter(member=self).order_by('-start_date', 'end_date')[0:] - if monthly_logs == None or len(monthly_logs) == 0: return None - return monthly_logs[0] + def last_membership(self): + """Returns the latest membership, even if it has an end date, or None if none exists""" + memberships = Membership.objects.filter(member=self).order_by('-start_date', 'end_date')[0:] + if memberships == None or len(memberships) == 0: return None + return memberships[0] def paid_count(self): return DailyLog.objects.filter(member=self, payment='Bill').count() @@ -213,8 +213,8 @@ def first_visit(self): if DailyLog.objects.filter(member=self).count() > 0: return DailyLog.objects.filter(member=self).order_by('visit_date')[0].visit_date else: - if MonthlyLog.objects.filter(member=self).count() > 0: - return MonthlyLog.objects.filter(member=self).order_by('start_date')[0].start_date + if Membership.objects.filter(member=self).count() > 0: + return Membership.objects.filter(member=self).order_by('start_date')[0].start_date else: return None @@ -230,16 +230,16 @@ def last_visit(self): if DailyLog.objects.filter(member=self).count() > 0: return DailyLog.objects.filter(member=self).latest('visit_date').visit_date else: - if MonthlyLog.objects.filter(member=self, end_date__isnull=False).count() > 0: - return MonthlyLog.objects.filter(member=self, end_date__isnull=False).latest('end_date').end_date + if Membership.objects.filter(member=self, end_date__isnull=False).count() > 0: + return Membership.objects.filter(member=self, end_date__isnull=False).latest('end_date').end_date else: return None def membership_type(self): # First check for existing monthly - monthly_logs = MonthlyLog.objects.filter(member=self) - if monthly_logs.count() > 0: - last_monthly = self.last_monthly_log() + memberships = Membership.objects.filter(member=self) + if memberships.count() > 0: + last_monthly = self.last_membership() if last_monthly.end_date == None or last_monthly.end_date > date.today(): return last_monthly.plan else: @@ -260,7 +260,7 @@ def membership_type(self): return "No drop-ins" def is_monthly(self): - last_log = self.last_monthly_log() + last_log = self.last_membership() if not last_log: return False return last_log.end_date == None or last_log.end_date >= date.today() @@ -275,7 +275,7 @@ def onboard_tasks_to_complete(self): return Onboard_Task.objects.count() - Onboard_Task_Completed.objects.filter(member=self).count() def qualifies_for_exit_tasks(self): - last_log = self.last_monthly_log() + last_log = self.last_membership() if not last_log or last_log.end_date == None: return False return last_log.end_date < date.today() @@ -335,14 +335,14 @@ class Meta: verbose_name = "Daily Log" ordering = ['-visit_date', '-created'] -class MonthlyLog_Manager(models.Manager): +class Membership_Manager(models.Manager): def by_date(self, target_date): return self.filter(start_date__lte=target_date).filter(Q(end_date__isnull=True) | Q(end_date__gte=target_date)) -class MonthlyLog(models.Model): +class Membership(models.Model): """A membership level which is billed monthly""" - member = models.ForeignKey(Member, related_name="monthly_logs") - plan = models.CharField(max_length=8, choices=MONTHLY_PLAN_CHOICES) + member = models.ForeignKey(Member, related_name="memberships") + plan = models.CharField(max_length=8, choices=MEMBERSHIP_CHOICES) start_date = models.DateField() end_date = models.DateField(blank=True, null=True) rate = models.IntegerField(default=0) @@ -350,16 +350,16 @@ class MonthlyLog(models.Model): guest_dropins = models.IntegerField(default=0) guest_of = models.ForeignKey(Member, blank=True, null=True, related_name="monthly_guests") - objects = MonthlyLog_Manager() + objects = Membership_Manager() def save(self, *args, **kwargs): - if MonthlyLog.objects.by_date(self.start_date).exclude(pk=self.pk).filter(member=self.member).count() != 0: - raise Exception('Already have a Monthly Log for that start date') - if self.end_date and MonthlyLog.objects.by_date(self.end_date).exclude(pk=self.pk).filter(member=self.member).count() != 0: - raise Exception('Already have a Monthly Log for that end date: %s' % MonthlyLog.objects.by_date(self.end_date).exclude(pk=self.pk).filter(member=self.member)) + if Membership.objects.by_date(self.start_date).exclude(pk=self.pk).filter(member=self.member).count() != 0: + raise Exception('Already have a Membership for that start date') + if self.end_date and Membership.objects.by_date(self.end_date).exclude(pk=self.pk).filter(member=self.member).count() != 0: + raise Exception('Already have a Membership for that end date: %s' % Membership.objects.by_date(self.end_date).exclude(pk=self.pk).filter(member=self.member)) if self.end_date and self.start_date > self.end_date: - raise Exception('A Monthly Log cannot start after it ends') - super(MonthlyLog, self).save(*args, **kwargs) + raise Exception('A Membership cannot start after it ends') + super(Membership, self).save(*args, **kwargs) def is_anniversary_day(self, test_date): # Do something smarter if we're at the end of February @@ -375,24 +375,24 @@ def __str__(self): return '%s - %s' % (self.start_date, self.member) def get_admin_url(self): - return urlresolvers.reverse('admin:staff_monthlylog_change', args=[self.id]) + return urlresolvers.reverse('admin:staff_membership_change', args=[self.id]) class Meta: - verbose_name = "Monthly Log" - verbose_name_plural = "Monthly Logs" + verbose_name = "Membership" + verbose_name_plural = "Memberships" ordering = ['start_date']; class ExitTask(models.Model): - """Tasks which are to be completed when a monthly member ends their monthly logs.""" + """Tasks which are to be completed when a monthly member ends their memberships.""" name = models.CharField(max_length=64) description = models.CharField(max_length=512) order = models.SmallIntegerField() def uncompleted_members(self): - return [member for member in Member.objects.filter(monthly_logs__isnull=False).exclude(exittaskcompleted__task=self).distinct() if not member.is_monthly()] + return [member for member in Member.objects.filter(memberships__isnull=False).exclude(exittaskcompleted__task=self).distinct() if not member.is_monthly()] def completed_members(self): - return Member.objects.filter(monthly_logs__end_date__gt=date.today()).filter(exittaskcompleted__task=self).distinct() + return Member.objects.filter(memberships__end_date__gt=date.today()).filter(exittaskcompleted__task=self).distinct() def __str__(self): return self.name @@ -424,7 +424,7 @@ class Onboard_Task(models.Model): def uncompleted_members(self): if self.monthly_only: - eligable_members = Member.objects.filter(monthly_logs__start_date__isnull=False).filter(Q(monthly_logs__end_date__gt=date.today()) | Q(monthly_logs__end_date__isnull=True)) + eligable_members = Member.objects.filter(memberships__start_date__isnull=False).filter(Q(memberships__end_date__gt=date.today()) | Q(memberships__end_date__isnull=True)) else: eligable_members = Member.objects.all() return eligable_members.exclude(onboard_task_completed__task=self).distinct() diff --git a/staff/templates/staff/bill_table.frag b/staff/templates/staff/bill_table.frag index d82074be1..a83b641f1 100644 --- a/staff/templates/staff/bill_table.frag +++ b/staff/templates/staff/bill_table.frag @@ -24,12 +24,12 @@ {% endif %} {% endif %} - {% if bill.monthly_log %} + {% if bill.membership %} {% if bill.new_member_deposit %} diff --git a/staff/templates/staff/bills.html b/staff/templates/staff/bills.html index 9d4d965eb..d2c30d966 100644 --- a/staff/templates/staff/bills.html +++ b/staff/templates/staff/bills.html @@ -72,9 +72,9 @@

/ Amount: ${{ bill.amount }}

- {% if bill.monthly_log %} + {% if bill.membership %} {% endif %} {% if bill.new_member_deposit %} diff --git a/staff/templates/staff/member_activity.html b/staff/templates/staff/member_activity.html index 571b5c9ed..05f0fcb03 100644 --- a/staff/templates/staff/member_activity.html +++ b/staff/templates/staff/member_activity.html @@ -10,8 +10,8 @@ {% block content %}

Activity for {{ member.first_name }} {{ member.last_name }}:

-{% if member.monthly_logs.all %} -

Monthly logs:

+{% if member.memberships.all %} +

Memberships:

{{ log.plan }} {{ log.start_date|date:"M d, Y" }}
Monthly: - {{ bill.monthly_log.plan }} @ ${{ bill.monthly_log.rate }}: - started {{ bill.monthly_log.start_date|date:"m/d/y"}}{% if bill.monthly_log.end_date %}, ended {{ bill.monthly_log.end_date|date:"m/d/y"}}{% endif %} + {{ bill.membership.plan }} @ ${{ bill.membership.rate }}: + started {{ bill.membership.start_date|date:"m/d/y"}}{% if bill.membership.end_date %}, ended {{ bill.membership.end_date|date:"m/d/y"}}{% endif %}
@@ -20,7 +20,7 @@

Monthly logs:

- {% for log in member.monthly_logs.all reversed %} + {% for log in member.memberships.all reversed %} diff --git a/staff/templates/staff/member_detail.html b/staff/templates/staff/member_detail.html index 914d9ef39..2e8cb1287 100755 --- a/staff/templates/staff/member_detail.html +++ b/staff/templates/staff/member_detail.html @@ -59,15 +59,15 @@

Member Detail

- {% if member.last_monthly_log %} + {% if member.last_membership %} - + {% endif %} diff --git a/staff/templates/staff/member_transactions.html b/staff/templates/staff/member_transactions.html index 18ac56dbe..a141e0409 100644 --- a/staff/templates/staff/member_transactions.html +++ b/staff/templates/staff/member_transactions.html @@ -41,8 +41,8 @@

Open Bills:

{% endfor %}
Plan Notes
{{ log.plan }} {{ log.start_date }}
Membership Type {{ member.membership_type }} - {% if member.last_monthly_log %}{% if not member.last_monthly_log.end_date %} - [edit] + {% if member.last_membership %}{% if not member.last_membership.end_date %} + [edit] {% endif %}{% endif %}
Plan Start{{ member.last_monthly_log.start_date|date:"Y-m-d" }}{{ member.last_membership.start_date|date:"Y-m-d" }}
-{% if member.monthly_logs.all %} -

Monthly logs:

+{% if member.memberships.all %} +

Memberships:

@@ -51,7 +51,7 @@

Monthly logs:

- {% for log in member.monthly_logs.all reversed %} + {% for log in member.memberships.all reversed %} diff --git a/staff/templates/staff/search_and_quicklinks.frag b/staff/templates/staff/search_and_quicklinks.frag index 3fc549b8a..9e6f55d6f 100644 --- a/staff/templates/staff/search_and_quicklinks.frag +++ b/staff/templates/staff/search_and_quicklinks.frag @@ -10,7 +10,7 @@ Quicklinks: record activity | - add monthly log | + add membership | add member diff --git a/staff/templates/staff/signup.html b/staff/templates/staff/signup.html index fe93c0921..bec7d371a 100644 --- a/staff/templates/staff/signup.html +++ b/staff/templates/staff/signup.html @@ -12,7 +12,7 @@

Member Signup:

{% if page_message %} diff --git a/staff/templates/staff/stats_monthly.html b/staff/templates/staff/stats_monthly.html index 1157a4c17..e1b000ab4 100644 --- a/staff/templates/staff/stats_monthly.html +++ b/staff/templates/staff/stats_monthly.html @@ -13,7 +13,7 @@

Stats - Monthly members:

{% include "staff/stats_menu.frag" %}
- Total Monthly Members: {{ monthly_logs.count }}    + Total Monthly Members: {{ memberships.count }}    Total Monthly Income: ${{ total_income }}
@@ -27,7 +27,7 @@

Stats - Monthly members:

- {% for log in monthly_logs %} + {% for log in memberships %} diff --git a/staff/tests.py b/staff/tests.py index 5854cd497..8ba7d29d1 100644 --- a/staff/tests.py +++ b/staff/tests.py @@ -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 from staff.views import beginning_of_next_month, first_days_in_months @@ -26,10 +26,10 @@ class TasksTestCase(TestCase): def setUp(self): self.user1 = User.objects.create(username='member_one', first_name='Member', last_name='One') - MonthlyLog.objects.create(member=self.user1.get_profile(), plan='Resident', start_date=date(2008, 6, 26), rate=settings.RESIDENT_MONTHLY_FEE) + Membership.objects.create(member=self.user1.get_profile(), plan='Resident', start_date=date(2008, 6, 26), rate=settings.RESIDENT_MONTHLY_FEE) self.user2 = User.objects.create(username='member_two', first_name='Member', last_name='Two') - MonthlyLog.objects.create(member=self.user2.get_profile(), plan='Resident', start_date=date(2008, 6, 26), end_date=(date.today() - timedelta(days=1)), rate=settings.RESIDENT_MONTHLY_FEE) + Membership.objects.create(member=self.user2.get_profile(), plan='Resident', start_date=date(2008, 6, 26), end_date=(date.today() - timedelta(days=1)), rate=settings.RESIDENT_MONTHLY_FEE) self.on_task_1 = Onboard_Task.objects.create(name="Welcome Coffee Mug", order=1, description="Print a coffee mug", monthly_only=True) self.on_task_2 = Onboard_Task.objects.create(name="Entry Tat", order=2, description="Tattoo a bar code on the neck.", monthly_only=False) @@ -43,7 +43,7 @@ def testTasks(self): self.assertEqual(ExitTaskCompleted.objects.filter(member=self.user1.profile).count(), 0) self.assertTrue(self.user1.profile in self.on_task_1.uncompleted_members()) - self.assertFalse(self.user2.profile in self.on_task_1.uncompleted_members()) # ended monthly logs don't require onboard tasks + self.assertFalse(self.user2.profile in self.on_task_1.uncompleted_members()) # ended memberships don't require onboard tasks Onboard_Task_Completed.objects.create(member=self.user1.profile, task=self.on_task_1) self.assertFalse(self.user1.profile in self.on_task_1.uncompleted_members()) @@ -62,12 +62,12 @@ def setUp(self): self.profile1 = self.user1.profile self.profile1.neighborhood=self.neighborhood1 self.profile1.save() - MonthlyLog.objects.create(member=self.user1.get_profile(), plan='Basic', start_date=date(2008, 2, 26), end_date=date(2010, 6, 25), rate=settings.BASIC_MONTHLY_FEE) - MonthlyLog.objects.create(member=self.user1.get_profile(), plan='Resident', start_date=date(2010, 6, 26), rate=settings.RESIDENT_MONTHLY_FEE) + Membership.objects.create(member=self.user1.get_profile(), plan='Basic', start_date=date(2008, 2, 26), end_date=date(2010, 6, 25), rate=settings.BASIC_MONTHLY_FEE) + Membership.objects.create(member=self.user1.get_profile(), plan='Resident', start_date=date(2010, 6, 26), rate=settings.RESIDENT_MONTHLY_FEE) self.user2 = User.objects.create(username='member_two', first_name='Member', last_name='Two') self.profile2 = self.user2.profile - MonthlyLog.objects.create(member=self.user2.get_profile(), plan='PT5', start_date=date(2009, 1, 1), rate=settings.PT5_MONTHLY_FEE) + Membership.objects.create(member=self.user2.get_profile(), plan='PT5', start_date=date(2009, 1, 1), rate=settings.PT5_MONTHLY_FEE) self.user3 = User.objects.create(username='member_three', first_name='Member', last_name='Three') self.profile3 = self.user3.profile @@ -79,14 +79,14 @@ def setUp(self): self.profile4 = self.user4.profile self.profile4.neighborhood=self.neighborhood1 self.profile4.save() - MonthlyLog.objects.create(member=self.user4.get_profile(), plan='PT5', start_date=date(2009, 1, 1), end_date=date(2010, 1, 1), rate=settings.PT5_MONTHLY_FEE) + Membership.objects.create(member=self.user4.get_profile(), plan='PT5', start_date=date(2009, 1, 1), end_date=date(2010, 1, 1), rate=settings.PT5_MONTHLY_FEE) def testInfoMethods(self): - self.assertTrue(self.user1.profile in Member.objects.members_by_monthly_log_type('Resident')) - self.assertFalse(self.user1.profile in Member.objects.members_by_monthly_log_type('Basic')) - self.assertTrue(self.user2.profile in Member.objects.members_by_monthly_log_type('PT5')) - self.assertFalse(self.user2.profile in Member.objects.members_by_monthly_log_type('Resident')) + self.assertTrue(self.user1.profile in Member.objects.members_by_membership_type('Resident')) + self.assertFalse(self.user1.profile in Member.objects.members_by_membership_type('Basic')) + self.assertTrue(self.user2.profile in Member.objects.members_by_membership_type('PT5')) + self.assertFalse(self.user2.profile in Member.objects.members_by_membership_type('Resident')) self.assertTrue(self.user1.profile in Member.objects.members_by_neighborhood(self.neighborhood1)) self.assertFalse(self.user2.profile in Member.objects.members_by_neighborhood(self.neighborhood1)) @@ -103,24 +103,24 @@ def setUp(self): self.user3 = User.objects.create(username='member_three', first_name='Member', last_name='Three') self.user4 = User.objects.create(username='member_four', first_name='Member', last_name='Four') - MonthlyLog.objects.create(member=self.user1.get_profile(), plan='Resident', start_date=date(2008, 6, 26), rate=settings.RESIDENT_MONTHLY_FEE) + Membership.objects.create(member=self.user1.get_profile(), plan='Resident', start_date=date(2008, 6, 26), rate=settings.RESIDENT_MONTHLY_FEE) - MonthlyLog.objects.create(member=self.user2.get_profile(), plan='Resident', start_date=date(2008, 1, 31), rate=settings.RESIDENT_MONTHLY_FEE) + Membership.objects.create(member=self.user2.get_profile(), plan='Resident', start_date=date(2008, 1, 31), rate=settings.RESIDENT_MONTHLY_FEE) - MonthlyLog.objects.create(member=self.user3.get_profile(), plan='PT15', start_date=date(2008, 2, 1), end_date=date(2010, 6, 20), rate=settings.PT15_MONTHLY_FEE) - MonthlyLog.objects.create(member=self.user3.get_profile(), plan='Basic', start_date=date(2010, 6, 21), rate=settings.BASIC_MONTHLY_FEE) + Membership.objects.create(member=self.user3.get_profile(), plan='PT15', start_date=date(2008, 2, 1), end_date=date(2010, 6, 20), rate=settings.PT15_MONTHLY_FEE) + Membership.objects.create(member=self.user3.get_profile(), plan='Basic', start_date=date(2010, 6, 21), rate=settings.BASIC_MONTHLY_FEE) for day in range(2,19): DailyLog.objects.create(member=self.user3.get_profile(), visit_date=date(2010, 6, day), payment='Bill') - MonthlyLog.objects.create(member=self.user4.get_profile(), plan='PT5', start_date=date(2008, 2, 1), end_date=date(2010, 6, 10), rate=settings.PT5_MONTHLY_FEE) - MonthlyLog.objects.create(member=self.user4.get_profile(), plan='Resident', start_date=date(2010, 6, 11), rate=settings.RESIDENT_MONTHLY_FEE) + Membership.objects.create(member=self.user4.get_profile(), plan='PT5', start_date=date(2008, 2, 1), end_date=date(2010, 6, 10), rate=settings.PT5_MONTHLY_FEE) + Membership.objects.create(member=self.user4.get_profile(), plan='Resident', start_date=date(2010, 6, 11), rate=settings.RESIDENT_MONTHLY_FEE) for day in range(2,11): DailyLog.objects.create(member=self.user4.get_profile(), visit_date=date(2010, 6, day), payment='Bill') - def testMonthlyLog(self): - orig_log = MonthlyLog.objects.create(member=self.user1.get_profile(), plan='Resident', start_date=date(2008, 2, 10), rate=475) + def testMembership(self): + orig_log = Membership.objects.create(member=self.user1.get_profile(), plan='Resident', start_date=date(2008, 2, 10), rate=475) self.assertTrue(orig_log.is_anniversary_day(date(2010, 4, 10))) orig_log.end_date = orig_log.start_date + timedelta(days=31) orig_log.save() - new_log = MonthlyLog(start_date=orig_log.end_date, member=orig_log.member, plan=orig_log.plan, rate=orig_log.rate) + new_log = Membership(start_date=orig_log.end_date, member=orig_log.member, plan=orig_log.plan, rate=orig_log.rate) self.assertRaises(Exception, new_log.save) # the start date is the same as the previous plan's end date, which is an error new_log.start_date = orig_log.end_date + timedelta(days=1) new_log.save() @@ -144,13 +144,13 @@ def testRun(self): if day.month == 6 and day.day == 10: self.assertTrue(member4.last_bill() != None) self.assertTrue(member4.last_bill().created.month == day.month and member4.last_bill().created.day == day.day) - self.assertEqual(member4.last_bill().monthly_log, MonthlyLog.objects.get(member=member4, plan="PT5")) + self.assertEqual(member4.last_bill().membership, Membership.objects.get(member=member4, plan="PT5")) self.assertEqual(member4.last_bill().dropins.count(), 9) # dropins on 6/2 - 6/10 self.assertEqual(member4.last_bill().amount, (member4.last_bill().dropins.count() - 5) * settings.PT5_DROPIN_FEE) if day.month == 6 and day.day == 11: self.assertTrue(member4.last_bill() != None) self.assertTrue(member4.last_bill().created.month == day.month and member4.last_bill().created.day == day.day) - self.assertEqual(member4.last_bill().monthly_log, MonthlyLog.objects.get(member=member4, plan="Resident")) + self.assertEqual(member4.last_bill().membership, Membership.objects.get(member=member4, plan="Resident")) self.assertEqual(member4.last_bill().dropins.count(), 0) if day.month == 6 and day.day == 20: @@ -164,11 +164,11 @@ def testRun(self): self.assertEqual(member3.last_bill().dropins.count(), 0) if day.day == 26: - self.assertTrue(member1.last_monthly_log().is_anniversary_day(day)) + self.assertTrue(member1.last_membership().is_anniversary_day(day)) member_bills = member1.bills.all().order_by('-created') self.assertTrue(len(member_bills) > 0) - self.assertTrue(member_bills[0].monthly_log == member1.last_monthly_log()) + self.assertTrue(member_bills[0].membership == member1.last_membership()) if day.month == 6 and day.day == 30: - self.assertTrue(member2.last_monthly_log().is_anniversary_day(day)) + self.assertTrue(member2.last_membership().is_anniversary_day(day)) # 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. diff --git a/staff/views.py b/staff/views.py index a3adcf947..a386c44ce 100755 --- a/staff/views.py +++ b/staff/views.py @@ -23,8 +23,8 @@ def members(request): if not request.user.is_staff: return HttpResponseRedirect(reverse('members.views.user', args=[], kwargs={'username':request.user.username})) plans = [] - for plan_id, plan_name in MONTHLY_PLAN_CHOICES: - plans.append({ 'name':plan_name, 'id':plan_id, 'members':Member.objects.members_by_monthly_log_type(plan_id), 'count':len(Member.objects.members_by_monthly_log_type(plan_id))}) + for plan_id, plan_name in MEMBERSHIP_CHOICES: + plans.append({ 'name':plan_name, 'id':plan_id, 'members':Member.objects.members_by_membership_type(plan_id), 'count':len(Member.objects.members_by_membership_type(plan_id))}) return render_to_response('staff/members.html', { 'plans': plans, 'member_search_form':MemberSearchForm() }, context_instance=RequestContext(request)) @staff_member_required @@ -204,7 +204,7 @@ def __init__(self, year, month): @staff_member_required def stats_membership_history(request): - start_month = min(DailyLog.objects.all().order_by('visit_date')[0].visit_date, MonthlyLog.objects.all().order_by('start_date')[0].start_date) + start_month = min(DailyLog.objects.all().order_by('visit_date')[0].visit_date, Membership.objects.all().order_by('start_date')[0].start_date) start_month = date(year=start_month.year, month=start_month.month, day=1) end_month = date.today() end_month = date(year=end_month.year, month=end_month.month, day=1) @@ -243,18 +243,18 @@ def calculate_dropins(start_date, end_date): return (all_logs.filter(payment='Visit').distinct().count(), all_logs.filter(payment='Trial').distinct().count(), all_logs.filter(payment='Waved').distinct().count(), all_logs.filter(payment='Bill').distinct().count()) def calculate_monthly_low_high(plan_name, dates): - """returns a tuple of (min, max) for number of monthly_logs in the date range of dates""" + """returns a tuple of (min, max) for number of memberships in the date range of dates""" high = 0 low = 100000000 for working_date in dates: - num_residents = MonthlyLog.objects.by_date(working_date).filter(plan=plan_name).count() + num_residents = Membership.objects.by_date(working_date).filter(plan=plan_name).count() high = max(high, num_residents) low = min(low, num_residents) return (low, high) @staff_member_required def stats_history(request): - logs = [log for log in MonthlyLog.objects.all()] + logs = [log for log in Membership.objects.all()] end_date = date.today() if len(logs) > 0: start_date = logs[0].start_date @@ -263,28 +263,28 @@ def stats_history(request): monthly_stats = [{'start_date':d, 'end_date':beginning_of_next_month(d) - timedelta(days=1)} for d in first_days_in_months(start_date, end_date)] for stat in monthly_stats: - stat['monthly_total'] = MonthlyLog.objects.by_date(stat['end_date']).count() - stat['started'] = MonthlyLog.objects.filter(start_date__range=(stat['start_date'], stat['end_date'])).count() - stat['ended'] = MonthlyLog.objects.filter(end_date__range=(stat['start_date'], stat['end_date'])).count() + stat['monthly_total'] = Membership.objects.by_date(stat['end_date']).count() + stat['started'] = Membership.objects.filter(start_date__range=(stat['start_date'], stat['end_date'])).count() + stat['ended'] = Membership.objects.filter(end_date__range=(stat['start_date'], stat['end_date'])).count() monthly_stats.reverse() return render_to_response('staff/stats_history.html', { 'monthly_stats':monthly_stats }, context_instance=RequestContext(request)) @staff_member_required def stats_monthly(request): # Pull all the monthly members - monthly_logs = MonthlyLog.objects.filter(end_date__isnull=True).order_by('start_date') + memberships = Membership.objects.filter(end_date__isnull=True).order_by('start_date') total_income = 0 - for log in monthly_logs: + for log in memberships: total_income = total_income + log.rate - return render_to_response('staff/stats_monthly.html', {'monthly_logs':monthly_logs, 'total_income': total_income}, context_instance=RequestContext(request)) + return render_to_response('staff/stats_monthly.html', {'memberships':memberships, 'total_income': total_income}, context_instance=RequestContext(request)) @staff_member_required def stats_member_types(request): types_dict = {} - for plan_id, plan_name in MONTHLY_PLAN_CHOICES: - types_dict[plan_id] = len(Member.objects.members_by_monthly_log_type(plan_id)) + for plan_id, plan_name in MEMBERSHIP_CHOICES: + types_dict[plan_id] = len(Member.objects.members_by_membership_type(plan_id)) - plan_ids = [t[0] for t in MONTHLY_PLAN_CHOICES] + plan_ids = [t[0] for t in MEMBERSHIP_CHOICES] for member in Member.objects.all(): type_id = member.membership_type() if type_id in plan_ids: continue @@ -317,7 +317,7 @@ def stats_neighborhood(request): def member_detail(request, member_id): member = get_object_or_404(Member, pk=member_id) daily_logs = DailyLog.objects.filter(member=member).order_by('visit_date').reverse() - monthly_logs = MonthlyLog.objects.filter(member=member).order_by('start_date').reverse() + memberships = Membership.objects.filter(member=member).order_by('start_date').reverse() if request.method == 'POST': if 'save_onboard_task' in request.POST: @@ -355,8 +355,8 @@ def activity(request): days = [{'date':start_date + timedelta(days=i)} for i in range((end_date - start_date).days) ] for day in days: day['daily_logs'] = DailyLog.objects.filter(visit_date=day['date']).count() - day['membership'] = MonthlyLog.objects.by_date(day['date']).count() - day['residents'] = MonthlyLog.objects.by_date(day['date']).filter(plan='Resident').count() + day['membership'] = Membership.objects.by_date(day['date']).count() + day['residents'] = Membership.objects.by_date(day['date']).filter(plan='Resident').count() day['occupancy'] = day['daily_logs'] + day['residents'] max_membership = 0
Plan Notes
{{ log.plan }} {{ log.start_date|date:"m/d/y" }} Note
{{ log.member }} {{ log.start_date }}