move request status query methods from domain to model

This commit is contained in:
dandds 2018-09-13 15:18:10 -04:00
parent 8e4430ffc5
commit 2b144aa857
6 changed files with 41 additions and 46 deletions

View File

@ -135,32 +135,6 @@ class Requests(object):
section in existing_request_sections for section in all_request_sections section in existing_request_sections for section in all_request_sections
) )
@classmethod
def is_pending_financial_verification(cls, request):
return request.status == RequestStatus.PENDING_FINANCIAL_VERIFICATION
@classmethod
def is_pending_financial_verification_changes(cls, request):
return request.status == RequestStatus.CHANGES_REQUESTED_TO_FINVER
@classmethod
def is_pending_ccpo_acceptance(cls, request):
return request.status == RequestStatus.PENDING_CCPO_ACCEPTANCE
@classmethod
def is_pending_ccpo_approval(cls, request):
return request.status == RequestStatus.PENDING_CCPO_APPROVAL
@classmethod
def is_pending_ccpo_action(cls, request):
return Requests.is_pending_ccpo_acceptance(
request
) or Requests.is_pending_ccpo_approval(request)
@classmethod
def is_approved(cls, request):
return request.status == RequestStatus.APPROVED
@classmethod @classmethod
def status_count(cls, status, creator=None): def status_count(cls, status, creator=None):
return RequestsQuery.status_count(status, creator) return RequestsQuery.status_count(status, creator)

View File

@ -170,3 +170,27 @@ class Request(Base):
@property @property
def internal_comments_text(self): def internal_comments_text(self):
return self.internal_comments.text if self.internal_comments else "" return self.internal_comments.text if self.internal_comments else ""
@property
def is_pending_financial_verification(self):
return self.status == RequestStatus.PENDING_FINANCIAL_VERIFICATION
@property
def is_pending_financial_verification_changes(self):
return self.status == RequestStatus.CHANGES_REQUESTED_TO_FINVER
@property
def is_pending_ccpo_acceptance(self):
return self.status == RequestStatus.PENDING_CCPO_ACCEPTANCE
@property
def is_pending_ccpo_approval(self):
return self.status == RequestStatus.PENDING_CCPO_APPROVAL
@property
def is_pending_ccpo_action(self):
return self.is_pending_ccpo_acceptance or self.is_pending_ccpo_approval
@property
def is_approved(self):
return self.status == RequestStatus.APPROVED

View File

@ -21,10 +21,8 @@ def map_ccpo_authorizing(user):
def render_approval(request, form=None): def render_approval(request, form=None):
data = request.body data = request.body
pending_final_approval = Requests.is_pending_ccpo_approval(request) pending_final_approval = request.is_pending_ccpo_approval
pending_review = ( pending_review = request.is_pending_ccpo_acceptance or pending_final_approval
Requests.is_pending_ccpo_acceptance(request) or pending_final_approval
)
if pending_final_approval and request.task_order: if pending_final_approval and request.task_order:
data["task_order"] = request.task_order.to_dictionary() data["task_order"] = request.task_order.to_dictionary()

View File

@ -14,9 +14,10 @@ def task_order_data(task_order):
def is_extended(request): def is_extended(request):
return http_request.args.get( return (
"extended" http_request.args.get("extended")
) or Requests.is_pending_financial_verification_changes(request) or request.is_pending_financial_verification_changes
)
def financial_form(request, data): def financial_form(request, data):

View File

@ -44,10 +44,8 @@ class RequestsIndex(object):
num_action_required = len( num_action_required = len(
[r for r in mapped_requests if r.get("action_required")] [r for r in mapped_requests if r.get("action_required")]
) )
pending_fv = any( pending_fv = any(r.is_pending_financial_verification for r in requests)
Requests.is_pending_financial_verification(r) for r in requests pending_ccpo = any(r.is_pending_ccpo_acceptance for r in requests)
)
pending_ccpo = any(Requests.is_pending_ccpo_acceptance(r) for r in requests)
return { return {
"requests": mapped_requests, "requests": mapped_requests,
@ -60,13 +58,13 @@ class RequestsIndex(object):
def _edit_link_for_request(self, viewing_role, request): def _edit_link_for_request(self, viewing_role, request):
if viewing_role == "ccpo": if viewing_role == "ccpo":
return url_for("requests.approval", request_id=request.id) return url_for("requests.approval", request_id=request.id)
elif Requests.is_pending_financial_verification(request): elif request.is_pending_financial_verification:
return url_for("requests.financial_verification", request_id=request.id) return url_for("requests.financial_verification", request_id=request.id)
elif Requests.is_pending_financial_verification_changes(request): elif request.is_pending_financial_verification_changes:
return url_for( return url_for(
"requests.financial_verification", request_id=request.id, extended=True "requests.financial_verification", request_id=request.id, extended=True
) )
elif Requests.is_pending_ccpo_action(request) or Requests.is_approved(request): elif request.is_pending_ccpo_action or request.is_approved:
return url_for("requests.view_request_details", request_id=request.id) return url_for("requests.view_request_details", request_id=request.id)
else: else:
return url_for( return url_for(

View File

@ -128,9 +128,9 @@ def requests_submit(request_id=None):
def view_request_details(request_id=None): def view_request_details(request_id=None):
request = Requests.get(g.current_user, request_id) request = Requests.get(g.current_user, request_id)
financial_review = ( financial_review = (
Requests.is_pending_ccpo_approval(request) request.is_pending_ccpo_approval
or Requests.is_approved(request) or request.is_approved
or Requests.is_pending_financial_verification_changes(request) or request.is_pending_financial_verification_changes
) )
data = request.body data = request.body
@ -142,8 +142,8 @@ def view_request_details(request_id=None):
data=data, data=data,
request_id=request.id, request_id=request.id,
status=request.status_displayname, status=request.status_displayname,
pending_review=Requests.is_pending_ccpo_action(request), pending_review=request.is_pending_ccpo_action,
financial_verification=Requests.is_pending_financial_verification(request) financial_verification=request.is_pending_financial_verification
or Requests.is_pending_financial_verification_changes(request), or request.is_pending_financial_verification_changes,
financial_review=financial_review, financial_review=financial_review,
) )