Kevin Veroneau avatar Kevin Veroneau committed 810e23a

Added ability for roommates to make partial payments.

Comments (0)

Files changed (4)

pcbank/migrations/0004_auto__add_field_roommatebill_amount.py

+# -*- coding: 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):
+        # Adding field 'RoommateBill.amount'
+        db.add_column('pcbank_roommatebill', 'amount',
+                      self.gf('django.db.models.fields.DecimalField')(default=0, max_digits=5, decimal_places=2),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'RoommateBill.amount'
+        db.delete_column('pcbank_roommatebill', 'amount')
+
+
+    models = {
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", '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'})
+        },
+        'pcbank.bank': {
+            'Meta': {'object_name': 'Bank'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'balance': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'}),
+            'card': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '200'})
+        },
+        'pcbank.bill': {
+            'Meta': {'object_name': 'Bill'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '5', 'decimal_places': '2'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'paid': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'payee': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['pcbank.Payee']"})
+        },
+        'pcbank.cheque': {
+            'Meta': {'object_name': 'Cheque'},
+            'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+            'memo': ('django.db.models.fields.TextField', [], {}),
+            'number': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'post_date': ('django.db.models.fields.DateField', [], {}),
+            'transaction': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['pcbank.Transaction']", 'null': 'True', 'blank': 'True'})
+        },
+        'pcbank.creditcard': {
+            'Meta': {'object_name': 'CreditCard'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'balance': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'}),
+            'credit': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'}),
+            'due_date': ('django.db.models.fields.DateField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'min_payment': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '200'})
+        },
+        'pcbank.income': {
+            'Meta': {'object_name': 'Income'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'per_month': ('django.db.models.fields.IntegerField', [], {}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '80'})
+        },
+        'pcbank.payee': {
+            'Meta': {'ordering': "['due_date']", 'object_name': 'Payee'},
+            'account': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'due_date': ('django.db.models.fields.DateField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'split_by': ('django.db.models.fields.IntegerField', [], {}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'})
+        },
+        'pcbank.roommate': {
+            'Meta': {'object_name': 'Roommate'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+            'total_given': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'})
+        },
+        'pcbank.roommatebill': {
+            'Meta': {'object_name': 'RoommateBill'},
+            'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '5', 'decimal_places': '2'}),
+            'for_bill': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['pcbank.Bill']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'paid': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'pay_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+            'roommate': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['pcbank.Roommate']"})
+        },
+        'pcbank.transaction': {
+            'Meta': {'ordering': "['-date']", 'object_name': 'Transaction'},
+            'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'date': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'from_ct': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'fromtrans_set'", 'to': "orm['contenttypes.ContentType']"}),
+            'from_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'memo': ('django.db.models.fields.CharField', [], {'max_length': '60', 'null': 'True', 'blank': 'True'}),
+            'object_id': ('django.db.models.fields.PositiveIntegerField', [], {})
+        }
+    }
+
+    complete_apps = ['pcbank']
     for_bill = models.ForeignKey(Bill)
     paid = models.BooleanField()
     pay_date = models.DateField(blank=True, null=True)
+    amount = models.DecimalField(max_digits=5, decimal_places=2)
     def __unicode__(self):
         return u"%s" % self.for_bill.payee
-    def amount(self):
-        return self.for_bill.amount / self.for_bill.payee.split_by
+    def set_amount(self):
+        self.amount = self.for_bill.amount / self.for_bill.payee.split_by
     def past_due(self):
         if self.pay_date != None:
             if self.pay_date > self.for_bill.payee.due_date:

pcbank/templates/pcbank/roommatebill_detail.html

 </table>
 {% if not object.paid %}
 <form action="{{object.make_payment}}" method="post">{% csrf_token %}
-<b>Payment transfer:</b> {% bank_list %}
+<b>Payment transfer:</b> <input type="text" value="{{object.amount|floatformat:2}}" name="amount"/>{% bank_list %}
 <input type="submit" value="Do Payment" class="btn btn-primary" />
 </form>
 {% endif %}
     roommate = Roommate.objects.get(pk=object_id)
     bill = Bill.objects.get(pk=req.POST.get('bill_id', 1))
     rbill = RoommateBill(roommate=roommate, for_bill=bill)
+    rbill.set_amount()
     rbill.save()
     return redirect(rbill)
 
         raise PermissionDenied
     if req.POST.get('bank_id', 'None') == 'None':
         raise PermissionDenied
+    try:
+        amount = Decimal(req.POST.get('amount','0.00'))
+    except:
+        raise PermissionDenied
     rbill = RoommateBill.objects.get(pk=object_id)
+    if amount > rbill.amount:
+        # I am really over using PermisionDenied!!!  Don't do it!
+        raise PermissionDenied
     bank = Bank.objects.get(pk=req.POST.get('bank_id', 1))
-    bank.balance += rbill.amount()
+    bank.balance += amount
     bank.save()
-    rbill.paid = True
-    rbill.pay_date = datetime.date.today()
+    rbill.amount -= amount
+    if rbill.amount == 0:
+        rbill.paid = True
+        rbill.pay_date = datetime.date.today()
     rbill.save()
     rmate = rbill.roommate
-    rmate.total_given += rbill.amount()
+    rmate.total_given += amount
     rmate.save()
-    t = Transaction(from_obj=rbill.roommate, amount=rbill.amount(), content_object=bank)
+    t = Transaction(from_obj=rbill.roommate, amount=amount, content_object=bank)
     t.save()
     return redirect('view-bank', object_id=bank.pk)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.