Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Created June 6, 2016 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/dcf83bbff15231200029f68ecb740d4e to your computer and use it in GitHub Desktop.
Save sivabudh/dcf83bbff15231200029f68ecb740d4e to your computer and use it in GitHub Desktop.
# run this command.
# echo 'import script_data_pKwan' | python manage.py shell_plus
import datetime
from apps.franchises.models import Franchise
from apps.orders.models import Order
print ""
all_order_count_shop = 0
all_order_count_factory = 0
all_franchises = Franchise.objects.prefetch_related('shop_set', 'factory_set').all()
for franchise in all_franchises:
# Franchise Summary
shop_count = franchise.shop_set.count()
factory_count = franchise.factory_set.count()
all_shop_factory = shop_count + factory_count
if franchise.productcategory_set.count() == 1:
print franchise.name, ",Type : Repair Only,", "Count : ", all_shop_factory
else:
print franchise.name, ",Type : Car Care,", "Count : ", all_shop_factory
start_date = datetime.datetime.strptime("1 Nov 15", "%d %b %y")
end_date = datetime.datetime.strptime("15 Feb 16", "%d %b %y")
# Shop Summary
print " Shop count : ", shop_count
for shop_value in franchise.shop_set.prefetch_related('orders').all():
orders = shop_value.orders.prefetch_related("order_items").filter(created_at__gte=start_date, created_at__lte=end_date)
shop_type = "Demo"
if shop_value.is_production:
shop_type = "Production"
print " ", shop_value.name, ",Type :", shop_type, ",Order Count:", orders.count()
all_order_count_shop += orders.count()
# Factory Summary
print " Factory count : ", factory_count
start_date = datetime.datetime.strptime("1 Nov 15", "%d %b %y")
end_date = datetime.datetime.strptime("15 Feb 16", "%d %b %y")
for factory in franchise.factory_set.prefetch_related("factory_bookings").all():
order_set = set()
for factory_booking in factory.factory_bookings.all():
try:
order = Order.objects.filter(pk=factory_booking.order.pk, created_at__gte=start_date, created_at__lte=end_date).first()
except:
pass
if order:
order_set.add(factory_booking.order)
factory_type = "Demo"
if factory.is_production:
factory_type = "Production"
print " ", factory.name, ",Type :", factory_type, ",Order Count: ", len(order_set)
all_order_count_factory += len(order_set)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment