Skip to content

Commit

Permalink
Merge pull request #36 from CSUF-Computer-Science/dev
Browse files Browse the repository at this point in the history
Remove inventory items
  • Loading branch information
KernelPop authored Oct 27, 2018
2 parents 2c98c01 + ff65f91 commit 4ca7270
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sporkify/backend/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from backend.models import Inventory


class AddItemForm(ModelForm):
class InventoryForm(ModelForm):
class Meta:
model = Inventory
fields = ["product_code", "selling_site", "vendor", "condition", "pur_price", "ask_price", "product_type",
Expand Down
2 changes: 1 addition & 1 deletion sporkify/backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Product_Type(models.Model):
brand = models.CharField(max_length=75)

def __str__(self):
return type_name
return self.type_name

class Employee(models.Model):
# or emp_ID = models.CharField(max_length = 20, primary_key = true, unique=true)
Expand Down
4 changes: 2 additions & 2 deletions sporkify/frontend/templates/inventory.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
<td>{{item.time_added}}</td>
<td><button>Edit Item</button></td>
<td>
<form action="" method="POST">{% csrf_token %}
<input type="hidden" name="productCode" value="{{item.product_code}}" />
<form action="/delete-item/" method="POST">{% csrf_token %}
<input type="hidden" id="product_code" name="product_code" value="{{item.product_code}}" />
<button type="submit" name="deleteItem">Delete Item</button>
</form>
</td>
Expand Down
23 changes: 21 additions & 2 deletions sporkify/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from backend.models import Product_Type
from backend.models import Condition

from backend.forms import AddItemForm
from backend.forms import InventoryForm


@login_required
Expand Down Expand Up @@ -81,7 +81,7 @@ def employee(request):
@login_required
def inventory(request):
if request.method == 'POST':
entry = AddItemForm(request.POST)
entry = InventoryForm(request.POST)
if entry.is_valid():
entry.save()
return render(request, 'inventory.html', {
Expand All @@ -95,6 +95,25 @@ def inventory(request):
})


@login_required
def delete_inventory(request):
if request.method == 'POST':
form = Inventory()
inventory = Inventory.objects.all()
item_id = request.POST.get('product_code')
item = Inventory.objects.get(product_code=item_id)
item.delete()
return render(request, 'inventory.html', {
"items": Inventory.objects.all(),
"vendors": Vendor.objects.all(),
"channels": Sale_Site.objects.all(),
"employee": Employee.objects.all(),
"shift": Shift.objects.all(),
"product_types": Product_Type.objects.all(),
"conditions": Condition.objects.all()
})


@login_required
def reports(request):
if request.method == 'POST':
Expand Down
1 change: 1 addition & 0 deletions sporkify/sporkify/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
urlpatterns = [
path('', views.inventory),
path('add-item/', views.inventory),
path('delete-item/', views.delete_inventory),
path('admin/', admin.site.urls),
path('dashboard/', views.dashboard),
path('employees/', views.employee),
Expand Down

0 comments on commit 4ca7270

Please sign in to comment.