Skip to content

Commit

Permalink
Merge pull request #97 from OfirMatasas/static-orders
Browse files Browse the repository at this point in the history
Create static orders
  • Loading branch information
Omeramsc authored May 19, 2022
2 parents c1051cb + c574dea commit 814a304
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 2 deletions.
184 changes: 184 additions & 0 deletions orders/migrations/0003_static_orders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
from django.db import migrations
from django.utils import timezone
from daycare.models import DayCare
from orders.models import StatusOptions
import datetime


class Migration(migrations.Migration):
dependencies = [
('orders', '0002_test_data'),
('daycare', '0004_static_daycare_users'),
('dogowner', '0004_test_static_data'),
]

def generate_data(apps, schema_editor):
from dogowner.models import DogOwner
from orders.models import Order

all_daycares = DayCare.objects.all()
all_dog_owners = DogOwner.objects.all()

Order.objects.create(daycare_id=all_daycares.get(pk=4), dog_owner_id=all_dog_owners.get(pk=4),
price_per_day=100, start_date=timezone.datetime(2024, 3, 23),
status=StatusOptions.Approved,
end_date=timezone.datetime(2024, 3, 23) + datetime.timedelta(days=7)),
Order.objects.create(daycare_id=all_daycares.get(pk=4), dog_owner_id=all_dog_owners.get(pk=5),
price_per_day=200, start_date=timezone.datetime(2023, 5, 6),
status=StatusOptions.Canceled,
end_date=timezone.datetime(2023, 5, 6) + datetime.timedelta(days=4)),
Order.objects.create(daycare_id=all_daycares.get(pk=5), dog_owner_id=all_dog_owners.get(pk=5),
price_per_day=500, start_date=timezone.datetime(2023, 2, 23),
status=StatusOptions.Canceled,
end_date=timezone.datetime(2023, 2, 23) + datetime.timedelta(days=10)),
Order.objects.create(daycare_id=all_daycares.get(pk=5), dog_owner_id=all_dog_owners.get(pk=6),
price_per_day=200, start_date=timezone.datetime(2023, 6, 7),
status=StatusOptions.Approved,
end_date=timezone.datetime(2023, 6, 7) + datetime.timedelta(days=14)),
Order.objects.create(daycare_id=all_daycares.get(pk=6), dog_owner_id=all_dog_owners.get(pk=6),
price_per_day=100, start_date=timezone.datetime(2023, 7, 15),
status=StatusOptions.Pending,
end_date=timezone.datetime(2023, 7, 15) + datetime.timedelta(days=5)),
Order.objects.create(daycare_id=all_daycares.get(pk=6), dog_owner_id=all_dog_owners.get(pk=7),
price_per_day=200, start_date=timezone.datetime(2024, 1, 20),
status=StatusOptions.Pending,
end_date=timezone.datetime(2024, 1, 20) + datetime.timedelta(days=8)),
Order.objects.create(daycare_id=all_daycares.get(pk=7), dog_owner_id=all_dog_owners.get(pk=7),
price_per_day=100, start_date=timezone.datetime(2023, 6, 6),
status=StatusOptions.Approved,
end_date=timezone.datetime(2023, 6, 6) + datetime.timedelta(days=5)),
Order.objects.create(daycare_id=all_daycares.get(pk=7), dog_owner_id=all_dog_owners.get(pk=8),
price_per_day=200, start_date=timezone.datetime(2024, 5, 6),
status=StatusOptions.Pending,
end_date=timezone.datetime(2024, 5, 6) + datetime.timedelta(days=10)),
Order.objects.create(daycare_id=all_daycares.get(pk=8), dog_owner_id=all_dog_owners.get(pk=8),
price_per_day=100, start_date=timezone.datetime(2023, 4, 20),
status=StatusOptions.Pending,
end_date=timezone.datetime(2023, 4, 20) + datetime.timedelta(days=3)),
Order.objects.create(daycare_id=all_daycares.get(pk=8), dog_owner_id=all_dog_owners.get(pk=9),
price_per_day=200, start_date=timezone.datetime(2023, 3, 30),
status=StatusOptions.Approved,
end_date=timezone.datetime(2023, 3, 30) + datetime.timedelta(days=2)),
Order.objects.create(daycare_id=all_daycares.get(pk=9), dog_owner_id=all_dog_owners.get(pk=9),
price_per_day=100, start_date=timezone.datetime(2022, 7, 3),
status=StatusOptions.Pending,
end_date=timezone.datetime(2022, 7, 3) + datetime.timedelta(days=9)),
Order.objects.create(daycare_id=all_daycares.get(pk=9), dog_owner_id=all_dog_owners.get(pk=10),
price_per_day=200, start_date=timezone.datetime(2022, 10, 10),
status=StatusOptions.Canceled,
end_date=timezone.datetime(2022, 10, 10) + datetime.timedelta(days=6)),
Order.objects.create(daycare_id=all_daycares.get(pk=10), dog_owner_id=all_dog_owners.get(pk=10),
price_per_day=100, start_date=timezone.datetime(2022, 12, 15),
status=StatusOptions.Pending,
end_date=timezone.datetime(2022, 12, 15) + datetime.timedelta(days=6)),
Order.objects.create(daycare_id=all_daycares.get(pk=10), dog_owner_id=all_dog_owners.get(pk=11),
price_per_day=200, start_date=timezone.datetime(2023, 5, 9),
status=StatusOptions.Approved,
end_date=timezone.datetime(2023, 5, 9) + datetime.timedelta(days=2)),
Order.objects.create(daycare_id=all_daycares.get(pk=11), dog_owner_id=all_dog_owners.get(pk=11),
price_per_day=100, start_date=timezone.datetime(2022, 9, 10),
status=StatusOptions.Pending,
end_date=timezone.datetime(2022, 9, 10) + datetime.timedelta(days=5)),
Order.objects.create(daycare_id=all_daycares.get(pk=11), dog_owner_id=all_dog_owners.get(pk=12),
price_per_day=200, start_date=timezone.datetime(2022, 6, 11),
status=StatusOptions.Approved,
end_date=timezone.datetime(2022, 6, 11) + datetime.timedelta(days=4)),
Order.objects.create(daycare_id=all_daycares.get(pk=12), dog_owner_id=all_dog_owners.get(pk=12),
price_per_day=100, start_date=timezone.datetime(2023, 5, 5),
status=StatusOptions.Approved,
end_date=timezone.datetime(2023, 5, 5) + datetime.timedelta(days=7)),
Order.objects.create(daycare_id=all_daycares.get(pk=12), dog_owner_id=all_dog_owners.get(pk=13),
price_per_day=200, start_date=timezone.datetime(2023, 2, 22),
status=StatusOptions.Canceled,
end_date=timezone.datetime(2023, 2, 22) + datetime.timedelta(days=4)),
Order.objects.create(daycare_id=all_daycares.get(pk=13), dog_owner_id=all_dog_owners.get(pk=13),
price_per_day=100, start_date=timezone.datetime(2022, 7, 8),
status=StatusOptions.Pending,
end_date=timezone.datetime(2022, 7, 8) + datetime.timedelta(days=3)),
Order.objects.create(daycare_id=all_daycares.get(pk=13), dog_owner_id=all_dog_owners.get(pk=14),
price_per_day=200, start_date=timezone.datetime(2022, 8, 1),
status=StatusOptions.Approved,
end_date=timezone.datetime(2022, 8, 1) + datetime.timedelta(days=12)),
Order.objects.create(daycare_id=all_daycares.get(pk=14), dog_owner_id=all_dog_owners.get(pk=14),
price_per_day=100, start_date=timezone.datetime(2023, 1, 1),
status=StatusOptions.Pending,
end_date=timezone.datetime(2023, 1, 1) + datetime.timedelta(days=6)),
Order.objects.create(daycare_id=all_daycares.get(pk=14), dog_owner_id=all_dog_owners.get(pk=15),
price_per_day=200, start_date=timezone.datetime(2022, 7, 7),
status=StatusOptions.Canceled,
end_date=timezone.datetime(2022, 7, 7) + datetime.timedelta(days=2)),
Order.objects.create(daycare_id=all_daycares.get(pk=15), dog_owner_id=all_dog_owners.get(pk=15),
price_per_day=100, start_date=timezone.datetime(2022, 7, 20),
status=StatusOptions.Pending,
end_date=timezone.datetime(2022, 7, 20) + datetime.timedelta(days=4)),
Order.objects.create(daycare_id=all_daycares.get(pk=15), dog_owner_id=all_dog_owners.get(pk=16),
price_per_day=200, start_date=timezone.datetime(2022, 8, 27),
status=StatusOptions.Approved,
end_date=timezone.datetime(2022, 8, 27) + datetime.timedelta(days=7)),
Order.objects.create(daycare_id=all_daycares.get(pk=16), dog_owner_id=all_dog_owners.get(pk=16),
price_per_day=100, start_date=timezone.datetime(2023, 1, 15),
status=StatusOptions.Pending,
end_date=timezone.datetime(2023, 1, 15) + datetime.timedelta(days=4)),
Order.objects.create(daycare_id=all_daycares.get(pk=16), dog_owner_id=all_dog_owners.get(pk=17),
price_per_day=200, start_date=timezone.datetime(2022, 12, 8),
status=StatusOptions.Pending,
end_date=timezone.datetime(2022, 12, 8) + datetime.timedelta(days=2)),
Order.objects.create(daycare_id=all_daycares.get(pk=17), dog_owner_id=all_dog_owners.get(pk=17),
price_per_day=100, start_date=timezone.datetime(2022, 9, 23),
status=StatusOptions.Approved,
end_date=timezone.datetime(2022, 9, 23) + datetime.timedelta(days=1)),
Order.objects.create(daycare_id=all_daycares.get(pk=17), dog_owner_id=all_dog_owners.get(pk=18),
price_per_day=200, start_date=timezone.datetime(2022, 11, 12),
status=StatusOptions.Pending,
end_date=timezone.datetime(2022, 11, 12) + datetime.timedelta(days=6)),
Order.objects.create(daycare_id=all_daycares.get(pk=18), dog_owner_id=all_dog_owners.get(pk=18),
price_per_day=100, start_date=timezone.datetime(2022, 9, 8),
status=StatusOptions.Canceled,
end_date=timezone.datetime(2022, 9, 8) + datetime.timedelta(days=5)),
Order.objects.create(daycare_id=all_daycares.get(pk=18), dog_owner_id=all_dog_owners.get(pk=19),
price_per_day=200, start_date=timezone.datetime(2023, 1, 23),
status=StatusOptions.Approved,
end_date=timezone.datetime(2023, 1, 23) + datetime.timedelta(days=5)),
Order.objects.create(daycare_id=all_daycares.get(pk=19), dog_owner_id=all_dog_owners.get(pk=19),
price_per_day=100, start_date=timezone.datetime(2022, 6, 12),
status=StatusOptions.Canceled,
end_date=timezone.datetime(2022, 6, 12) + datetime.timedelta(days=1)),
Order.objects.create(daycare_id=all_daycares.get(pk=19), dog_owner_id=all_dog_owners.get(pk=20),
price_per_day=200, start_date=timezone.datetime(2023, 2, 8),
status=StatusOptions.Approved,
end_date=timezone.datetime(2023, 2, 8) + datetime.timedelta(days=10)),
Order.objects.create(daycare_id=all_daycares.get(pk=20), dog_owner_id=all_dog_owners.get(pk=20),
price_per_day=100, start_date=timezone.datetime(2023, 3, 11),
status=StatusOptions.Pending,
end_date=timezone.datetime(2023, 3, 11) + datetime.timedelta(days=6)),
Order.objects.create(daycare_id=all_daycares.get(pk=20), dog_owner_id=all_dog_owners.get(pk=21),
price_per_day=200, start_date=timezone.datetime(2023, 1, 17),
status=StatusOptions.Pending,
end_date=timezone.datetime(2023, 1, 17) + datetime.timedelta(days=4)),
Order.objects.create(daycare_id=all_daycares.get(pk=21), dog_owner_id=all_dog_owners.get(pk=21),
price_per_day=100, start_date=timezone.datetime(2022, 8, 23),
status=StatusOptions.Approved,
end_date=timezone.datetime(2022, 8, 23) + datetime.timedelta(days=7)),
Order.objects.create(daycare_id=all_daycares.get(pk=21), dog_owner_id=all_dog_owners.get(pk=22),
price_per_day=200, start_date=timezone.datetime(2023, 3, 12),
status=StatusOptions.Approved,
end_date=timezone.datetime(2023, 3, 12) + datetime.timedelta(days=2)),
Order.objects.create(daycare_id=all_daycares.get(pk=22), dog_owner_id=all_dog_owners.get(pk=22),
price_per_day=100, start_date=timezone.datetime(2023, 3, 5),
status=StatusOptions.Pending,
end_date=timezone.datetime(2023, 3, 5) + datetime.timedelta(days=7)),
Order.objects.create(daycare_id=all_daycares.get(pk=22), dog_owner_id=all_dog_owners.get(pk=23),
price_per_day=200, start_date=timezone.datetime(2022, 4, 4),
status=StatusOptions.Canceled,
end_date=timezone.datetime(2022, 4, 4) + datetime.timedelta(days=3)),
Order.objects.create(daycare_id=all_daycares.get(pk=23), dog_owner_id=all_dog_owners.get(pk=23),
price_per_day=100, start_date=timezone.datetime(2023, 5, 15),
status=StatusOptions.Approved,
end_date=timezone.datetime(2023, 5, 15) + datetime.timedelta(days=6)),
Order.objects.create(daycare_id=all_daycares.get(pk=23), dog_owner_id=all_dog_owners.get(pk=4),
price_per_day=200, start_date=timezone.datetime(2023, 5, 5),
end_date=timezone.datetime(2023, 5, 5) + datetime.timedelta(days=8))

operations = [
migrations.RunPython(generate_data),
]
4 changes: 2 additions & 2 deletions orders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def __str__(self):
return f"Dog owner ID: {self.dog_owner_id}, daycare ID: {self.daycare_id}, status: {self.status}"

@classmethod
def create(cls, dog_owner_id, daycare_id, start_date, end_date, price_per_day):
def create(cls, dog_owner_id, daycare_id, start_date, end_date, price_per_day, status=StatusOptions.Pending):
new_order = Order(dog_owner_id=dog_owner_id,
daycare_id=daycare_id,
book_date=timezone.now(),
start_date=start_date,
end_date=end_date,
price_per_day=price_per_day,
status=StatusOptions.Pending
status=status
)

new_order.save()
Expand Down

0 comments on commit 814a304

Please sign in to comment.