clicrdv: add transitions on success/failure of cancellation (#1481)
This commit is contained in:
parent
f70edccf79
commit
d1aea22687
|
@ -309,7 +309,23 @@ register_item_class(ClicRdvCreateAppointment)
|
|||
class ClicRdvCancelAppointment(WorkflowStatusItem):
|
||||
description = N_('Cancel a ClicRDV Appointment')
|
||||
key = 'clicrdv-cancel'
|
||||
endpoint = True
|
||||
endpoint = False
|
||||
|
||||
status_on_success = None
|
||||
status_on_failure = None
|
||||
|
||||
def get_parameters(self):
|
||||
return ('status_on_success', 'status_on_failure')
|
||||
|
||||
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None):
|
||||
if 'status_on_success' in parameters:
|
||||
form.add(SingleSelectWidget, '%sstatus_on_success' % prefix,
|
||||
title=_('Status On Success'), value=self.status_on_success,
|
||||
options = [(None, '---')] + [(x.id, x.name) for x in self.parent.parent.possible_status])
|
||||
if 'status_on_failure' in parameters:
|
||||
form.add(SingleSelectWidget, '%sstatus_on_failure' % prefix,
|
||||
title=_('Status On Failure'), value=self.status_on_failure,
|
||||
options = [(None, '---')] + [(x.id, x.name) for x in self.parent.parent.possible_status])
|
||||
|
||||
def is_available(self):
|
||||
return get_publisher().has_site_option('clicrdv')
|
||||
|
@ -319,12 +335,23 @@ class ClicRdvCancelAppointment(WorkflowStatusItem):
|
|||
return _('Cancel an appointment in ClicRDV')
|
||||
|
||||
def perform(self, formdata):
|
||||
success = True
|
||||
|
||||
for evo in [evo for evo in formdata.evolution if evo.parts]:
|
||||
for part in [part for part in evo.parts if isinstance(part, AppointmentPart)]:
|
||||
appointment_id = part.id
|
||||
req = get_clicrdv_req('appointments/%s' % appointment_id)
|
||||
req.get_method = (lambda: 'DELETE')
|
||||
fd = urllib2.urlopen(req)
|
||||
none = fd.read()
|
||||
try:
|
||||
req = get_clicrdv_req('appointments/%s' % appointment_id)
|
||||
req.get_method = (lambda: 'DELETE')
|
||||
fd = urllib2.urlopen(req)
|
||||
none = fd.read()
|
||||
except: # no idea what's the error that would be raised :/
|
||||
success = False
|
||||
|
||||
if (success and self.status_on_success) or (success is False and self.status_on_failure):
|
||||
if success:
|
||||
formdata.status = 'wf-%s' % self.status_on_success
|
||||
else:
|
||||
formdata.status = 'wf-%s' % self.status_on_failure
|
||||
|
||||
register_item_class(ClicRdvCancelAppointment)
|
||||
|
|
Reference in New Issue