Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
RawanAbuleil committed Jan 17, 2023
1 parent 7b85468 commit d7e3128
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion buy_together/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@
path('products/', include('product.urls')),
path('suppliers/', include('supplier.urls')),
path('supplier_product/', include('supplier_product.urls', namespace='supplier_product')),

]
8 changes: 4 additions & 4 deletions supplier_product/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ def setUp(self):
quantity=10
)

def test_increase_quantity(self):
def increase_quantity_by_one(self):
response = self.client.get(
reverse(
'supplier_product:increase_quantity', kwargs={'id': self.supplier_product.supplier_product_id}))
'supplier_product:increase_quantity_by_one', kwargs={'id': self.supplier_product.supplier_product_id}))
updated_product = SupplierProduct.objects.get(supplier_product_id=self.supplier_product.supplier_product_id)
self.assertEqual(updated_product.quantity, self.supplier_product.quantity + 1)
self.assertEqual(response.status_code, 302)

def test_decrease_quantity(self):
def decrease_quantity_by_one(self):
response = self.client.get(
reverse(
'supplier_product:decrease_quantity', kwargs={'id': self.supplier_product.supplier_product_id}))
'supplier_product:decrease_quantity_by_one', kwargs={'id': self.supplier_product.supplier_product_id}))
updated_product = SupplierProduct.objects.get(supplier_product_id=self.supplier_product.supplier_product_id)
self.assertEqual(updated_product.quantity, self.supplier_product.quantity - 1)
self.assertEqual(response.status_code, 302)
4 changes: 2 additions & 2 deletions supplier_product/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

app_name = 'supplier_product'
urlpatterns = [
path('increase_quantity/<int:id>/', views.increase_quantity, name='increase_quantity'),
path('decrease_quantity/<int:id>/', views.decrease_quantity, name='decrease_quantity'),
path('increase_quantity_by_one/<int:id>/', views.increase_quantity, name='increase_quantity'),
path('decrease_quantity_by_one/<int:id>/', views.decrease_quantity, name='decrease_quantity'),
]
4 changes: 2 additions & 2 deletions supplier_product/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db.models import F


def increase_quantity(request, id):
def increase_quantity_by_one(request, id):
SupplierProduct.objects.filter(supplier_product_id=id).update(quantity=F('quantity')+1)
product = SupplierProduct.objects.get(supplier_product_id=id)
context = {'product': product}
Expand All @@ -16,7 +16,7 @@ def increase_quantity(request, id):
return HttpResponse("Template not found")


def decrease_quantity(request, id):
def decrease_quantity_by_one(request, id):
product = SupplierProduct.objects.get(supplier_product_id=id)
if product.quantity > 0:
SupplierProduct.objects.filter(supplier_product_id=id).update(quantity=F('quantity')-1)
Expand Down
4 changes: 2 additions & 2 deletions templates/supplier/suppliers.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<td>{{sup_product.qr_code.product_name}}</td>
<td>{{sup_product.quantity}}</td>
<td>{{sup_product.price}}</td>
<td><form action="{% url 'supplier_product:increase_quantity' id=sup_product.supplier_product_id %}">
<td><form action="{% url 'supplier_product:increase_quantity_by_one' id=sup_product.supplier_product_id %}">
<button type="submit" class="btn btn-primary"> + </button>
</form>
<form action="{% url 'supplier_product:decrease_quantity' id=sup_product.supplier_product_id %}">
<form action="{% url 'supplier_product:decrease_quantity_by_one' id=sup_product.supplier_product_id %}">
<button type="submit" class="btn btn-danger"> - </button>
</form>
</td>
Expand Down

0 comments on commit d7e3128

Please sign in to comment.