Added table and model for letter rates.

The rates for the letters are per page, therefore it seemed better to build a different table.
This commit is contained in:
Rebecca Law
2017-05-31 13:34:54 +01:00
parent 1c90c8be16
commit 0b642623fb
2 changed files with 67 additions and 0 deletions

View File

@@ -1141,3 +1141,20 @@ class JobStatistics(db.Model):
)
the_string += "created at {}".format(self.created_at)
return the_string
class LetterRate(db.Model):
__tablename__ = 'letter_rates'
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
valid_from = valid_from = db.Column(db.DateTime, nullable=False)
class LetterRateDetail(db.Model):
__tablename__ = 'letter_rate_details'
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
letter_rate_id = db.Column(UUID(as_uuid=True), db.ForeignKey('letter_rates.id'), index=True, nullable=False)
letter_rate = db.relationship('LetterRate', backref='letter_rates')
page_total = db.Column(db.Integer, nullable=False)
rate = db.Column(db.Numeric(), nullable=False)

View File

@@ -0,0 +1,50 @@
"""empty message
Revision ID: 0088_letter_billing
Revises: 0087_scheduled_notifications
Create Date: 2017-05-31 11:43:55.744631
"""
import uuid
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0088_letter_billing'
down_revision = '0087_scheduled_notifications'
def upgrade():
op.create_table('letter_rates',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('valid_from', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('letter_rate_details',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('letter_rate_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('page_total', sa.Integer(), nullable=False),
sa.Column('rate', sa.Numeric(), nullable=False),
sa.ForeignKeyConstraint(['letter_rate_id'], ['letter_rates.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_letter_rate_details_letter_rate_id'), 'letter_rate_details', ['letter_rate_id'],
unique=False)
op.get_bind()
letter_id = uuid.uuid4()
op.execute("insert into letter_rates(id, valid_from) values('{}', '2017-03-31 23:00:00')".format(letter_id))
insert_details = "insert into letter_rate_details(id, letter_rate_id, page_total, rate) values('{}', '{}', {}, {})"
op.execute(
insert_details.format(uuid.uuid4(), letter_id, 1, 29.3))
op.execute(
insert_details.format(uuid.uuid4(), letter_id, 2, 32))
op.execute(
insert_details.format(uuid.uuid4(), letter_id, 3, 35))
def downgrade():
op.get_bind()
op.drop_index('ix_letter_rate_details_letter_rate_id')
op.drop_table('letter_rate_details')
op.drop_table('letter_rates')