Save TO creator data as cor data if am_cor is checked

This commit is contained in:
Montana 2019-01-15 11:42:44 -05:00
parent 41268cc1e4
commit 5d4fee9546
3 changed files with 22 additions and 5 deletions

View File

@ -25,6 +25,7 @@ from .data import (
) )
from atst.utils.localization import translate from atst.utils.localization import translate
class RequiredIfNot(Required): class RequiredIfNot(Required):
# a validator which makes a field required only if # a validator which makes a field required only if
# another field has a falsy value # another field has a falsy value
@ -137,20 +138,19 @@ class OversightForm(CacheableForm):
validators=[Required(), Length(min=10), IsNumber()], validators=[Required(), Length(min=10), IsNumber()],
) )
am_cor = BooleanField( am_cor = BooleanField(translate("forms.task_order.oversight_am_cor_label"))
translate("forms.task_order.oversight_am_cor_label"),
)
cor_first_name = StringField( cor_first_name = StringField(
translate("forms.task_order.oversight_first_name_label") translate("forms.task_order.oversight_first_name_label")
) )
cor_last_name = StringField(translate("forms.task_order.oversight_last_name_label")) cor_last_name = StringField(translate("forms.task_order.oversight_last_name_label"))
cor_email = StringField(translate("forms.task_order.oversight_email_label")) cor_email = StringField(translate("forms.task_order.oversight_email_label"))
cor_phone_number = TelField( cor_phone_number = TelField(
translate("forms.task_order.oversight_phone_label"), validators=[RequiredIfNot('am_cor'), PhoneNumber()] translate("forms.task_order.oversight_phone_label"),
validators=[RequiredIfNot("am_cor"), PhoneNumber()],
) )
cor_dod_id = StringField( cor_dod_id = StringField(
translate("forms.task_order.oversight_dod_id_label"), translate("forms.task_order.oversight_dod_id_label"),
validators=[RequiredIfNot('am_cor'), Length(min=10), IsNumber()], validators=[RequiredIfNot("am_cor"), Length(min=10), IsNumber()],
) )
so_first_name = StringField( so_first_name = StringField(

View File

@ -130,6 +130,16 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow):
if "dev_team" in to_data and "other" not in to_data["dev_team"]: if "dev_team" in to_data and "other" not in to_data["dev_team"]:
to_data["dev_team_other"] = None to_data["dev_team_other"] = None
if self.form_data.get("am_cor"):
cor_data = {
"cor_first_name": self.user.first_name,
"cor_last_name": self.user.last_name,
"cor_email": self.user.email,
"cor_phone_number": self.user.phone_number,
"cor_dod_id": self.user.dod_id,
}
to_data = {**to_data, **cor_data}
return to_data return to_data
def validate(self): def validate(self):

View File

@ -175,6 +175,13 @@ def test_other_text_not_saved_if_other_not_checked(task_order):
assert not workflow.task_order.complexity_other assert not workflow.task_order.complexity_other
def test_cor_data_set_to_user_data_if_am_cor_is_checked(task_order):
to_data = {**task_order.to_dictionary(), "am_cor": True}
workflow = UpdateTaskOrderWorkflow(task_order.creator, to_data, 3, task_order.id)
workflow.update()
assert task_order.cor_dod_id == task_order.creator.dod_id
def test_invite_officers_to_task_order(task_order, queue): def test_invite_officers_to_task_order(task_order, queue):
to_data = { to_data = {
**TaskOrderFactory.dictionary(), **TaskOrderFactory.dictionary(),