Skip to content

Instantly share code, notes, and snippets.

@johncosta
Created July 16, 2012 13:20
Show Gist options
  • Save johncosta/3122678 to your computer and use it in GitHub Desktop.
Save johncosta/3122678 to your computer and use it in GitHub Desktop.
Shutdown code example with few or confusing comments
# TODO 1.5 Does shutdown belong on Order?
@defer_to_detail
def shutdown(self, reason, comment, by_user):
log.debug('Shutdown order (%s) for reason: %s' % (self, reason))
if reason == self.Status.RETURN:
# we're going to ignore deactivated and promo cards, and shutdown as long
# as the primary cards are pristine
deactivated_statuses = [gift_card.Certificate.Status.RETURN,
gift_card.Certificate.Status.DELETED, gift_card.Certificate.Status.FRAUD]
for vgc in self.primary_vgcs.exclude(status__in=deactivated_statuses):
# some clients allow cashout, meaning partial refunds on
# card is acceptable and able to be refunded
# --> do some stuff, clipped for brevity <--
self.refund()
self.set_status(reason, comment, by_user, 'return')
if self.product.is_bulk:
self.order_detail.update_status(reason)
elif reason == self.Status.FRAUD:
self.set_status(reason, comment, by_user)
# Prevent any unsent messages from being sent for this order
self.notifications.cancel_pending_messages()
else:
raise ValueError('Unknown shutdown reason "%s"' % reason)
# Create an api callback to notify users the order was shutdown
self.activationcallback_set.new_callback(self)
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment