Skip to content

Commit

Permalink
Merge pull request #776 from sumesh-aot/rpt
Browse files Browse the repository at this point in the history
Adding PPR filing types, and fixing lint errors
  • Loading branch information
sumesh-aot authored Sep 21, 2021
2 parents f865021 + ecba9fb commit eb10dec
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 56 deletions.
70 changes: 70 additions & 0 deletions pay-api/migrations/versions/44bd57ece7b0_ppr_filing_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""ppr_filing_types
Revision ID: 44bd57ece7b0
Revises: 609b98d87a72
Create Date: 2021-09-16 16:25:58.618648
"""
from alembic import op
import sqlalchemy as sa
from datetime import date

import sqlalchemy as sa
from alembic import op
from sqlalchemy import Date, Float, String, Boolean
from sqlalchemy.sql import column, table

# revision identifiers, used by Alembic.
revision = '44bd57ece7b0'
down_revision = '609b98d87a72'
branch_labels = None
depends_on = None


def upgrade():
op.create_index(op.f('ix_invoices_created_on'), 'invoices', ['created_on'], unique=False)
op.alter_column('payment_line_items', 'fee_distribution_id',
existing_type=sa.INTEGER(),
nullable=True)

filing_type_table = table('filing_types',
column('code', String),
column('description', String)
)
fee_schedule_table = table('fee_schedules',
column('filing_type_code', String),
column('corp_type_code', String),
column('fee_code', String),
column('fee_start_date', Date),
column('fee_end_date', Date)
)

op.bulk_insert(
filing_type_table,
[
{'code': 'FSDIS', 'description': 'PPR Total Discharge'},
{'code': 'NCREG', 'description': 'PPR No Charge Registration'},
{'code': 'NCCHG', 'description': 'PPR No Charge Change or Amendment'}
]
)

op.bulk_insert(
fee_schedule_table,
[
{'filing_type_code': 'FSDIS', 'corp_type_code': 'PPR', 'fee_code': 'EN107', 'fee_start_date': date.today(),
'fee_end_date': None},
{'filing_type_code': 'NCREG', 'corp_type_code': 'PPR', 'fee_code': 'EN107', 'fee_start_date': date.today(),
'fee_end_date': None},
{'filing_type_code': 'NCCHG', 'corp_type_code': 'PPR', 'fee_code': 'EN107', 'fee_start_date': date.today(),
'fee_end_date': None}
]
)


def downgrade():
op.execute("DELETE FROM fee_schedules WHERE filing_type_code in ('NCCHG', 'NCREG', 'FSDIS')")
op.execute("DELETE FROM filing_types WHERE code in ('NCCHG', 'NCREG', 'FSDIS')")
op.alter_column('payment_line_items', 'fee_distribution_id',
existing_type=sa.INTEGER(),
nullable=False)
op.drop_index(op.f('ix_invoices_created_on'), table_name='invoices')
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):

# Configure Sentry
if app.config.get('SENTRY_DSN', None): # pragma: no cover
sentry_sdk.init(
sentry_sdk.init( # pylint: disable=abstract-class-instantiated
dsn=app.config.get('SENTRY_DSN'),
integrations=[FlaskIntegration()]
)
Expand Down
12 changes: 3 additions & 9 deletions pay-api/src/pay_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class _Config(): # pylint: disable=too-few-public-methods
DB_NAME = _get_config('DATABASE_NAME')
DB_HOST = _get_config('DATABASE_HOST')
DB_PORT = _get_config('DATABASE_PORT', default='5432')
SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{password}@{host}:{port}/{name}'.format(
user=DB_USER, password=DB_PASSWORD, host=DB_HOST, port=int(DB_PORT), name=DB_NAME
)
SQLALCHEMY_DATABASE_URI = f'postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{int(DB_PORT)}/{DB_NAME}'
SQLALCHEMY_ECHO = _get_config('SQLALCHEMY_ECHO', default='False').lower() == 'true'

# JWT_OIDC Settings
Expand Down Expand Up @@ -204,9 +202,7 @@ class TestConfig(_Config): # pylint: disable=too-few-public-methods
DB_PORT = _get_config('DATABASE_TEST_PORT', default='5432')
SQLALCHEMY_DATABASE_URI = _get_config(
'DATABASE_TEST_URL',
default='postgresql://{user}:{password}@{host}:{port}/{name}'.format(
user=DB_USER, password=DB_PASSWORD, host=DB_HOST, port=int(DB_PORT), name=DB_NAME
),
default=f'postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{int(DB_PORT)}/{DB_NAME}'
)

JWT_OIDC_TEST_MODE = True
Expand Down Expand Up @@ -330,7 +326,5 @@ class MigrationConfig(): # pylint: disable=too-few-public-methods
DB_NAME = _get_config('DATABASE_NAME')
DB_HOST = _get_config('DATABASE_HOST')
DB_PORT = _get_config('DATABASE_PORT', default='5432')
SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{password}@{host}:{port}/{name}'.format(
user=DB_USER, password=DB_PASSWORD, host=DB_HOST, port=int(DB_PORT), name=DB_NAME
)
SQLALCHEMY_DATABASE_URI = f'postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{int(DB_PORT)}/{DB_NAME}'
SQLALCHEMY_TRACK_MODIFICATIONS = False
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/factory/payment_system_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def create(**kwargs):
has_bcol_account_number = account_info is not None and account_info.get('bcolAccountNumber') is not None

_instance: PaymentSystemService = None
current_app.logger.debug('payment_method: {}'.format(payment_method))
current_app.logger.debug(f'payment_method: {payment_method}')

if not payment_method:
raise BusinessException(Error.INVALID_CORP_OR_FILING_TYPE)
Expand Down
1 change: 1 addition & 0 deletions pay-api/src/pay_api/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Invoice(Audit): # pylint: disable=too-many-instance-attributes
payment_method_code = db.Column(db.String(15), ForeignKey('payment_methods.code'), nullable=False)
corp_type_code = db.Column(db.String(10), ForeignKey('corp_types.code'), nullable=True)
disbursement_status_code = db.Column(db.String(20), ForeignKey('disbursement_status_codes.code'), nullable=True)
created_on = db.Column('created_on', db.DateTime, nullable=False, default=datetime.now, index=True)

business_identifier = db.Column(db.String(20), nullable=True)
total = db.Column(db.Float, nullable=False)
Expand Down
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/models/payment_line_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PaymentLineItem(BaseModel): # pylint: disable=too-many-instance-attribute
waived_by = db.Column(db.String(50), nullable=True, default=None)
service_fees = db.Column(db.Float, nullable=True)

fee_distribution_id = db.Column(db.Integer, ForeignKey('distribution_codes.distribution_code_id'), nullable=False)
fee_distribution_id = db.Column(db.Integer, ForeignKey('distribution_codes.distribution_code_id'), nullable=True)

fee_schedule = relationship(FeeSchedule, foreign_keys=[fee_schedule_id], lazy='joined', innerjoin=True)

Expand Down
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/resources/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def post(account_number: str):
if not valid_format:
return error_to_response(Error.INVALID_REQUEST, invalid_params=schema_utils.serialize(errors))

report_name = 'bcregistry-transactions-{}'.format(datetime.now().strftime('%m-%d-%Y'))
report_name = f"bcregistry-transactions-{datetime.now().strftime('%m-%d-%Y')}"

if response_content_type == ContentType.PDF.value:
report_name = f'{report_name}.pdf'
Expand Down
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/resources/fas/routing_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def post(date: str):
pdf, file_name = RoutingSlipService.create_daily_reports(date)

response = Response(pdf, 201)
response.headers.set('Content-Disposition', 'attachment', filename='{}.pdf'.format(file_name))
response.headers.set('Content-Disposition', 'attachment', filename=f'{file_name}.pdf')
response.headers.set('Content-Type', 'application/pdf')
response.headers.set('Access-Control-Expose-Headers', 'Content-Disposition')

Expand Down
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/resources/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def post(invoice_id: int = None):
try:
pdf, file_name = InvoiceService.create_invoice_pdf(invoice_id)
response = Response(pdf, 201)
response.headers.set('Content-Disposition', 'attachment', filename='{}.pdf'.format(file_name))
response.headers.set('Content-Disposition', 'attachment', filename=f'{file_name}.pdf')
response.headers.set('Content-Type', 'application/pdf')
response.headers.set('Access-Control-Expose-Headers', 'Content-Disposition')
return response
Expand Down
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/resources/invoice_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def post(invoice_id):
response = Response(pdf, 201)
file_name = request_json.get('fileName')
file_name = 'Coops-Filing' if not file_name else file_name
response.headers.set('Content-Disposition', 'attachment', filename='{}.pdf'.format(file_name))
response.headers.set('Content-Disposition', 'attachment', filename=f'{file_name}.pdf')
response.headers.set('Content-Type', 'application/pdf')
response.headers.set('Access-Control-Expose-Headers', 'Content-Disposition')
return response
Expand Down
3 changes: 1 addition & 2 deletions pay-api/src/pay_api/services/base_payment_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,4 @@ def _release_payment(invoice: Invoice):
except Exception as e: # NOQA pylint: disable=broad-except
current_app.logger.error(e)
current_app.logger.error('Notification to Queue failed for the Payment Event %s', payload)
capture_message('Notification to Queue failed for the Payment Event : {msg}.'.format(msg=payload),
level='error')
capture_message(f'Notification to Queue failed for the Payment Event : {payload}.', level='error')
13 changes: 7 additions & 6 deletions pay-api/src/pay_api/services/cfs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ def _transform_error_message(param: str) -> str:
def _create_paybc_account(access_token, party):
"""Create account record in PayBC."""
current_app.logger.debug('<Creating account')
account_url = current_app.config.get('CFS_BASE_URL') + '/cfs/parties/{}/accs/'.format(
party.get('party_number', None))
account_url = current_app.config.get('CFS_BASE_URL') + f"/cfs/parties/{party.get('party_number', None)}/accs/"
account: Dict[str, Any] = {
'account_description': current_app.config.get('CFS_ACCOUNT_DESCRIPTION'),
'customer_profile_class': CFS_CUSTOMER_PROFILE_CLASS
Expand All @@ -174,8 +173,9 @@ def _create_site(access_token, account, contact_info, receipt_method):
current_app.logger.debug('<Creating site ')
if not contact_info:
contact_info = {}
site_url = current_app.config.get('CFS_BASE_URL') + '/cfs/parties/{}/accs/{}/sites/' \
.format(account.get('party_number', None), account.get('account_number', None))
site_url = current_app.config.get(
'CFS_BASE_URL') + f"/cfs/parties/{account.get('party_number', None)}" \
f"/accs/{account.get('account_number', None)}/sites/"
site: Dict[str, Any] = {
'site_name': 'Site 1', # Make it dynamic if we ever need multiple sites per account
'city': get_non_null_value(contact_info.get('city'), DEFAULT_CITY),
Expand Down Expand Up @@ -269,8 +269,9 @@ def create_account_invoice(cls, transaction_number: str, line_items: List[Paymen
now = current_local_time()
curr_time = now.strftime('%Y-%m-%dT%H:%M:%SZ')

invoice_url = current_app.config.get('CFS_BASE_URL') + '/cfs/parties/{}/accs/{}/sites/{}/invs/' \
.format(cfs_account.cfs_party, cfs_account.cfs_account, cfs_account.cfs_site)
invoice_url = current_app.config.get(
'CFS_BASE_URL') + f'/cfs/parties/{cfs_account.cfs_party}' \
f'/accs/{cfs_account.cfs_account}/sites/{cfs_account.cfs_site}/invs/'

invoice_payload = dict(
batch_source=CFS_BATCH_SOURCE,
Expand Down
4 changes: 2 additions & 2 deletions pay-api/src/pay_api/services/distribution_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def find_all():
@staticmethod
def find_by_id(identifier: int):
"""Find distribution code by id."""
current_app.logger.debug('<find_by_id, {}'.format(identifier))
current_app.logger.debug(f'<find_by_id, {identifier}')
distribution_code = DistributionCodeModel.find_by_id(identifier=identifier)
distribution_code_schema = DistributionCodeSchema()
current_app.logger.debug('>find_by_id')
Expand All @@ -321,7 +321,7 @@ def find_by_id(identifier: int):
@staticmethod
def find_active_by_account_id(account_id: int) -> DistributionCode:
"""Find active distribution code by account_id."""
current_app.logger.debug('<find_active_by_account_id, {}'.format(account_id))
current_app.logger.debug(f'<find_active_by_account_id, {account_id}')
distribution_code = DistributionCodeModel.find_by_active_for_account(account_id)
dist_code_svc = DistributionCode()
dist_code_svc._dao = distribution_code # pylint: disable=protected-access
Expand Down
19 changes: 9 additions & 10 deletions pay-api/src/pay_api/services/oauth_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def post(endpoint, token, auth_header_type: AuthHeaderType, # pylint: disable=t
if content_type == ContentType.JSON:
data = json.dumps(data)

current_app.logger.debug('Endpoint : {}'.format(endpoint))
current_app.logger.debug('headers : {}'.format(headers))
current_app.logger.debug('data : {}'.format(data))
current_app.logger.debug(f'Endpoint : {endpoint}')
current_app.logger.debug(f'headers : {headers}')
current_app.logger.debug(f'data : {data}')
response = None
try:
if is_put:
Expand All @@ -72,7 +72,7 @@ def post(endpoint, token, auth_header_type: AuthHeaderType, # pylint: disable=t
raise ServiceUnavailableException(exc) from exc
except HTTPError as exc:
current_app.logger.error(
'HTTPError on POST with status code {}'.format(response.status_code if response else ''))
f"HTTPError on POST with status code {response.status_code if response else ''}")
if response and response.status_code >= 500:
raise ServiceUnavailableException(exc) from exc
raise exc
Expand All @@ -85,11 +85,11 @@ def post(endpoint, token, auth_header_type: AuthHeaderType, # pylint: disable=t
@staticmethod
def __log_response(response):
if response is not None:
current_app.logger.info('Response Headers {}'.format(response.headers))
current_app.logger.info(f'Response Headers {response.headers}')
if response.headers and isinstance(response.headers, Iterable) and \
'Content-Type' in response.headers and \
response.headers['Content-Type'] == ContentType.JSON.value:
current_app.logger.info('response : {}'.format(response.text if response else ''))
current_app.logger.info(f"response : {response.text if response else ''} ")

@staticmethod
def get(endpoint, token, auth_header_type: AuthHeaderType, # pylint:disable=too-many-arguments
Expand All @@ -106,8 +106,8 @@ def get(endpoint, token, auth_header_type: AuthHeaderType, # pylint:disable=too
if additional_headers is not None:
headers.update(additional_headers)

current_app.logger.debug('Endpoint : {}'.format(endpoint))
current_app.logger.debug('headers : {}'.format(headers))
current_app.logger.debug(f'Endpoint : {endpoint}')
current_app.logger.debug(f'headers : {headers}')
session = requests.Session()
if retry_on_failure:
session.mount(endpoint, RETRY_ADAPTER)
Expand All @@ -120,8 +120,7 @@ def get(endpoint, token, auth_header_type: AuthHeaderType, # pylint:disable=too
current_app.logger.error(exc)
raise ServiceUnavailableException(exc) from exc
except HTTPError as exc:
current_app.logger.error(
'HTTPError on POST with status code {}'.format(response.status_code if response else ''))
current_app.logger.error(f"HTTPError on POST with status code {response.status_code if response else ''}")
if response is not None:
if response.status_code >= 500:
raise ServiceUnavailableException(exc) from exc
Expand Down
15 changes: 9 additions & 6 deletions pay-api/src/pay_api/services/paybc_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ def get_receipt(self, payment_account: PaymentAccount, pay_response_url: str, in
current_app.logger.debug('<paybc_service_Getting token')
access_token: str = CFSService.get_token().json().get('access_token')
current_app.logger.debug('<Getting receipt')
receipt_url = current_app.config.get('CFS_BASE_URL') + '/cfs/parties/{}/accs/{}/sites/{}/rcpts/'.format(
payment_account.cfs_party, payment_account.cfs_account, payment_account.cfs_site)
receipt_url = current_app.config.get(
'CFS_BASE_URL') + f'/cfs/parties/{payment_account.cfs_party}/accs/' \
f'{payment_account.cfs_account}/sites/{payment_account.cfs_site}/rcpts/'
parsed_url = parse_url_params(pay_response_url)
receipt_number: str = parsed_url.get('receipt_number') if 'receipt_number' in parsed_url else None
if not receipt_number: # Find all receipts for the site and then match with invoice number
Expand Down Expand Up @@ -148,8 +149,9 @@ def _add_adjustment(self, payment_account: PaymentAccount, # pylint: disable=to
inv_number: str, comment: str, amount: float, line: int = 0, access_token: str = None):
"""Add adjustment to the invoice."""
current_app.logger.debug(f'>Creating PayBC Adjustment For Invoice: {inv_number}')
adjustment_url = current_app.config.get('CFS_BASE_URL') + '/cfs/parties/{}/accs/{}/sites/{}/invs/{}/adjs/' \
.format(payment_account.cfs_party, payment_account.cfs_account, payment_account.cfs_site, inv_number)
adjustment_url = current_app.config.get(
'CFS_BASE_URL') + f'/cfs/parties/{payment_account.cfs_party}/accs/{payment_account.cfs_account}' \
f'/sites/{payment_account.cfs_site}/invs/{inv_number}/adjs/'
current_app.logger.debug(f'>Creating PayBC Adjustment URL {adjustment_url}')

adjustment = dict(
Expand All @@ -172,8 +174,9 @@ def _add_adjustment(self, payment_account: PaymentAccount, # pylint: disable=to
def _get_invoice(self, payment_account: PaymentAccount, inv_number: str, access_token: str):
"""Get invoice from PayBC."""
current_app.logger.debug('<__get_invoice')
invoice_url = current_app.config.get('CFS_BASE_URL') + '/cfs/parties/{}/accs/{}/sites/{}/invs/{}/' \
.format(payment_account.cfs_party, payment_account.cfs_account, payment_account.cfs_site, inv_number)
invoice_url = current_app.config.get(
'CFS_BASE_URL') + f'/cfs/parties/{payment_account.cfs_party}/accs/{payment_account.cfs_account}/' \
f'sites/{payment_account.cfs_site}/invs/{inv_number}/'

invoice_response = self.get(invoice_url, access_token, AuthHeaderType.BEARER, ContentType.JSON)
current_app.logger.debug('>__get_invoice')
Expand Down
5 changes: 2 additions & 3 deletions pay-api/src/pay_api/services/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,8 @@ def _prepare_csv_data(results):
total_fees = float(invoice.get('total', 0))
row_value = [
','.join([line_item.get('description') for line_item in invoice.get('line_items')]),
','.join(['{} {}'.format(
detail.get('label'), detail.get('value')) for detail in invoice.get('details')
]) if invoice.get('details') else None,
','.join([f"{detail.get('label')} {detail.get('value')}" for detail in invoice.get('details')])
if invoice.get('details') else None,
invoice.get('folio_number'),
invoice.get('created_name'),
get_local_formatted_date_time(
Expand Down
Loading

0 comments on commit eb10dec

Please sign in to comment.