Task Order number not found #159087193
This commit is contained in:
dandds
2018-08-21 16:16:19 -04:00
committed by GitHub
11 changed files with 231 additions and 73 deletions

View File

@@ -18,6 +18,7 @@ from atst.routes.dev import bp as dev_routes
from atst.routes.errors import make_error_pages
from atst.domain.authnid.crl import CRLCache
from atst.domain.auth import apply_authentication
from atst.eda_client import MockEDAClient
ENV = os.getenv("FLASK_ENV", "dev")
@@ -41,6 +42,7 @@ def make_app(config):
make_flask_callbacks(app)
make_crl_validator(app)
register_filters(app)
make_eda_client(app)
db.init_app(app)
csrf.init_app(app)
@@ -139,3 +141,5 @@ def make_crl_validator(app):
crl_locations.append(filename.absolute())
app.crl_cache = CRLCache(app.config["CA_CHAIN"], crl_locations, logger=app.logger)
def make_eda_client(app):
app.eda_client = MockEDAClient()

View File

@@ -1,4 +1,5 @@
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
@@ -8,12 +9,36 @@ from .exceptions import NotFoundError
class TaskOrders(object):
@classmethod
def get(self, order_number):
def get(cls, order_number):
try:
task_order = (
db.session.query(TaskOrder).filter_by(number=order_number).one()
)
except NoResultFound:
raise NotFoundError("task_order")
if TaskOrders._client():
task_order = TaskOrders._get_from_eda(order_number)
else:
raise NotFoundError("task_order")
return task_order
@classmethod
def _get_from_eda(cls, order_number):
to_data = TaskOrders._client().get_contract(order_number, status="y")
if to_data:
return TaskOrders.create(to_data["contract_no"])
else:
raise NotFoundError("task_order")
@classmethod
def create(cls, order_number):
task_order = TaskOrder(number=order_number)
db.session.add(task_order)
db.session.commit()
return task_order
@classmethod
def _client(cls):
return app.eda_client

View File

@@ -71,8 +71,10 @@ class MockEDAClient(EDAClientBase):
},
]
MOCK_CONTRACT_NUMBER = "DCA10096D0052"
def get_contract(self, contract_number, status):
if contract_number == "DCA10096D0052" and status == "y":
if contract_number == self.MOCK_CONTRACT_NUMBER and status == "y":
return {
"aco_mod": "01",
"admin_dodaac": None,

View File

@@ -1,10 +1,11 @@
import re
from wtforms.fields.html5 import EmailField
from wtforms.fields import StringField
from wtforms.validators import Required, Email, Regexp
from wtforms.validators import Required, Email, Regexp, ValidationError
from atst.domain.exceptions import NotFoundError
from atst.domain.pe_numbers import PENumbers
from atst.domain.task_orders import TaskOrders
from .fields import NewlineListField, SelectField
from .forms import ValidatedForm
@@ -57,12 +58,7 @@ def validate_pe_id(field, existing_request):
return True
class FinancialForm(ValidatedForm):
def validate(self, *args, **kwargs):
if self.funding_type.data == "OTHER":
self.funding_type_other.validators.append(Required())
return super().validate(*args, **kwargs)
class BaseFinancialForm(ValidatedForm):
def reset(self):
"""
Reset UII info so that it can be de-parsed rendered properly.
@@ -76,7 +72,11 @@ class FinancialForm(ValidatedForm):
valid = validate_pe_id(self.pe_id, existing_request)
return valid
task_order_id = StringField(
@property
def is_missing_task_order_number(self):
return False
task_order_number = StringField(
"Task Order Number associated with this request",
description="Include the original Task Order number (including the 000X at the end). Do not include any modification numbers. Note that there may be a lag between approving a task order and when it becomes available in our system.",
validators=[Required()]
@@ -117,6 +117,25 @@ class FinancialForm(ValidatedForm):
"Contracting Officer Representative (COR) Office", validators=[Required()]
)
class FinancialForm(BaseFinancialForm):
def validate_task_order_number(form, field):
try:
TaskOrders.get(field.data)
except NotFoundError:
raise ValidationError("Task Order number not found")
@property
def is_missing_task_order_number(self):
return "task_order_number" in self.errors
class ExtendedFinancialForm(BaseFinancialForm):
def validate(self, *args, **kwargs):
if self.funding_type.data == "OTHER":
self.funding_type_other.validators.append(Required())
return super().validate(*args, **kwargs)
funding_type = SelectField(
description="What is the source of funding?",
choices=[

View File

@@ -3,15 +3,25 @@ from flask import request as http_request
from . import requests_bp
from atst.domain.requests import Requests
from atst.forms.financial import FinancialForm
from atst.forms.financial import FinancialForm, ExtendedFinancialForm
def financial_form(data):
if http_request.args.get("extended"):
return ExtendedFinancialForm(data=data)
else:
return FinancialForm(data=data)
@requests_bp.route("/requests/verify/<string:request_id>", methods=["GET"])
def financial_verification(request_id=None):
request = Requests.get(request_id)
form = FinancialForm(data=request.body.get("financial_verification"))
form = financial_form(request.body.get("financial_verification"))
return render_template(
"requests/financial_verification.html", f=form, request_id=request_id
"requests/financial_verification.html",
f=form,
request_id=request_id,
extended=http_request.args.get("extended"),
)
@@ -19,9 +29,9 @@ def financial_verification(request_id=None):
def update_financial_verification(request_id):
post_data = http_request.form
existing_request = Requests.get(request_id)
form = FinancialForm(post_data)
form = financial_form(post_data)
rerender_args = dict(request_id=request_id, f=form)
rerender_args = dict(request_id=request_id, f=form, extended=http_request.args.get("extended"))
if form.validate():
request_data = {"financial_verification": form.data}
@@ -31,11 +41,13 @@ def update_financial_verification(request_id):
Requests.update(request_id, request_data)
if valid:
return redirect(url_for("requests.financial_verification_submitted"))
else:
form.reset()
return render_template(
"requests/financial_verification.html", **rerender_args
)
else:
form.reset()
return render_template("requests/financial_verification.html", **rerender_args)