Skip to content

Commit

Permalink
[SDESK-4691] Planning was not published when event was completed (#1330)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrvikas authored and MarkLark86 committed Sep 17, 2019
1 parent 1f7e2da commit 06aa4b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,10 @@ def mark_event_complete(self, original, updates, event, mark_complete_validated)
plans = list(get_resource_service('planning').find(where={'event_item': event[config.ID_FIELD]}))
for plan in plans:
if plan.get('state') != WORKFLOW_STATE.CANCELLED and len(plan.get('coverages', [])) > 0:
get_resource_service('planning_cancel').update(plan[config.ID_FIELD], {
get_resource_service('planning_cancel').patch(plan[config.ID_FIELD], {
'reason': 'Event Completed',
'cancel_all_coverage': True,
}, plan)
})

def _convert_to_recurring_event(self, updates, original):
"""Convert a single event to a series of recurring events"""
Expand Down
15 changes: 12 additions & 3 deletions server/planning/planning/planning_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from copy import deepcopy
from .planning import PlanningResource, planning_schema
from planning.common import WORKFLOW_STATE, ITEM_STATE, update_post_item, ITEM_ACTIONS, \
is_valid_event_planning_reason
is_valid_event_planning_reason, ASSIGNMENT_WORKFLOW_STATE


planning_cancel_schema = deepcopy(planning_schema)
Expand Down Expand Up @@ -78,7 +78,7 @@ def update(self, id, updates, original):

planning_service = get_resource_service('planning')
for coverage in coverages:
if coverage['workflow_status'] != WORKFLOW_STATE.CANCELLED:
if coverage['workflow_status'] not in [WORKFLOW_STATE.CANCELLED, ASSIGNMENT_WORKFLOW_STATE.COMPLETED]:
ids.append(coverage.get('coverage_id'))
planning_service.cancel_coverage(coverage, coverage_cancel_state,
coverage.get('workflow_status'), None, reason,
Expand Down Expand Up @@ -122,5 +122,14 @@ def _cancel_plan(self, updates, reason):

def on_updated(self, updates, original):
lock_action = original.get('lock_action')
if lock_action in [ITEM_ACTIONS.EDIT, ITEM_ACTIONS.PLANNING_CANCEL, ITEM_ACTIONS.CANCEL_ALL_COVERAGE]:
if lock_action in [ITEM_ACTIONS.EDIT, ITEM_ACTIONS.PLANNING_CANCEL,
ITEM_ACTIONS.CANCEL_ALL_COVERAGE] or self.is_related_event_completed(updates, original):
update_post_item(updates, original)

def is_related_event_completed(self, updates, original):
if len(original.get('coverages')) > 0 and len(updates.get('coverages') or []) > 0 and \
not original['coverages'][0]['planning'].get('workflow_status_reason') and \
updates['coverages'][0]['planning'].get('workflow_status_reason') == 'Event Completed':
return True

return False

0 comments on commit 06aa4b0

Please sign in to comment.