Merge pull request #300 from dod-ccpo/total-spend-#159974960
reports shows real budget information for total spend
This commit is contained in:
commit
e34b1b55d0
@ -154,18 +154,15 @@ CUMULATIVE_BUDGET_BELUGA = {
|
|||||||
|
|
||||||
class Reports:
|
class Reports:
|
||||||
@classmethod
|
@classmethod
|
||||||
def workspace_totals(cls, alternate):
|
def workspace_totals(cls, workspace):
|
||||||
data = MONTHLY_SPEND_BELUGA if alternate else MONTHLY_SPEND_AARDVARK
|
if workspace.request and workspace.request.task_order:
|
||||||
spent = sum(
|
ws_to = workspace.request.task_order
|
||||||
[
|
budget = ws_to.budget
|
||||||
spend
|
else:
|
||||||
for project in data.values()
|
budget = 0
|
||||||
for env in project.values()
|
|
||||||
for spend in env.values()
|
# spent will be derived from CSP data
|
||||||
]
|
return {"budget": budget, "spent": 0}
|
||||||
)
|
|
||||||
budget = 70_000 if alternate else 500_000
|
|
||||||
return {"budget": budget, "spent": spent}
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def monthly_totals(cls, alternate):
|
def monthly_totals(cls, alternate):
|
||||||
|
@ -47,3 +47,19 @@ class TaskOrder(Base):
|
|||||||
for c in self.__table__.columns
|
for c in self.__table__.columns
|
||||||
if c.name not in ["id", "attachment_id"]
|
if c.name not in ["id", "attachment_id"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def budget(self):
|
||||||
|
return sum(
|
||||||
|
filter(
|
||||||
|
None,
|
||||||
|
[
|
||||||
|
self.clin_0001,
|
||||||
|
self.clin_0003,
|
||||||
|
self.clin_1001,
|
||||||
|
self.clin_1003,
|
||||||
|
self.clin_2001,
|
||||||
|
self.clin_2003,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
@ -109,7 +109,7 @@ def workspace_reports(workspace_id):
|
|||||||
return render_template(
|
return render_template(
|
||||||
"workspaces/reports/index.html",
|
"workspaces/reports/index.html",
|
||||||
cumulative_budget=Reports.cumulative_budget(alternate_reports),
|
cumulative_budget=Reports.cumulative_budget(alternate_reports),
|
||||||
workspace_totals=Reports.workspace_totals(alternate_reports),
|
workspace_totals=Reports.workspace_totals(workspace),
|
||||||
monthly_totals=Reports.monthly_totals(alternate_reports),
|
monthly_totals=Reports.monthly_totals(alternate_reports),
|
||||||
current_month=current_month,
|
current_month=current_month,
|
||||||
prev_month=prev_month,
|
prev_month=prev_month,
|
||||||
|
18
tests/domain/test_reports.py
Normal file
18
tests/domain/test_reports.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from atst.domain.reports import Reports
|
||||||
|
|
||||||
|
from tests.factories import RequestFactory, TaskOrderFactory, WorkspaceFactory
|
||||||
|
|
||||||
|
CLIN_NUMS = ["0001", "0003", "1001", "1003", "2001", "2003"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_workspace_totals():
|
||||||
|
task_order = TaskOrderFactory.create()
|
||||||
|
|
||||||
|
for num in CLIN_NUMS:
|
||||||
|
setattr(task_order, "clin_{}".format(num), 200)
|
||||||
|
|
||||||
|
request = RequestFactory.create(task_order=task_order)
|
||||||
|
workspace = WorkspaceFactory.create(request=request)
|
||||||
|
report = Reports.workspace_totals(workspace)
|
||||||
|
total = 200 * len(CLIN_NUMS)
|
||||||
|
assert report == {"budget": total, "spent": 0}
|
@ -7,3 +7,15 @@ def test_as_dictionary():
|
|||||||
data = TaskOrderFactory.dictionary()
|
data = TaskOrderFactory.dictionary()
|
||||||
real_task_order = TaskOrderFactory.create(**data)
|
real_task_order = TaskOrderFactory.create(**data)
|
||||||
assert real_task_order.to_dictionary() == data
|
assert real_task_order.to_dictionary() == data
|
||||||
|
|
||||||
|
|
||||||
|
def test_budget():
|
||||||
|
task_order = TaskOrderFactory.create(
|
||||||
|
clin_0001=500,
|
||||||
|
clin_0003=200,
|
||||||
|
clin_1001=None,
|
||||||
|
clin_1003=None,
|
||||||
|
clin_2001=None,
|
||||||
|
clin_2003=None,
|
||||||
|
)
|
||||||
|
assert task_order.budget == 700
|
||||||
|
Loading…
x
Reference in New Issue
Block a user