Skip to content

Commit

Permalink
Simplify query, add in try catch (#1838)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Nov 25, 2024
1 parent 678421b commit 77b0c77
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 41 deletions.
34 changes: 17 additions & 17 deletions jobs/payment-jobs/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jobs/payment-jobs/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
pay-api = {git = "https://github.com/ochiu/sbc-pay.git", branch = "24454-EFT-TDI17-Processing-Updates", subdirectory = "pay-api"}
pay-api = {git = "https://github.com/bcgov/sbc-pay.git", branch = "main", subdirectory = "pay-api"}
flask = "^3.0.2"
flask-sqlalchemy = "^3.1.1"
sqlalchemy = "^2.0.28"
Expand Down
47 changes: 27 additions & 20 deletions jobs/payment-jobs/tasks/ap_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
"""Task to create AP file for FAS refunds and Disbursement via EFT for non-government orgs without a GL."""

import time
import traceback
from datetime import date, datetime, timedelta, timezone
from typing import List

from flask import current_app
from more_itertools import batched
from pay_api.models import CorpType as CorpTypeModel
from pay_api.models import DistributionCode as DistributionCodeModel
from pay_api.models import EFTCredit as EFTCreditModel
from pay_api.models import EFTCreditInvoiceLink as EFTCreditInvoiceLinkModel
from pay_api.models import EFTRefund as EFTRefundModel
from pay_api.models import EFTShortnameLinks as EFTShortnameLinksModel
from pay_api.models import EjvFile as EjvFileModel
from pay_api.models import EjvHeader as EjvHeaderModel
from pay_api.models import EjvLink as EjvLinkModel
Expand All @@ -42,6 +40,7 @@
PaymentMethod,
RoutingSlipStatus,
)
from sentry_sdk import capture_message
from sqlalchemy import Date, cast

from tasks.common.cgi_ap import CgiAP
Expand Down Expand Up @@ -78,29 +77,37 @@ def create_ap_files(cls):
10. After some time, a feedback file will arrive and Payment-reconciliation queue will move these
EFT refunds to REFUNDED. (filter out)
"""
cls._create_routing_slip_refund_file()
cls._create_non_gov_disbursement_file()
cls._create_eft_refund_file()
try:
cls._create_routing_slip_refund_file()
except Exception as e:
capture_message(
f"Error creating routing slip refund file ERROR : {str(e)}",
level="error",
)
current_app.logger.error(f"{{error: {str(e)}, stack_trace: {traceback.format_exc()}}}")
try:
cls._create_non_gov_disbursement_file()
except Exception as e:
capture_message(
f"Error creating non gov disbursement file ERROR : {str(e)}",
level="error",
)
current_app.logger.error(f"{{error: {str(e)}, stack_trace: {traceback.format_exc()}}}")
try:
cls._create_eft_refund_file()
except Exception as e:
capture_message(
f"Error creating eft refund file ERROR : {str(e)}",
level="error",
)
current_app.logger.error(f"{{error: {str(e)}, stack_trace: {traceback.format_exc()}}}")

@classmethod
def _create_eft_refund_file(cls):
"""Create AP file for EFT refunds and upload to CGI."""
cls.ap_type = EjvFileType.EFT_REFUND
eft_refunds_dao: List[EFTRefundModel] = (
eft_refunds_dao = (
db.session.query(EFTRefundModel)
.join(
EFTShortnameLinksModel,
EFTRefundModel.short_name_id == EFTShortnameLinksModel.eft_short_name_id,
)
.join(
EFTCreditModel,
EFTCreditModel.short_name_id == EFTShortnameLinksModel.eft_short_name_id,
)
.join(
EFTCreditInvoiceLinkModel,
EFTCreditModel.id == EFTCreditInvoiceLinkModel.eft_credit_id,
)
.join(InvoiceModel, EFTCreditInvoiceLinkModel.invoice_id == InvoiceModel.id)
.filter(EFTRefundModel.status == EFTShortnameRefundStatus.APPROVED.value)
.filter(EFTRefundModel.disbursement_status_code != DisbursementStatus.UPLOADED.value)
.filter(EFTRefundModel.refund_amount > 0)
Expand Down
11 changes: 8 additions & 3 deletions jobs/payment-jobs/tasks/cfs_bank_name_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ def get_bank_info(
+ f"/cfs/parties/{party_number}/accs/{account_number}/sites/{site_number}/payment/"
)
access_token: str = CFSService.get_token().json().get("access_token")
payment_details = CFSService.get(site_payment_url, access_token, AuthHeaderType.BEARER, ContentType.JSON,
additional_headers={"Pay-Connector": current_app.config.get("PAY_CONNECTOR_AUTH")})
payment_details = CFSService.get(
site_payment_url,
access_token,
AuthHeaderType.BEARER,
ContentType.JSON,
additional_headers={"Pay-Connector": current_app.config.get("PAY_CONNECTOR_AUTH")},
)
return payment_details.json()


Expand Down Expand Up @@ -162,7 +167,7 @@ def save_bank_details(
AuthHeaderType.BEARER,
ContentType.JSON,
payment_details,
additional_headers={"Pay-Connector": current_app.config.get("PAY_CONNECTOR_AUTH")}
additional_headers={"Pay-Connector": current_app.config.get("PAY_CONNECTOR_AUTH")},
).json()
current_app.logger.debug("<<<<<<")
current_app.logger.debug(site_payment_response)
Expand Down

0 comments on commit 77b0c77

Please sign in to comment.