Skip to content

Commit

Permalink
More simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 committed Jul 17, 2024
1 parent 0be8fb8 commit dbf4040
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions jobs/payment-jobs/tasks/electronic_funds_transfer_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,15 @@ def _apply_eft_receipt_to_invoice(cls,
cfs_account: CfsAccountModel,
invoice: InvoiceModel,
invoice_number: str,
receipt_number) -> bool:
receipt_number,
amount) -> bool:
"""Apply electronic funds transfers (receipts in CFS) to invoice."""
current_app.logger.debug(f'Apply receipt {receipt_number} on invoice {invoice_number} ')
receipt_balance_before_apply = float(
CFSService.get_receipt(cfs_account, receipt_number).get('unapplied_amount')
)
current_app.logger.debug(f'Current balance on {receipt_number} = {receipt_balance_before_apply}')
current_app.logger.debug(f'Applying receipt {receipt_number} to {invoice_number}')
receipt_response = CFSService.apply_receipt(cfs_account, receipt_number, invoice_number)
receipt_json = receipt_response.json()
receipt = ReceiptModel(receipt_number=receipt_json.get('receipt_number', None),
receipt_amount=receipt_balance_before_apply -
float(receipt_json.get('unapplied_amount')),
receipt_amount=amount,
invoice_id=invoice.id,
receipt_date=datetime.now(tz=timezone.utc))
receipt.flush()
Expand Down Expand Up @@ -105,8 +101,7 @@ def link_electronic_funds_transfers_cfs(cls):
payment_method=PaymentMethod.EFT.value,
access_token=CFSService.get_token(PaymentSystem.FAS).json().get('access_token'))
cls._apply_eft_receipt_to_invoice(
cfs_account, invoice, invoice_reference.invoice_number, receipt_number
)
cfs_account, invoice, invoice_reference.invoice_number, receipt_number, credit_invoice_link.amount)
invoice.invoice_status_code = InvoiceStatus.PAID.value
invoice.paid = credit_invoice_link.amount
invoice.payment_date = datetime.now(tz=timezone.utc)
Expand Down

0 comments on commit dbf4040

Please sign in to comment.