Save as draft

This commit is contained in:
George Drummond
2019-06-17 11:04:44 -04:00
parent c0da5d482f
commit d672f5792c
10 changed files with 107 additions and 30 deletions

View File

@@ -7,7 +7,7 @@ from wtforms.fields import (
StringField,
)
from wtforms.fields.html5 import DateField
from wtforms.validators import Required
from wtforms.validators import Required, Optional
from flask_wtf.file import FileAllowed
from flask_wtf import FlaskForm
@@ -30,18 +30,20 @@ class CLINForm(FlaskForm):
"CLIN type", choices=JEDI_CLIN_TYPES, coerce=coerce_enum
)
number = StringField(label="CLIN", validators=[Required()])
number = StringField(label="CLIN", validators=[Optional()])
start_date = DateField(
translate("forms.task_order.start_date_label"),
format="%m/%d/%Y",
validators=[Required()],
validators=[Optional()],
)
end_date = DateField(
translate("forms.task_order.end_date_label"),
format="%m/%d/%Y",
validators=[Required()],
validators=[Optional()],
)
obligated_amount = DecimalField(
label="Funds obligated for cloud", validators=[Optional()]
)
obligated_amount = DecimalField(label="Funds obligated for cloud")
loas = FieldList(StringField())

View File

@@ -21,12 +21,12 @@ class CLIN(Base, mixins.TimestampsMixin):
task_order_id = Column(ForeignKey("task_orders.id"), nullable=False)
task_order = relationship("TaskOrder")
number = Column(String, nullable=False)
loas = Column(ARRAY(String), server_default="{}", nullable=False)
start_date = Column(Date, nullable=False)
end_date = Column(Date, nullable=False)
obligated_amount = Column(Numeric(scale=2), nullable=False)
jedi_clin_type = Column(SQLAEnum(JEDICLINType, native_enum=False), nullable=False)
number = Column(String, nullable=True)
loas = Column(ARRAY(String), server_default="{}", nullable=True)
start_date = Column(Date, nullable=True)
end_date = Column(Date, nullable=True)
obligated_amount = Column(Numeric(scale=2), nullable=True)
jedi_clin_type = Column(SQLAEnum(JEDICLINType, native_enum=False), nullable=True)
#
# NOTE: For now obligated CLINS are CLIN 1 + CLIN 3

View File

@@ -86,11 +86,11 @@ class TaskOrder(Base, mixins.TimestampsMixin):
@property
def has_begun(self):
return Clock.today() >= self.start_date
return self.start_date is not None and Clock.today() >= self.start_date
@property
def has_ended(self):
return Clock.today() >= self.end_date
return self.start_date is not None and Clock.today() >= self.end_date
@property
def is_completed(self):
@@ -133,7 +133,7 @@ class TaskOrder(Base, mixins.TimestampsMixin):
def total_obligated_funds(self):
total = 0
for clin in self.clins:
if clin.jedi_clin_type in [
if clin.obligated_amount is not None and clin.jedi_clin_type in [
JEDICLINType.JEDI_CLIN_1,
JEDICLINType.JEDI_CLIN_3,
]:
@@ -144,7 +144,8 @@ class TaskOrder(Base, mixins.TimestampsMixin):
def total_contract_amount(self):
total = 0
for clin in self.clins:
total += clin.obligated_amount
if clin.obligated_amount is not None:
total += clin.obligated_amount
return total
@property

View File

@@ -14,12 +14,15 @@ from atst.utils.flash import formatted_flash as flash
@user_can(Permissions.VIEW_TASK_ORDER_DETAILS, message="review task order details")
def review_task_order(task_order_id):
task_order = TaskOrders.get(task_order_id)
signature_form = SignatureForm()
return render_template(
"portfolios/task_orders/review.html",
task_order=task_order,
signature_form=signature_form,
)
if task_order.is_draft:
return redirect(url_for("task_orders.edit", task_order_id=task_order.id))
else:
signature_form = SignatureForm()
return render_template(
"portfolios/task_orders/review.html",
task_order=task_order,
signature_form=signature_form,
)
@task_orders_bp.route("/task_orders/<task_order_id>/submit", methods=["POST"])

View File

@@ -57,13 +57,14 @@ def update(portfolio_id=None, task_order_id=None):
else:
task_order = TaskOrders.create(g.current_user, portfolio_id, **form.data)
if http_request.args.get("review"):
if task_order.is_completed and http_request.args.get("review"):
return redirect(
url_for("task_orders.review_task_order", task_order_id=task_order.id)
)
flash("task_order_draft")
return redirect(url_for("task_orders.edit", task_order_id=task_order.id))
else:
return render_task_orders_edit(portfolio_id, task_order_id, form), 400
if task_order.is_completed:
return redirect(url_for("task_orders.edit", task_order_id=task_order.id))
return render_task_orders_edit(portfolio_id, task_order_id, form), 400