-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
171 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
37 changes: 37 additions & 0 deletions
37
lms/djangoapps/shoppingcart/management/commands/retire_order.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Script for retiring order that went through cybersource but weren't | ||
marked as "purchased" in the db | ||
""" | ||
|
||
from django.core.management.base import BaseCommand, CommandError | ||
from shoppingcart.models import Order, OrderItem | ||
from shoppingcart.exceptions import UnexpectedOrderItemStatus, InvalidStatusToRetire | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Retire orders that went through cybersource but weren't updated | ||
appropriately in the db | ||
""" | ||
help = """ | ||
Retire orders that went through cybersource but weren't updated appropriately in the db. | ||
Takes a file of orders to be retired, one order per line | ||
""" | ||
|
||
def handle(self, *args, **options): | ||
"Execute the command" | ||
if len(args) != 1: | ||
raise CommandError("retire_order requires one argument: <orders file>") | ||
|
||
with open(args[0]) as orders_file: | ||
order_ids = [int(line.strip()) for line in orders_file.readlines()] | ||
|
||
orders = Order.objects.filter(id__in=order_ids) | ||
|
||
for order in orders: | ||
try: | ||
order.retire() | ||
except (UnexpectedOrderItemStatus, InvalidStatusToRetire) as err: | ||
print "Did not retire order {order}: {message}".format( | ||
order = order.id, message = err.message | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters