mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
Add bill.creation_date field (#327)
This commit is contained in:
parent
0f2a5e9255
commit
0428cf06b5
5 changed files with 63 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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 ###
|
|
@ -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"))
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue