Permalink
Browse files

Merge pull request #823 from lamontfr/fix822

Command to set orders status to Delivered
  • Loading branch information...
lamontfr committed Dec 12, 2017
2 parents e2f6b28 + 0c54266 commit 844ca09186124734e6db774d3e832801fde2b613
Showing with 81 additions and 1 deletion.
  1. +38 −0 src/order/management/commands/setordersdelivered.py
  2. +1 −0 src/order/models.py
  3. +42 −1 src/order/tests.py
@@ -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))
View
@@ -32,6 +32,7 @@
)
ORDER_STATUS_ORDERED = ORDER_STATUS[0][0]
ORDER_STATUS_DELIVERED = ORDER_STATUS[1][0]
ORDER_STATUS_CANCELLED = ORDER_STATUS[3][0]
SIZE_CHOICES = (
View
@@ -21,7 +21,9 @@
from meal.factories import ComponentFactory
from order.models import Order, Order_item, MAIN_PRICE_DEFAULT, \
OrderStatusChange, COMPONENT_GROUP_CHOICES_MAIN_DISH, \
ORDER_ITEM_TYPE_CHOICES_COMPONENT
ORDER_ITEM_TYPE_CHOICES_COMPONENT, \
ORDER_STATUS_ORDERED, ORDER_STATUS_DELIVERED, ORDER_STATUS_CANCELLED
from order.factories import OrderFactory
from sous_chef.tests import TestMixin as SousChefTestMixin
@@ -1723,6 +1725,45 @@ def test_generateorders_create_only_if_scheduled_today(self):
len(self.ongoing_clients) - 4
)
def test_setordersdelivered(self):
"""Set status to delivered for orders on a given day"""
delivery_date_str = "2017-12-09"
delivery_date = datetime.datetime.strptime(
delivery_date_str, '%Y-%m-%d').date()
# status should be set to Delivered
OrderFactory(
delivery_date=delivery_date,
status=ORDER_STATUS_ORDERED
)
# status should be set to Delivered
OrderFactory(
delivery_date=delivery_date,
status=ORDER_STATUS_ORDERED
)
orders_to_be_set = 2
# status should NOT be set to Delivered
OrderFactory(
delivery_date=delivery_date,
status=ORDER_STATUS_CANCELLED
)
# status should NOT be set to Delivered
OrderFactory(
delivery_date=datetime.datetime.strptime(
"2017-12-31", '%Y-%m-%d').date(),
status=ORDER_STATUS_ORDERED
)
args = [delivery_date_str]
opts = {}
call_command('setordersdelivered', *args, **opts)
self.assertEqual(
Order.objects.filter(
delivery_date=delivery_date,
status=ORDER_STATUS_DELIVERED).count(),
orders_to_be_set
)
class OrderListViewTestCase(SousChefTestMixin, TestCase):
def test_redirects_users_who_do_not_have_read_permission(self):

0 comments on commit 844ca09

Please sign in to comment.