From febb2c5d0a1bd4d6c10eb7599bf9821dfb19ebab Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Fri, 1 Mar 2019 14:57:03 -0500 Subject: [PATCH] Fake remaining balance for A-Wing and B-Wing --- atst/models/task_order.py | 18 ++++++++++++++++++ templates/portfolios/header.html | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/atst/models/task_order.py b/atst/models/task_order.py index b09eca73..96bf6ebf 100644 --- a/atst/models/task_order.py +++ b/atst/models/task_order.py @@ -19,6 +19,11 @@ from werkzeug.datastructures import FileStorage from atst.models import Attachment, Base, types, mixins +# Imports used for mocking TO balance +from atst.domain.csp.reports import MockReportingProvider +from flask import current_app as app +import random + class Status(Enum): STARTED = "Started" @@ -135,6 +140,10 @@ class TaskOrder(Base, mixins.TimestampsMixin): def is_active(self): return self.status == Status.ACTIVE + @property + def is_expired(self): + return self.status == Status.EXPIRED + @property def status(self): if self.is_submitted: @@ -164,6 +173,15 @@ class TaskOrder(Base, mixins.TimestampsMixin): @property def balance(self): + # Faking the remaining balance using the stubbed reporting data for A-Wing & B-Wing + if ( + self.portfolio_name in MockReportingProvider.REPORT_FIXTURE_MAP + and self.is_active + ): + return self.budget - app.csp.reports.get_total_spending(self.portfolio) + # Faking an almost fully spent TO if the TO is expired + if self.is_expired: + return random.randrange(300) / 100 # nosec # TODO: somehow calculate the remaining balance. For now, assume $0 spent return self.budget diff --git a/templates/portfolios/header.html b/templates/portfolios/header.html index 1af5dbd5..c86701da 100644 --- a/templates/portfolios/header.html +++ b/templates/portfolios/header.html @@ -27,10 +27,10 @@
- {{ portfolio.task_orders | selectattr('is_active') | sum(attribute='budget') | justDollars }} + {{ portfolio.task_orders | selectattr('is_active') | sum(attribute='balance') | justDollars }} - .{{ portfolio.task_orders | selectattr('is_active') | sum(attribute='budget') | justCents }} + .{{ portfolio.task_orders | selectattr('is_active') | sum(attribute='balance') | justCents }}