Skip to content

Commit

Permalink
Merge pull request #658 from savoirfairelinux/feature/delivered-orders
Browse files Browse the repository at this point in the history
Allow batch order status change
  • Loading branch information
manumilou authored Jan 29, 2017
2 parents a784029 + 8edf128 commit fcbe341
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
File renamed without changes.
42 changes: 40 additions & 2 deletions src/order/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
from django.contrib import admin
from order.models import Order, Order_item, OrderStatusChange

admin.site.register(Order)
admin.site.register(Order_item)

def make_delivered(modeladmin, request, queryset):
queryset.update(status='D')
make_delivered.short_description = "Mark selected orders as delivered"


class OrderItemInline(admin.TabularInline):
model = Order_item


class OrderItemAdmin(admin.ModelAdmin):
search_fields = ['order__id']
list_display = (
'order',
'order_item_type',
'component_group',
'total_quantity',
'billable_flag',
'price',
)


class OrderAdmin(admin.ModelAdmin):
search_fields = ['client__member__lastname', 'client__member__firstname']
list_filter = ('status', 'delivery_date')
list_display = (
'id',
'client',
'status',
'price',
'delivery_date',
'creation_date',
)
actions = [make_delivered]
inlines = [
OrderItemInline
]

admin.site.register(Order, OrderAdmin)
admin.site.register(Order_item, OrderItemAdmin)
admin.site.register(OrderStatusChange)
7 changes: 7 additions & 0 deletions src/order/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ def create_order(self, delivery_date, client, items, prices):

return order

"""
Allow changing status of multiple orders at once.
"""
def update_orders_status(self, orders, new):
count = orders.update(status=new)
return count


class Order(models.Model):

Expand Down
13 changes: 13 additions & 0 deletions src/order/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ def test_get_shippable_orders_active_client_only(self):
new_orders = Order.objects.get_shippable_orders()
self.assertNotEqual(len(self.orders), len(new_orders))

def test_update_orders_status(self):
"""
Should update orders status.
"""
ordered = Order.objects.get_shippable_orders()
ordered_count = len(ordered)
Order.objects.update_orders_status(ordered, 'D')
delivered = Order.objects.filter(
delivery_date=date.today(),
status='D',
)
self.assertEqual(ordered_count, len(delivered))


class OrderItemTestCase(TestCase):

Expand Down

0 comments on commit fcbe341

Please sign in to comment.