Skip to content

Commit

Permalink
17224/17829 - EFT over due status handling updates (#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
ochiu authored Oct 23, 2023
1 parent 3cf091a commit 438faed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pay-api/src/pay_api/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from datetime import datetime
from decimal import Decimal
from typing import List, Optional
from dateutil.relativedelta import relativedelta
from attrs import define

from marshmallow import fields, post_dump
Expand All @@ -34,6 +35,7 @@
from .payment_account import PaymentAccountSchema, PaymentAccountSearchModel
from .payment_line_item import PaymentLineItem, PaymentLineItemSchema
from .receipt import ReceiptSchema
from ..utils.util import current_local_time


class Invoice(Audit): # pylint: disable=too-many-instance-attributes
Expand Down Expand Up @@ -98,7 +100,9 @@ class Invoice(Audit): # pylint: disable=too-many-instance-attributes
total = db.Column(db.Numeric(19, 2), nullable=False)
paid = db.Column(db.Numeric(19, 2), nullable=True)
payment_date = db.Column(db.DateTime, nullable=True)
overdue_date = db.Column(db.DateTime, nullable=True)
# default overdue_date to the first of next month
overdue_date = db.Column(db.DateTime, nullable=True,
default=lambda: current_local_time() + relativedelta(months=1, day=1))
refund_date = db.Column(db.DateTime, nullable=True)
refund = db.Column(db.Numeric(19, 2), nullable=True)
routing_slip = db.Column(db.String(50), nullable=True, index=True)
Expand Down
16 changes: 12 additions & 4 deletions pay-api/src/pay_api/services/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ def get_statement_report(statement_id: str, content_type: str, template_name='st
return report_response, report_name

@staticmethod
def get_summary(auth_account_id: str):
def get_summary(auth_account_id: str, statement_id: str = None):
"""Get summary for statements by account id."""
# Used by payment jobs to get the total due amount for statements, keep in mind when modifying.
# 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.
Expand All @@ -181,9 +182,16 @@ def get_summary(auth_account_id: str):
.join(PaymentAccountModel) \
.join(StatementInvoicesModel) \
.filter(PaymentAccountModel.auth_account_id == auth_account_id) \
.filter(InvoiceModel.invoice_status_code == InvoiceStatus.OVERDUE.value) \
.filter(StatementInvoicesModel.invoice_id == InvoiceModel.id) \
.group_by(InvoiceModel.payment_account_id) \
.filter(InvoiceModel.invoice_status_code.in_((InvoiceStatus.SETTLEMENT_SCHEDULED.value,
InvoiceStatus.PARTIAL.value,
InvoiceStatus.CREATED.value,
InvoiceStatus.OVERDUE.value))) \
.filter(StatementInvoicesModel.invoice_id == InvoiceModel.id)

if statement_id:
result = result.filter(StatementInvoicesModel.statement_id == statement_id)

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

total_due = float(result.total_due) if result else 0
Expand Down
7 changes: 7 additions & 0 deletions pay-api/tests/unit/models/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
Test-Suite to ensure that the CorpType Class is working as expected.
"""
from dateutil.relativedelta import relativedelta

from pay_api.models import Invoice, InvoiceSchema
from pay_api.utils.enums import InvoiceStatus
from pay_api.utils.util import current_local_time
from tests.utilities.base_test import factory_invoice, factory_payment, factory_payment_account


Expand All @@ -34,6 +37,10 @@ def test_invoice(session):
invoice.save()
assert invoice.id is not None

# assert overdue default is set
assert invoice.overdue_date is not None
assert invoice.overdue_date.date() == (current_local_time() + relativedelta(months=1, day=1)).date()


def test_invoice_find_by_id(session):
"""Assert a invoice is stored.
Expand Down

0 comments on commit 438faed

Please sign in to comment.