mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-12 18:08:05 -04:00
Merge pull request #1000 from alphagov/letters-billing-table
Added table and model for letter rates.
This commit is contained in:
@@ -671,7 +671,6 @@ NOTIFICATION_STATUS_TYPES_BILLABLE = [
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
]
|
||||
|
||||
|
||||
NOTIFICATION_STATUS_TYPES = [
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_SENDING,
|
||||
@@ -1175,3 +1174,20 @@ class InboundSms(db.Model):
|
||||
@content.setter
|
||||
def content(self, content):
|
||||
self._content = encryption.encrypt(content)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
50
migrations/versions/0091_letter_billing.py
Normal file
50
migrations/versions/0091_letter_billing.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0091_letter_billing
|
||||
Revises: 0090_inbound_sms
|
||||
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 = '0091_letter_billing'
|
||||
down_revision = '0090_inbound_sms'
|
||||
|
||||
|
||||
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')
|
||||
Reference in New Issue
Block a user