-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #823 from lamontfr/fix822
Command to set orders status to Delivered
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.core.management.base import BaseCommand | ||
from order.models import Order, ORDER_STATUS_ORDERED, ORDER_STATUS_DELIVERED | ||
from datetime import datetime | ||
from django.contrib.admin.models import LogEntry, ADDITION | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Set status to Delivered for all orders that have the status\ | ||
Ordered for the specified delivery date.' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'delivery_date', | ||
help='The date must be in the format YYYY-MM-DD', | ||
) | ||
|
||
def handle(self, *args, **options): | ||
delivery_date = datetime.strptime( | ||
options['delivery_date'], '%Y-%m-%d' | ||
).date() | ||
|
||
numorders = Order.objects.filter( | ||
status=ORDER_STATUS_ORDERED, | ||
delivery_date=delivery_date | ||
).update( | ||
status=ORDER_STATUS_DELIVERED | ||
) | ||
|
||
# Log the execution | ||
LogEntry.objects.log_action( | ||
user_id=1, content_type_id=1, | ||
object_id="", | ||
object_repr="Status set to delivered for orders on" + str( | ||
delivery_date.strftime('%Y-%m-%d %H:%M')), | ||
action_flag=ADDITION, | ||
) | ||
print("Status set to Delivered for {0} orders whose " | ||
"delivery date is {1}.".format(numorders, delivery_date)) |
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