Meaning of MemberPayment.fee_year has been changed. DB migration.
authorgniibe <gniibe@fsij.org>
Thu, 27 May 2010 03:13:19 +0000 (12:13 +0900)
committergniibe <gniibe@fsij.org>
Thu, 27 May 2010 03:13:19 +0000 (12:13 +0900)
+migrate+/20100527_membership.sql [new file with mode: 0644]
+migrate+/20100528_gc.sql [new file with mode: 0644]
.hgignore
ChangeLog
README
membership/models.py
membership/views.py
templates/membership/edit_member_payment.html
templates/membership/member_payment.html

diff --git a/+migrate+/20100527_membership.sql b/+migrate+/20100527_membership.sql
new file mode 100644 (file)
index 0000000..9f63c33
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Changed meaning of the value of field fee_year of membership_memberpayment 
+ */
+BEGIN TRANSACTION;
+
+create table membership_memberpayment_new (
+    "id" integer NOT NULL PRIMARY KEY,
+    "member_id" integer NOT NULL REFERENCES "membership_member" ("id"),
+    "date" date NOT NULL,
+    "fee_year" integer NOT NULL,
+    "member_type" varchar(1) NOT NULL,
+    "contribution" integer NOT NULL,
+    "le_id" integer NULL UNIQUE
+);
+insert into membership_memberpayment_new (
+       id, member_id, date, fee_year, member_type, contribution, le_id)
+    select id, member_id, date,
+       case when fee_year = 0 then 9999
+                   when fee_year = 2002 then 2002
+                   when fee_year = 2003 then 2003
+                   when fee_year = 2004 then 2004
+                   when fee_year = 2005 then 2005
+                   when fee_year = 2006 then 2006
+                   when fee_year = 2007 then 2007
+                   when fee_year = 2008 then 2008
+                   when fee_year = 2009 then 2009
+                   when fee_year = 9999 then 0 end, member_type, contribution, le_id
+    from membership_memberpayment;
+
+alter table membership_memberpayment rename to membership_memberpayment20100527;
+alter table membership_memberpayment_new rename to membership_memberpayment;
+-- drop table membership_memberpayment20100527
+COMMIT;
diff --git a/+migrate+/20100528_gc.sql b/+migrate+/20100528_gc.sql
new file mode 100644 (file)
index 0000000..cd514aa
--- /dev/null
@@ -0,0 +1,6 @@
+drop table membership_corporatemember20090804;
+drop table membership_member20090730;
+drop table membership_member20090801;
+drop table membership_memberpayment20090730;
+drop table membership_memberpayment20090801;
+drop table membership_memberpayment20100527;
index 207c1bf..e3cb5c0 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -1,5 +1,6 @@
 syntax: glob
 *.db
+*.db.*
 *.mo
 *.pyc
 *~
index ab7a597..ef5f823 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2010-05-27  NIIBE Yutaka  <gniibe@fsij.org>
 
+       * +migrate+/20100528_gc.sql: New.
+
+       DB migration.
+       * +migrate+/20100527_membership.sql: New migration script.
+       * membership/models.py (MemberPayment.fee_year): Change the
+       meaning of special value (was: 9999==Nyuukai-kin, 0==Maeuke-kin).
+       * templates/membership/member_payment.html: Follow the change.
+       * templates/membership/edit_member_payment.html: Likewise.
+       * membership/views.py (edit_member_payment, member_payment): Likewise.
+
        * templates/membership/member_payment.html: Added link to transaction.
        Handle Maeuke-kin.
 
diff --git a/README b/README
index 74990f3..959e3de 100644 (file)
--- a/README
+++ b/README
@@ -1,11 +1,12 @@
 INSTALL
 =======
 
-Modules needed:
+Packages needed:
   * python-django
   * python-django-doc
   * python-markdown
   * python-pysqlite2
+  * sqlite3
 
 Then, create a file
   $ cat >settings_private.py
@@ -32,3 +33,16 @@ Accounting
 /accounting/   *** index should be implemented
 /accounting/[0-9]+   *** annual index should be implemented
  close (forbid to change) the transactions
+
+
+DB migration
+============
+
+When we change schema (or meaning of value) and DB migration is
+needed, we write SQL script under +migrate+ directory, and then run
+the SQL by dbshell.
+
+Here is an example:
+
+ $ cp -p fsij.db fsij.db.20100527
+ $ python manage.py dbshell <+migrate+/20100527_membership.sql
index 11424ce..8ccbd7f 100644 (file)
@@ -56,7 +56,7 @@ class MemberPayment(models.Model):
     date = models.DateField()
     #
     # FEE_YEAR: Financial year to which this payment is connected
-    #           9999 means Admission-fee, 0 means Advance-payment
+    #           0 means Admission-fee, 9999 means Advance-payment
     #
     fee_year = models.IntegerField()
     # member type as of payment time
