Skip to content

Commit

Permalink
22895 - Refactor statements template into one file (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Sep 11, 2024
2 parents e7cac81 + 0df78a5 commit ba9eda3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
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

0 comments on commit ba9eda3

Please sign in to comment.