-
Notifications
You must be signed in to change notification settings - Fork 39
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
22263 - EFT Refund AP Job Implementation #1719
Merged
Merged
Changes from 22 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
84f2802
EFT Refunds
rodrigo-barraza 46181fc
Merge branch 'main' into feature/22263
rodrigo-barraza 92a24bc
More AP task implementation and cleanup
rodrigo-barraza a7141ab
Lint fixes
rodrigo-barraza 76ebedd
Merge branch 'main' into feature/22263
rodrigo-barraza aa6bd0a
Readding factory_create_eft_account
rodrigo-barraza ba89348
Fixes
rodrigo-barraza d1c553d
removing comments
rodrigo-barraza dc1e4c6
Comment cleanup
rodrigo-barraza d8161ed
Lint fix
rodrigo-barraza a5aa6f5
Feedback updates
rodrigo-barraza 5e5d779
Merge branch 'main' into feature/22263
rodrigo-barraza 014b222
Adding disbursement_status_codes to eft_refund
rodrigo-barraza 4166f4a
Description
rodrigo-barraza a695bd4
Merge branch 'main' into feature/22263
rodrigo-barraza aa74b54
Update pyproject
rodrigo-barraza 7740245
Updating poetry.lock
rodrigo-barraza 3d9fe37
Revert version change
rodrigo-barraza 8ae97f3
Revert lock
rodrigo-barraza 57d24e1
Merge branch 'main' into feature/22263
rodrigo-barraza d788dc6
Pyproject and poetry.lock
rodrigo-barraza 9013100
Lint fix
rodrigo-barraza 8a023ea
New CP job variables
rodrigo-barraza 1059f36
Merge branch 'main' into feature/22263
rodrigo-barraza afa57fc
Tweaks
rodrigo-barraza e9356e8
Merge branch 'main' into feature/22263
rodrigo-barraza 2fe4b5a
Passing CAS Supplier number
rodrigo-barraza 2a33c54
Merge branch 'main' into feature/22263
rodrigo-barraza 4008568
Adding comment to EFT refund AP job
rodrigo-barraza c3b0a09
Updating migration
rodrigo-barraza 02d60ba
EFTShortnameRefundStatus
rodrigo-barraza bf936a5
Fixes
rodrigo-barraza da44192
REFUND_REQUESTED to APPROVED
rodrigo-barraza 174cd16
Merge branch 'main' into feature/22263
rodrigo-barraza 6953947
Merge branch 'main' into feature/22263
rodrigo-barraza 361ebdf
Cleanup
rodrigo-barraza bf4e431
Lint fix
rodrigo-barraza 27543c6
Fixing deps
rodrigo-barraza 0b77a32
Deps fix
rodrigo-barraza c70746c
Revision fix
rodrigo-barraza 6ae8c67
isort fix
rodrigo-barraza 4d9943f
isort fix
rodrigo-barraza fa51d23
Revision fix
rodrigo-barraza 86f2388
Revision fix
rodrigo-barraza ddaa201
Deps fix
rodrigo-barraza 890bf03
small test fix
rodrigo-barraza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,18 @@ | |
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 EFTShortnameLinks as EFTShortnameLinksModel | ||
from pay_api.models import EFTRefund as EFTRefundModel | ||
from pay_api.models import EjvFile as EjvFileModel | ||
from pay_api.models import EjvHeader as EjvHeaderModel | ||
from pay_api.models import EjvLink as EjvLinkModel | ||
from pay_api.models import Invoice as InvoiceModel | ||
from pay_api.models import Refund as RefundModel | ||
from pay_api.models import RoutingSlip as RoutingSlipModel | ||
from pay_api.models import db | ||
from pay_api.utils.enums import DisbursementStatus, EjvFileType, EJVLinkType, RoutingSlipStatus | ||
from pay_api.utils.enums import DisbursementStatus, EjvFileType, EJVLinkType, InvoiceStatus, RoutingSlipStatus | ||
from tasks.common.cgi_ap import CgiAP | ||
from tasks.common.dataclasses import APLine | ||
from tasks.ejv_partner_distribution_task import EjvPartnerDistributionTask | ||
|
@@ -59,9 +63,58 @@ def create_ap_files(cls): | |
6. Create AP file and upload to SFTP. | ||
7. After some time, a feedback file will arrive and Payment-reconciliation queue will set disbursement | ||
status to COMPLETED or REVERSED (filter out) | ||
8. Find all EFT refunds with status REFUND_REQUESTED. | ||
9. Create AP file and upload to SFTP. | ||
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() | ||
|
||
@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[tuple[InvoiceModel, EFTRefundModel]] = db.session.query(InvoiceModel, EFTRefundModel) \ | ||
.join(EFTCreditInvoiceLinkModel, EFTCreditInvoiceLinkModel.invoice_id == InvoiceModel.id) \ | ||
.join(EFTCreditModel, EFTCreditModel.id == EFTCreditInvoiceLinkModel.eft_credit_id) \ | ||
.join(EFTShortnameLinksModel, EFTShortnameLinksModel.eft_short_name_id == EFTCreditModel.short_name_id) \ | ||
.join(EFTRefundModel, EFTRefundModel.short_name_id == EFTShortnameLinksModel.eft_short_name_id) \ | ||
.filter(EFTRefundModel.status == InvoiceStatus.REFUND_REQUESTED.value) \ | ||
.filter(EFTRefundModel.refund_amount > 0) \ | ||
.all() | ||
|
||
current_app.logger.info(f'Found {len(eft_refunds_dao)} to refund.') | ||
|
||
for refunds in list(batched(eft_refunds_dao, 250)): | ||
ejv_file_model = EjvFileModel( | ||
file_type=cls.ap_type.value, | ||
file_ref=cls.get_file_name(), | ||
disbursement_status_code=DisbursementStatus.UPLOADED.value | ||
).flush() | ||
|
||
batch_number: str = cls.get_batch_number(ejv_file_model.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change hint for get_batch_number to return |
||
ap_content: str = cls.get_batch_header(batch_number) | ||
batch_total = 0 | ||
line_count_total: int = 0 | ||
seeker25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for invoice_refund in refunds: | ||
invoice, eft_refund = invoice_refund | ||
current_app.logger.info(f'Creating refund for {invoice.id}, Amount {eft_refund.refund_amount}.') | ||
ap_content = f'{ap_content}{cls.get_ap_header( | ||
eft_refund.refund_amount, invoice.id, invoice.created_on)}' | ||
ap_line = APLine( | ||
total=eft_refund.refund_amount, | ||
invoice_number=invoice.id, | ||
line_number=line_count_total + 1) | ||
ap_content = f'{ap_content}{cls.get_ap_invoice_line(ap_line)}' | ||
line_count_total += 2 | ||
batch_total += eft_refund.refund_amount | ||
eft_refund.disbursement_status_code = DisbursementStatus.UPLOADED.value | ||
|
||
batch_trailer: str = cls.get_batch_trailer(batch_number, batch_total, control_total=line_count_total) | ||
ap_content = f'{ap_content}{batch_trailer}' | ||
cls._create_file_and_upload(ap_content) | ||
|
||
@classmethod | ||
def _create_routing_slip_refund_file(cls): # pylint:disable=too-many-locals, too-many-statements | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to filter out eft_refund.disbursement_status_code = UPLOADED ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EFTRefundModels.status probably shouldn't be compared to the InvoiceStatus.
It also looks like when we create the eft_refund in pay api it uses EFTCreditInvoiceStatus. EFT refunds has its own flow, I would suggest it has its own set of statuses.
Something similar to:
PENDING_APPROVAL
REJECTED
APPROVED