aboutsummaryrefslogtreecommitdiff
path: root/ihatemoney
diff options
context:
space:
mode:
Diffstat (limited to 'ihatemoney')
-rw-r--r--ihatemoney/migrations/alembic.ini1
-rw-r--r--ihatemoney/migrations/versions/afbf27e6ef20_add_bill_import_date_field.py26
-rw-r--r--ihatemoney/models.py5
-rw-r--r--ihatemoney/templates/list_bills.html3
-rw-r--r--ihatemoney/tests/tests.py33
5 files changed, 63 insertions, 5 deletions
diff --git a/ihatemoney/migrations/alembic.ini b/ihatemoney/migrations/alembic.ini
index f8ed480..5301449 100644
--- a/ihatemoney/migrations/alembic.ini
+++ b/ihatemoney/migrations/alembic.ini
@@ -7,6 +7,7 @@
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
+script_location = .
# Logging configuration
diff --git a/ihatemoney/migrations/versions/afbf27e6ef20_add_bill_import_date_field.py b/ihatemoney/migrations/versions/afbf27e6ef20_add_bill_import_date_field.py
new file mode 100644
index 0000000..4179155
--- /dev/null
+++ b/ihatemoney/migrations/versions/afbf27e6ef20_add_bill_import_date_field.py
@@ -0,0 +1,26 @@
+"""add bill.import_date field
+
+Revision ID: afbf27e6ef20
+Revises: b78f8a8bdb16
+Create Date: 2018-02-19 20:29:26.286136
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'afbf27e6ef20'
+down_revision = 'b78f8a8bdb16'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ ### commands auto generated by Alembic - please adjust! ###
+ op.add_column('bill', sa.Column('creation_date', sa.Date(), nullable=True))
+ ### end Alembic commands ###
+
+
+def downgrade():
+ ### commands auto generated by Alembic - please adjust! ###
+ op.drop_column('bill', 'creation_date')
+ ### end Alembic commands ###
diff --git a/ihatemoney/models.py b/ihatemoney/models.py
index c6ce23f..9e9fbeb 100644
--- a/ihatemoney/models.py
+++ b/ihatemoney/models.py
@@ -163,6 +163,7 @@ class Project(db.Model):
.filter(Bill.payer_id == Person.id)\
.filter(Person.project_id == Project.id)\
.filter(Project.id == self.id)\
+ .order_by(Bill.creation_date.desc())\
.order_by(Bill.date.desc())\
.order_by(Bill.id.desc())
@@ -329,7 +330,8 @@ class Bill(db.Model):
query_class = BillQuery
- _to_serialize = ("id", "payer_id", "owers", "amount", "date", "what")
+ _to_serialize = ("id", "payer_id", "owers", "amount", "date",
+ "creation_date", "what")
id = db.Column(db.Integer, primary_key=True)
@@ -338,6 +340,7 @@ class Bill(db.Model):
amount = db.Column(db.Float)
date = db.Column(db.Date, default=datetime.now)
+ creation_date = db.Column(db.Date, default=datetime.now)
what = db.Column(db.UnicodeText)
archive = db.Column(db.Integer, db.ForeignKey("archive.id"))
diff --git a/ihatemoney/templates/list_bills.html b/ihatemoney/templates/list_bills.html
index 81f8cd5..718009b 100644
--- a/ihatemoney/templates/list_bills.html
+++ b/ihatemoney/templates/list_bills.html
@@ -98,10 +98,11 @@
{% if bills.count() > 0 %}
<table id="bill_table" class="col table table-striped table-hover">
- <thead><tr><th>{{ _("When?") }}</th><th>{{ _("Who paid?") }}</th><th>{{ _("For what?") }}</th><th>{{ _("For whom?") }}</th><th>{{ _("How much?") }}</th><th>{{ _("Actions") }}</th></tr></thead>
+ <thead><tr><th>{{ _("Added on") }}</th><th>{{ _("When?") }}</th><th>{{ _("Who paid?") }}</th><th>{{ _("For what?") }}</th><th>{{ _("For whom?") }}</th><th>{{ _("How much?") }}</th><th>{{ _("Actions") }}</th></tr></thead>
<tbody>
{% for bill in bills %}
<tr owers="{{bill.owers|join(',','id')}}" payer="{{bill.payer.id}}">
+ <td>{{ bill.creation_date if bill.creation_date else bill.date }}</td>
<td>{{ bill.date }}</td>
<td>{{ bill.payer }}</td>
<td>{{ bill.what }}</td>
diff --git a/ihatemoney/tests/tests.py b/ihatemoney/tests/tests.py
index 63a7394..f368780 100644
--- a/ihatemoney/tests/tests.py
+++ b/ihatemoney/tests/tests.py
@@ -9,6 +9,7 @@ try:
except ImportError:
from mock import patch
+import datetime
import os
import json
from collections import defaultdict
@@ -1271,7 +1272,13 @@ class APITestCase(IhatemoneyTestCase):
"date": "2011-08-10",
"id": 1}
- self.assertDictEqual(expected, json.loads(req.data.decode('utf-8')))
+ got = json.loads(req.data.decode('utf-8'))
+ self.assertEqual(
+ datetime.date.today(),
+ datetime.datetime.strptime(got["creation_date"], '%Y-%m-%d').date()
+ )
+ del got["creation_date"]
+ self.assertDictEqual(expected, got)
# the list of bills should length 1
req = self.client.get("/api/projects/raclette/bills",
@@ -1303,6 +1310,10 @@ class APITestCase(IhatemoneyTestCase):
# check its fields
req = self.client.get("/api/projects/raclette/bills/1",
headers=self.get_auth("raclette"))
+ creation_date = datetime.datetime.strptime(
+ json.loads(req.data.decode('utf-8'))["creation_date"],
+ '%Y-%m-%d'
+ ).date()
expected = {
"what": "beer",
@@ -1314,7 +1325,13 @@ class APITestCase(IhatemoneyTestCase):
"date": "2011-09-10",
"id": 1}
- self.assertDictEqual(expected, json.loads(req.data.decode('utf-8')))
+ got = json.loads(req.data.decode('utf-8'))
+ self.assertEqual(
+ creation_date,
+ datetime.datetime.strptime(got["creation_date"], '%Y-%m-%d').date()
+ )
+ del got["creation_date"]
+ self.assertDictEqual(expected, got)
# delete a bill
req = self.client.delete("/api/projects/raclette/bills/1",
@@ -1393,6 +1410,10 @@ class APITestCase(IhatemoneyTestCase):
# get this bill details
req = self.client.get("/api/projects/raclette/bills/1",
headers=self.get_auth("raclette"))
+ creation_date = datetime.datetime.strptime(
+ json.loads(req.data.decode('utf-8'))["creation_date"],
+ '%Y-%m-%d'
+ ).date()
# compare with the added info
self.assertStatus(200, req)
@@ -1405,7 +1426,13 @@ class APITestCase(IhatemoneyTestCase):
"amount": 25.0,
"date": "2011-08-10",
"id": 1}
- self.assertDictEqual(expected, json.loads(req.data.decode('utf-8')))
+ got = json.loads(req.data.decode('utf-8'))
+ self.assertEqual(
+ creation_date,
+ datetime.datetime.strptime(got["creation_date"], '%Y-%m-%d').date()
+ )
+ del got["creation_date"]
+ self.assertDictEqual(expected, got)
# getting it should return a 404
req = self.client.get("/api/projects/raclette",