Skip to content

Commit

Permalink
feat(products): decrement product
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamad-liyaghi committed Aug 9, 2024
1 parent 53a73ca commit c24e725
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions apps/orders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def create_order(cls, user: settings.AUTH_USER_MODEL, cart: dict) -> QuerySet:

with transaction.atomic():
OrderItem.objects.bulk_create(order_items)

for item in order_items:
item.product.quantity -= item.quantity
item.product.save()

for order in orders.values():
order.save()

Expand Down
2 changes: 1 addition & 1 deletion apps/products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_queryset(self):
restaurant = self._get_restaurant()
return Product.objects.select_related("restaurant", "restaurant__owner").filter(
restaurant=restaurant, is_deleted=False
) # TODO: make this single query
)

def _get_restaurant(self, for_creation=False):
if not for_creation:
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ COPY . /src/
WORKDIR /src

EXPOSE 8000
# TODO: This Dockerfile is shit, clean it up

0 comments on commit c24e725

Please sign in to comment.