Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14092 - Use decimals for Invoices / Payment Line Items / Payment Accounts / Fees - Part 2 #1008

Merged
merged 5 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions jobs/payment-jobs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-e git+https://github.com/bcgov/sbc-common-components.git@02f90e3a1c9b6eeff424ecec758d58a43d2cfc9b#egg=sbc_common_components&subdirectory=python
-e git+https://github.com/bcgov/sbc-pay.git@f31a5a097468d59b558d9638e5a7d70f176a4803#egg=pay_api&subdirectory=pay-api
-e git+https://github.com/bcgov/sbc-pay.git@12a54e1c1cab60b0c0a59b3834f4d660b568f015#egg=pay_api&subdirectory=pay-api
Flask-Caching==2.0.1
Flask-Migrate==2.7.0
Flask-Moment==1.0.5
Expand Down Expand Up @@ -28,41 +28,41 @@ cffi==1.15.1
charset-normalizer==2.1.1
click==8.1.3
croniter==1.3.7
cryptography==38.0.1
cryptography==38.0.3
dataclass-wizard==0.22.2
dpath==2.0.6
ecdsa==0.18.0
expiringdict==1.2.2
flask-jwt-oidc==0.3.0
flask-marshmallow==0.11.0
flask-restx==0.5.1
flask-restx==1.0.3
gunicorn==20.1.0
idna==3.4
importlib-metadata==5.0.0
importlib-resources==5.10.0
itsdangerous==2.0.1
jaeger-client==4.8.0
jsonschema==4.16.0
jsonschema==4.17.0
launchdarkly-server-sdk==7.5.1
marshmallow-sqlalchemy==0.25.0
marshmallow==3.18.0
minio==7.1.12
opentracing==2.4.0
packaging==21.3
paramiko==2.11.0
paramiko==2.12.0
pkgutil_resolve_name==1.3.10
protobuf==3.19.6
psycopg2-binary==2.9.5
pyRFC3339==1.1
pyasn1==0.4.8
pycparser==2.21
pyparsing==3.0.9
pyrsistent==0.18.1
pyrsistent==0.19.2
pysftp==0.2.9
python-dateutil==2.8.2
python-dotenv==0.21.0
python-jose==3.3.0
pytz==2022.5
pytz==2022.6
requests==2.28.1
rsa==4.9
semver==2.13.0
Expand Down
2 changes: 1 addition & 1 deletion jobs/payment-jobs/requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ dataclass_wizard
launchdarkly-server-sdk

-e git+https://github.com/bcgov/sbc-common-components.git#egg=sbc-common-components&subdirectory=python
-e git+https://github.com/bcgov/sbc-pay.git@13309#egg=pay_api&subdirectory=pay-api
-e git+https://github.com/bcgov/sbc-pay.git@main#egg=pay_api&subdirectory=pay-api

2 changes: 1 addition & 1 deletion jobs/payment-jobs/tasks/cfs_create_invoice_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def _create_pad_invoices(cls): # pylint: disable=too-many-locals
continue

additional_params = {
'invoice_total': invoice_total,
'invoice_total': float(invoice_total),
'invoice_process_date': f'{datetime.now()}'
}
mailer.publish_mailer_events('pad.invoiceCreated', payment_account, additional_params)
Expand Down
2 changes: 1 addition & 1 deletion jobs/payment-jobs/tasks/routing_slip_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def process_nsf(cls):

inv = cls._create_nsf_invoice(cfs_account, routing_slip.number, payment_account)
# Reduce the NSF fee from remaining amount.
routing_slip.remaining_amount = float(routing_slip.remaining_amount) - inv.total
routing_slip.remaining_amount = routing_slip.remaining_amount - inv.total
routing_slip.save()

except Exception as e: # NOQA # pylint: disable=broad-except
Expand Down
2 changes: 1 addition & 1 deletion jobs/payment-jobs/utils/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def publish_mailer_events(message_type: str, pay_account: PaymentAccountModel,
'datacontenttype': 'application/json',
'data': {
'accountId': pay_account.auth_account_id,
'nsfFee': fee_schedule.fee.amount,
'nsfFee': float(fee_schedule.fee.amount),
**additional_params
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""empty message

Revision ID: 1e62e1c27b08
Revises: 160d44b02e09
Create Date: 2022-11-07 15:19:29.515671

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '1e62e1c27b08'
down_revision = '160d44b02e09'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('fee_codes', 'amount',
existing_type=postgresql.DOUBLE_PRECISION(precision=53),
type_=sa.Numeric(precision=19, scale=2),
existing_nullable=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('fee_codes', 'amount',
existing_type=sa.Numeric(precision=19, scale=2),
type_=postgresql.DOUBLE_PRECISION(precision=53),
existing_nullable=False)
# ### end Alembic commands ###
5 changes: 4 additions & 1 deletion pay-api/src/pay_api/models/fee_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
"""Model to handle all operations related to Fee Code master data."""

from marshmallow import fields

from .code_table import CodeTable
from .db import db, ma

Expand All @@ -26,7 +28,7 @@ class FeeCode(db.Model, CodeTable):
__tablename__ = 'fee_codes'

code = db.Column(db.String(10), primary_key=True)
amount = db.Column('amount', db.Float, nullable=False)
amount = db.Column('amount', db.Numeric(19, 2), nullable=False)

def save(self):
"""Save fee code."""
Expand All @@ -45,3 +47,4 @@ class Meta: # pylint: disable=too-few-public-methods
"""Returns all the fields from the SQLAlchemy class."""

model = FeeCode
amount = fields.Float(data_key='amount')
37 changes: 18 additions & 19 deletions pay-api/src/pay_api/services/fee_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Service to manage Fee Calculation."""

from datetime import date
from decimal import Decimal

from flask import current_app
from sbc_common_components.tracing.service_tracing import ServiceTracing
Expand All @@ -26,7 +27,6 @@
from pay_api.utils.enums import Role
from pay_api.utils.errors import Error
from pay_api.utils.user_context import UserContext, user_context
from pay_api.utils.util import get_quantized


@ServiceTracing.trace(ServiceTracing.enable_tracing, ServiceTracing.should_be_tracing)
Expand All @@ -42,13 +42,13 @@ def __init__(self):
self._fee_code: str = None
self._fee_start_date: date = None
self._fee_end_date: date = None
self._fee_amount: float = None
self._fee_amount = Decimal('0')
self._filing_type: str = None
self._priority_fee: float = 0
self._future_effective_fee: float = 0
self._waived_fee_amount: float = 0
self._priority_fee = Decimal('0')
self._future_effective_fee = Decimal('0')
self._waived_fee_amount = Decimal('0')
self._quantity: int = 1
self._service_fees: float = 0
self._service_fees = Decimal('0')
self._service_fee_code: str = None
self._variable: bool = False

Expand All @@ -67,7 +67,7 @@ def _dao(self, value):
self.fee_code: str = self._dao.fee_code
self.fee_start_date: date = self._dao.fee_start_date
self.fee_end_date: date = self._dao.fee_end_date
self._fee_amount: float = self._dao.fee.amount
self._fee_amount: Decimal = self._dao.fee.amount
self._filing_type: str = self._dao.filing_type.description
self._service_fee_code: str = self._dao.service_fee_code
self._variable: bool = self._dao.variable
Expand Down Expand Up @@ -184,7 +184,7 @@ def priority_fee(self):
return self._priority_fee

@priority_fee.setter
def priority_fee(self, value: float):
def priority_fee(self, value: Decimal):
"""Set the priority fee."""
self._priority_fee = value

Expand All @@ -194,7 +194,7 @@ def future_effective_fee(self):
return self._future_effective_fee

@future_effective_fee.setter
def future_effective_fee(self, value: float):
def future_effective_fee(self, value: Decimal):
"""Set the future_effective_fee."""
self._future_effective_fee = value

Expand All @@ -204,7 +204,7 @@ def service_fees(self):
return self._service_fees

@service_fees.setter
def service_fees(self, value: float):
def service_fees(self, value: Decimal):
"""Set the service_fees."""
self._service_fees = value

Expand All @@ -228,8 +228,7 @@ def quantity(self, value: int):
"""Set the quantity."""
self._quantity = value
if self._quantity and self._quantity > 1:
# Need a float here, otherwise serialization wont work.
self._fee_amount = float(get_quantized(self._fee_amount * self._quantity))
self._fee_amount = self._fee_amount * self._quantity

@description.setter
def description(self, value: str):
Expand Down Expand Up @@ -258,15 +257,15 @@ def asdict(self):
d = {
'filing_type': self._filing_type,
'filing_type_code': self.filing_type_code,
'filing_fees': self.fee_amount,
'priority_fees': self.priority_fee,
'future_effective_fees': self.future_effective_fee,
'filing_fees': float(self.fee_amount),
'priority_fees': float(self.priority_fee),
'future_effective_fees': float(self.future_effective_fee),
'tax': {
'gst': self.gst,
'pst': self.pst
'gst': float(self.gst),
'pst': float(self.pst)
},
'total': self.total,
'service_fees': self._service_fees,
'total': float(self.total),
'service_fees': float(self._service_fees),
'processing_fees': 0
}
return d
Expand Down
6 changes: 3 additions & 3 deletions pay-api/src/pay_api/services/payment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def create_invoice(cls, payment_request: Tuple[Dict[str, Any]], authorization: T
invoice.payment_account_id = payment_account.id
invoice.cfs_account_id = payment_account.cfs_account_id
invoice.invoice_status_code = pay_service.get_default_invoice_status()
invoice.service_fees = sum(Decimal(str(fee.service_fees)) for fee in fees) if fees else 0
invoice.total = sum(Decimal(str(fee.total)) for fee in fees) if fees else 0
invoice.service_fees = sum(fee.service_fees for fee in fees) if fees else 0
invoice.total = sum(fee.total for fee in fees) if fees else 0
invoice.paid = 0
invoice.refund = 0
invoice.routing_slip = get_str_by_path(account_info, 'routingSlip')
Expand Down Expand Up @@ -303,7 +303,7 @@ def _calculate_fees(corp_type, filing_info):
service_fee_applied = True

if fee.variable:
fee.fee_amount = float(filing_type_info.get('fee', 0))
fee.fee_amount = Decimal(str(filing_type_info.get('fee', 0)))

if filing_type_info.get('filingDescription'):
fee.description = filing_type_info.get('filingDescription')
Expand Down