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

22895 - Refactor statements template into one file #1739

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions pay-api/src/pay_api/services/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,17 @@ def get_statement_invoices(statement_id: int) -> List[InvoiceModel]:
.filter(StatementInvoicesModel.statement_id == statement_id))

@staticmethod
def get_statement_template(statement: StatementModel, ordered_invoices: List[InvoiceModel]) -> str:
def is_eft_statement(statement: StatementModel, ordered_invoices: List[InvoiceModel]) -> bool:
"""Return the statement template name."""
# Check invoice payment method for statement template
if ordered_invoices and ordered_invoices[0].payment_method_code == PaymentMethod.EFT.value:
return StatementTemplate.EFT_STATEMENT.value
return True

# In the event of an empty statement check statement payment methods, could be more than one on transition days
if PaymentMethod.EFT.value in statement.payment_methods:
return StatementTemplate.EFT_STATEMENT.value
return True

return StatementTemplate.STATEMENT_REPORT.value
return False

@staticmethod
def get_invoices_owing_amount(auth_account_id: str):
Expand Down Expand Up @@ -337,13 +337,12 @@ def get_statement_report(statement_id: str, content_type: str, **kwargs):
statement['from_date'] = from_date_string
statement['to_date'] = to_date_string

template_name = Statement.get_statement_template(statement_dao, statement_purchases)
report_inputs = PaymentReportInput(content_type=content_type,
report_name=report_name,
template_name=template_name,
template_name=StatementTemplate.STATEMENT_REPORT.value,
results=result_items)

if template_name == StatementTemplate.EFT_STATEMENT.value:
if Statement.is_eft_statement(statement_dao, statement_purchases):
report_inputs.statement_summary = Statement._populate_statement_summary(statement_dao,
statement_purchases)

Expand Down
1 change: 0 additions & 1 deletion pay-api/src/pay_api/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ class EJVLinkType(Enum):
class StatementTemplate(Enum):
"""Statement report templates."""

EFT_STATEMENT = 'eft_statement'
STATEMENT_REPORT = 'statement_report'


Expand Down
4 changes: 2 additions & 2 deletions pay-api/tests/unit/services/test_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def test_get_eft_statement_for_empty_invoices(session):
}
}
expected_report_inputs = ReportRequest(report_name=report_name,
template_name=StatementTemplate.EFT_STATEMENT.value,
template_name=StatementTemplate.STATEMENT_REPORT.value,
template_vars=expected_template_vars,
populate_page_number=True,
content_type=ContentType.PDF.value)
Expand Down Expand Up @@ -693,7 +693,7 @@ def test_get_eft_statement_with_invoices(session):
}
}
expected_report_inputs = ReportRequest(report_name=report_name,
template_name=StatementTemplate.EFT_STATEMENT.value,
template_name=StatementTemplate.STATEMENT_REPORT.value,
template_vars=expected_template_vars,
populate_page_number=True,
content_type=ContentType.PDF.value)
Expand Down
Loading