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

17829 - Implement summary route for statements. #1256

Merged
merged 2 commits into from
Sep 26, 2023

Conversation

seeker25
Copy link
Collaborator

Issue #:
bcgov/entity#17829

Description of changes:
Return invoices that are included in summaries, for the pending balance.

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).


# Check if user is authorized to perform this action
check_auth(business_identifier=None, account_id=account_id, contains_role=EDIT_ROLE, is_premium=True)
check_auth(business_identifier=None, account_id=account_id, contains_role=EDIT_ROLE)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some cleanup, eventually we want to get rid of premium accounts

@@ -60,12 +60,26 @@ def get_account_statement(account_id: str, statement_id: str):
response_content_type = request.headers.get('Accept', ContentType.PDF.value)

# Check if user is authorized to perform this action
auth = check_auth(business_identifier=None, account_id=account_id, contains_role=EDIT_ROLE, is_premium=True)
auth = check_auth(business_identifier=None, account_id=account_id, contains_role=EDIT_ROLE)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some cleanup, eventually we want to get rid of premium accounts

.group_by(InvoiceModel.payment_account_id) \
.one_or_none()

total_due = float(result.total_due) if result else 0
Copy link
Collaborator Author

@seeker25 seeker25 Sep 26, 2023

Choose a reason for hiding this comment

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

Couldn't find a nicer way to do this unfortunately. I tried .first(), .all() etc. Could be replaced by scalars() in SQLAlchemy 2 possibly

@staticmethod
def get_summary(auth_account_id: str):
"""Get summary for statements by account id."""
# This is written outside of the model, because we have multiple model references that need to be included.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps worth reading

@sonarcloud
Copy link

sonarcloud bot commented Sep 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

# This is written outside of the model, because we have multiple model references that need to be included.
# If we include these references inside of a model, it runs the risk of having circular dependencies.
# It's easier to build out features if our models don't rely on other models.
result = db.session.query(func.sum(InvoiceModel.total - InvoiceModel.paid).label('total_due'),
Copy link
Collaborator Author

@seeker25 seeker25 Sep 26, 2023

Choose a reason for hiding this comment

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

This should cover partial payments ideally (not implemented currently, maybe for online banking)

result = db.session.query(func.sum(InvoiceModel.total - InvoiceModel.paid).label('total_due'),
func.min(InvoiceModel.overdue_date).label('oldest_overdue_date')) \
.join(PaymentAccountModel) \
.join(StatementInvoicesModel) \
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Uses Statement invoices, so this only shows invoices that have statements. Otherwise I would have moved this into the invoice service.

@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

Merging #1256 (a863e98) into main (79924ce) will increase coverage by 0.02%.
Report is 5 commits behind head on main.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1256      +/-   ##
==========================================
+ Coverage   91.45%   91.47%   +0.02%     
==========================================
  Files         186      177       -9     
  Lines       11319    10514     -805     
==========================================
- Hits        10352     9618     -734     
+ Misses        967      896      -71     
Flag Coverage Δ
payapi 93.75% <100.00%> (+0.01%) ⬆️
paymentreconciliationsqueue ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
pay-api/src/pay_api/models/invoice.py 100.00% <100.00%> (ø)
...api/src/pay_api/resources/v1/account_statements.py 100.00% <100.00%> (ø)
pay-api/src/pay_api/services/statement.py 97.24% <100.00%> (+0.34%) ⬆️
pay-api/src/pay_api/utils/enums.py 100.00% <100.00%> (ø)
pay-api/src/pay_api/version.py 100.00% <100.00%> (ø)

... and 9 files with indirect coverage changes

"""Get summary for statements by account id."""
# This is written outside of the model, because we have multiple model references that need to be included.
# If we include these references inside of a model, it runs the risk of having circular dependencies.
# It's easier to build out features if our models don't rely on other models.
Copy link
Collaborator Author

@seeker25 seeker25 Sep 26, 2023

Choose a reason for hiding this comment

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

Ideally resources rely on services, should rely on models, models should never rely on models - Otherwise you're in for a world of pain with circular references.

@seeker25 seeker25 merged commit 37ac454 into bcgov:main Sep 26, 2023
7 checks passed
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