Skip to content

Commit

Permalink
add generator for order_number
Browse files Browse the repository at this point in the history
  • Loading branch information
juliana-str committed Dec 29, 2023
1 parent ad4e6ec commit f9fedce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/api/orders_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)
from .products_views import STATUS_200_RESPONSE_ON_DELETE_IN_DOCS
from core.loggers import logger
from good_food.utils import generate_order_number
from orders.models import Delivery, Order, OrderProduct, ShoppingCart
from orders.shopping_carts import ShopCart
from products.models import Product
Expand Down Expand Up @@ -352,7 +353,7 @@ def create(self, request, *args, **kwargs):
quantity=prod["quantity"],
order=order,
)
order.order_number = order.id
order.order_number = generate_order_number()
order.save()
shopping_cart.clear()
response_serializer = (
Expand Down
14 changes: 14 additions & 0 deletions backend/good_food/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import random

from django.utils import timezone

LENGTH = 6


def generate_order_number():
"""
Generates random ID.
"""
time = str(timezone.localdate())
random_int = random.randrange(100000, 1000000)
return str(time) + '-' + str(random_int)

0 comments on commit f9fedce

Please sign in to comment.