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

20907 - Pay outstanding balance switching from EFT payment method #1573

Merged
merged 4 commits into from
Jul 4, 2024

Conversation

ochiu
Copy link
Collaborator

@ochiu ochiu commented Jun 18, 2024

Issue #:
bcgov/entity#20907

Description of changes:

  • removed hybrid properties from statement model, was causing circular dependency issues and the complexity was not working well with general queries
  • add statement search filter to get all statements with an amounting
  • add validation to block changing payment method away from EFT when there is an outstanding balance
  • extend create account payment to support paying an outstanding payment as the existing logic depends on existing failed payments for scenarios like NSF
  • add amount owing to invoices that are currently not part of a statement yet in account summary
  • reworked payment_methods query and optimization
  • moving statement search out of model into service

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the sbc-pay license (Apache 2.0).

Copy link

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@ochiu ochiu marked this pull request as ready for review June 18, 2024 15:03
@@ -115,14 +116,49 @@ def payment_methods(self):

return list(payment_methods)

@hybrid_property
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested the performance scaling of this property over quite a few statements?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this from hybrid property and into the service. The hybrid property was no longer suitable due to the circular dependency issues.

Tested this on a data load with an account over 1000 statements at once, seemed performant

@staticmethod
def get_statement_owing_query():
"""Get statement query used for amount owing."""
from .statement_invoices import StatementInvoices # pylint: disable=import-outside-toplevel
Copy link
Collaborator

@seeker25 seeker25 Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not good, this should be done in a service

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to use this as part of the query existing in the model, I originally tried to do this in the statement service, but

service --> model --> service.

Should I just refactor the model and pull out the statement search up to the service?

Copy link
Collaborator

@seeker25 seeker25 Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the models should be fairly simple

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved out to service

@hybrid_property
def amount_owing(self):
"""Return amount owing on statement."""
from .statement_invoices import StatementInvoices # pylint: disable=import-outside-toplevel
Copy link
Collaborator

@seeker25 seeker25 Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not good, this should be done in a service

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed hybrid property and updated search query

Copy link
Collaborator

@seeker25 seeker25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use service instead of models to go cross models

@ochiu ochiu force-pushed the 20907-EFT-Outstanding-Balance branch from 137648c to eb8634a Compare July 3, 2024 16:34
pay_account: PaymentAccountModel,
invoice_total: Decimal):
"""Create payment for consolidated invoices and update invoice references."""
# Create consolidated invoice
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant


@classmethod
def _consolidate_invoices_and_pay(cls, auth_account_id: str) -> Payment:
# Find outstanding invoices and create a payment
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use """?

)
)

# Combine current and historical records and calculate the date range for when it was active
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good comment

@@ -271,7 +433,12 @@ def get_summary(auth_account_id: str, statement_id: str = None):
total_due = float(result.total_due) if result else 0
oldest_overdue_date = get_local_formatted_date(result.oldest_overdue_date) \
if result and result.oldest_overdue_date else None

# Unpaid invoice amount total that are not part of a statement yet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good comment, not obvious by reading the code

@@ -94,7 +94,8 @@ lines_after_imports = 2


[tool:pytest]
addopts = --cov=src --cov-report html:htmlcov --cov-report xml:coverage.xml
addopts = --verbose
#--cov=src --cov-report html:htmlcov --cov-report xml:coverage.xml
Copy link
Collaborator

@seeker25 seeker25 Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to revert this? I think I use vscode launch.json / settings.json to turn off codecov


invoice_number: str = invoice_response.get('invoice_number')

# Mark all invoice references to status CANCELLED, and create a new one for the new invoice number.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant?

@@ -378,6 +378,13 @@ def _check_and_handle_payment_method(cls, account: PaymentAccountModel, target_p
PaymentMethod.EFT.value not in {account.payment_method, target_payment_method}:
return

# Don't allow payment method change from EFT if there is an outstanding balance
Copy link
Collaborator

@seeker25 seeker25 Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant? can read the code below?

@ochiu ochiu merged commit 64cc341 into main Jul 4, 2024
16 checks passed
@ochiu ochiu deleted the 20907-EFT-Outstanding-Balance branch July 4, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants