Fix UpdateTaskOrderWorkflow to validate using the correct form when unclassified

This commit is contained in:
leigh-mil 2019-01-29 14:14:18 -05:00
parent 5057d2d603
commit 090fd167bb
3 changed files with 22 additions and 15 deletions

View File

@ -1,5 +1,7 @@
from sqlalchemy.orm.exc import NoResultFound
from flask import current_app as app
from atst.database import db
from atst.models.task_order import TaskOrder
from atst.models.permissions import Permissions
@ -50,6 +52,8 @@ class TaskOrders(object):
],
}
UNCLASSIFIED_FUNDING = ["performance_length", "csp_estimate", "clin_01", "clin_03"]
@classmethod
def get(cls, user, task_order_id):
try:
@ -90,7 +94,10 @@ class TaskOrders(object):
@classmethod
def is_section_complete(cls, task_order, section):
if section in TaskOrders.SECTIONS:
sections = TaskOrders.SECTIONS
if not app.config.get("CLASSIFIED"):
sections["funding"] = TaskOrders.UNCLASSIFIED_FUNDING
if section in sections:
for attr in TaskOrders.SECTIONS[section]:
if getattr(task_order, attr) is None:
return False
@ -102,7 +109,10 @@ class TaskOrders(object):
@classmethod
def all_sections_complete(cls, task_order):
for section in TaskOrders.SECTIONS.keys():
sections = TaskOrders.SECTIONS
if not app.config.get("CLASSIFIED"):
sections["funding"] = TaskOrders.UNCLASSIFIED_FUNDING
for section in sections:
if not TaskOrders.is_section_complete(task_order, section):
return False

View File

@ -120,22 +120,15 @@ class FundingForm(CacheableForm):
class UnclassifiedFundingForm(FundingForm):
clin_02 = DecimalField(
clin_02 = StringField(
translate("forms.task_order.unclassified_clin_02_label"),
places=2,
validators=[InputRequired(message="Please enter a dollar amount")],
filters=[lambda x: x or None],
)
clin_04 = DecimalField(
clin_04 = StringField(
translate("forms.task_order.unclassified_clin_04_label"),
places=2,
validators=[InputRequired(message="Please enter a dollar amount")],
filters=[lambda x: x or None],
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.clin_02.data = "0.00"
self.clin_04.data = "0.00"
class OversightForm(CacheableForm):
ko_first_name = StringField(

View File

@ -128,7 +128,12 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow):
self.portfolio_id = portfolio_id
self._task_order = None
self._section = TASK_ORDER_SECTIONS[screen - 1]
self._form = self._section["form"](self.form_data)
form_type = (
"unclassified_form"
if "unclassified_form" in self._section and not app.config.get("CLASSIFIED")
else "form"
)
self._form = self._section[form_type](self.form_data)
@property
def form(self):
@ -277,7 +282,6 @@ def update(screen, task_order_id=None, portfolio_id=None):
workflow = UpdateTaskOrderWorkflow(
g.current_user, form_data, screen, task_order_id, portfolio_id
)
if workflow.validate():
workflow.update()
return redirect(