mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-16 23:10:22 -04:00
Merge pull request #2112 from alphagov/add-postage-to-pk
Add postage to ft_billing primary key
This commit is contained in:
@@ -237,7 +237,7 @@ def update_fact_billing(data, process_day):
|
||||
process_day,
|
||||
data.crown,
|
||||
data.letter_page_count,
|
||||
"second")
|
||||
data.postage)
|
||||
billing_record = create_billing_record(data, rate, process_day)
|
||||
table = FactBilling.__table__
|
||||
'''
|
||||
|
||||
@@ -1811,7 +1811,7 @@ class FactBilling(db.Model):
|
||||
rate_multiplier = db.Column(db.Integer(), nullable=False, primary_key=True)
|
||||
international = db.Column(db.Boolean, nullable=False, primary_key=True)
|
||||
rate = db.Column(db.Numeric(), nullable=False, primary_key=True)
|
||||
postage = db.Column(db.String)
|
||||
postage = db.Column(db.String, nullable=False, primary_key=True)
|
||||
billable_units = db.Column(db.Integer(), nullable=True)
|
||||
notifications_sent = db.Column(db.Integer(), nullable=True)
|
||||
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
|
||||
|
||||
39
migrations/versions/0235_add_postage_to_pk.py
Normal file
39
migrations/versions/0235_add_postage_to_pk.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0235_add_postage_to_pk
|
||||
Revises: 0234_ft_billing_postage
|
||||
Create Date: 2018-09-28 15:39:21.115358
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = '0235_add_postage_to_pk'
|
||||
down_revision = '0234_ft_billing_postage'
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
'template_id',
|
||||
'service_id',
|
||||
'notification_type',
|
||||
'provider',
|
||||
'rate_multiplier',
|
||||
'international',
|
||||
'rate',
|
||||
'postage'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
op.alter_column('ft_billing', 'postage', nullable=True)
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
'template_id',
|
||||
'service_id',
|
||||
'notification_type',
|
||||
'provider',
|
||||
'rate_multiplier',
|
||||
'international',
|
||||
'rate'])
|
||||
@@ -177,6 +177,52 @@ def test_create_nightly_billing_different_sent_by(
|
||||
assert record.rate_multiplier == 1.0
|
||||
|
||||
|
||||
def test_create_nightly_billing_different_letter_postage(
|
||||
notify_db_session,
|
||||
sample_letter_template,
|
||||
mocker):
|
||||
yesterday = datetime.now() - timedelta(days=1)
|
||||
mocker.patch('app.dao.fact_billing_dao.get_rate', side_effect=mocker_get_rate)
|
||||
|
||||
for i in range(2):
|
||||
create_notification(
|
||||
created_at=yesterday,
|
||||
template=sample_letter_template,
|
||||
status='delivered',
|
||||
sent_by='dvla',
|
||||
billable_units=2,
|
||||
postage='first'
|
||||
)
|
||||
create_notification(
|
||||
created_at=yesterday,
|
||||
template=sample_letter_template,
|
||||
status='delivered',
|
||||
sent_by='dvla',
|
||||
billable_units=2,
|
||||
postage='second'
|
||||
)
|
||||
|
||||
records = FactBilling.query.all()
|
||||
assert len(records) == 0
|
||||
# Celery expects the arguments to be a string or primitive type.
|
||||
yesterday_str = datetime.strftime(yesterday, "%Y-%m-%d")
|
||||
create_nightly_billing(yesterday_str)
|
||||
|
||||
records = FactBilling.query.order_by('postage').all()
|
||||
assert len(records) == 2
|
||||
assert records[0].notification_type == LETTER_TYPE
|
||||
assert records[0].bst_date == datetime.date(yesterday)
|
||||
assert records[0].postage == 'first'
|
||||
assert records[0].notifications_sent == 2
|
||||
assert records[0].billable_units == 4
|
||||
|
||||
assert records[1].notification_type == LETTER_TYPE
|
||||
assert records[1].bst_date == datetime.date(yesterday)
|
||||
assert records[1].postage == 'second'
|
||||
assert records[1].notifications_sent == 1
|
||||
assert records[1].billable_units == 2
|
||||
|
||||
|
||||
def test_create_nightly_billing_letter(
|
||||
sample_service,
|
||||
sample_letter_template,
|
||||
|
||||
Reference in New Issue
Block a user