@@ -65,9 +65,9 @@ class MemberPayment(models.Model):
     contribution = models.IntegerField() # Kuchi-Suu in Japanese
     le = models.ForeignKey(LedgerEntry, unique=True, blank=True, null=True)
     def __unicode__(self):
-        if self.fee_year == 0:
+        if self.fee_year == 9999:
             payment_fee_str = u'前受金'
-        elif self.fee_year == 9999:
+        elif self.fee_year == 0:
             payment_fee_str = u'入会金'
         else:
             payment_fee_str = "%04d" % self.fee_year
index 3e06179..a6ef97b 100644 (file)
@@ -137,7 +137,8 @@ def member_payment(request, member, manage=False):
             end_year = end_year - 1
         fee_list = range(start_year, end_year + 1)
         if member.member_type != 'A':
-            fee_list.append(9999) # Admission fee
+            fee_list.append(9999)    # Advance payment
+            fee_list.append(0) # Admission fee
         fee_list_in_payments = map(lambda (p): p.fee_year, member.memberpayment_set.all())
         fee_list = filter(lambda (f): not f in fee_list_in_payments, fee_list)
     else:
@@ -215,8 +216,8 @@ def edit_member_payment(request, member_payment):
             end_year = end_year - 1
         fee_list = range(start_year, end_year + 1)
         if member.member_type != 'A':
-            fee_list.append(0)    # Advance payment
-            fee_list.append(9999) # Admission fee
+            fee_list.append(9999)    # Advance payment
+            fee_list.append(0) # Admission fee
         fee_list_in_payments = map(lambda (p): p.fee_year, member.memberpayment_set.all())
         if orig_fee_year == 0:
             fee_list = filter(lambda (f): not f in fee_list_in_payments, fee_list)
index dc94517..c759c07 100644 (file)
@@ -23,8 +23,8 @@
 {% for fee_year in fee_list %}
 <option value="{{ fee_year }}"
  {% ifequal fee_year orig_fee_year %}selected{% endifequal %}>
-{% ifequal fee_year 0 %}前受金{% else %}
-{% ifequal fee_year 9999 %}入会金{% else %}{{ fee_year }}年度{% endifequal %}
+{% ifequal fee_year 9999 %}前受金{% else %}
+{% ifequal fee_year 0 %}入会金{% else %}{{ fee_year }}年度{% endifequal %}
 {% endifequal %}
 </option>
 {% endfor %}
@@ -59,8 +59,8 @@
 {% if p.le %}</a>{% endif %}
 </td>
 <td>
-{% ifequal p.fee_year 0 %}前受金{% else %}
-{% ifequal p.fee_year 9999 %}入会金{% else %}{{ p.fee_year }}年度{% endifequal %}
+{% ifequal p.fee_year 9999 %}前受金{% else %}
+{% ifequal p.fee_year 0 %}入会金{% else %}{{ p.fee_year }}年度{% endifequal %}
 {% endifequal %}
 {% ifnotequal p.member_type member.member_type %}
 [ {{ p.get_member_type_display }} ]
index 444705b..e4b95e0 100644 (file)
@@ -28,10 +28,10 @@ parent.list.location.reload()
 {% if p.le %}</a>{% endif %}
 </td>
 <td>
-  {% ifequal p.fee_year 0 %}
+  {% ifequal p.fee_year 9999 %}
   前受金
   {% else %}
-  {% ifequal p.fee_year 9999 %}
+  {% ifequal p.fee_year 0 %}
   入会金
   {% else %}
   {{ p.fee_year }}年度
@@ -56,7 +56,11 @@ parent.list.location.reload()
 <td>
 <select name="fee_year">
 {% for fee_year in fee_list %}
-<option value="{{ fee_year }}">{% ifequal fee_year 9999 %}入会金{% else %}{{ fee_year }}年度{% endifequal %}</option>
+<option value="{{ fee_year }}">
+{% ifequal fee_year 9999 %}前受金{% else %}
+{% ifequal fee_year 0 %}入会金{% else %}{{ fee_year }}年度{% endifequal %}
+{% endifequal %}
+</option>
 {% endfor %}
 </select>
 {% ifequal member.member_type 'A' %}
@@ -84,8 +88,8 @@ parent.list.location.reload()
 {{ p.date }}
 </td>
 <td>
-{% ifequal p.fee_year 0 %}前受金{% else %}
-{% ifequal p.fee_year 9999 %}入会金{% else %}{{ p.fee_year }}年度{% endifequal %}
+{% ifequal p.fee_year 9999 %}前受金{% else %}
+{% ifequal p.fee_year 0 %}入会金{% else %}{{ p.fee_year }}年度{% endifequal %}
 {% endifequal %}
 {% ifnotequal p.member_type member.member_type %}
 [ {{ p.get_member_type_display }} ]