Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visitors Hostel #1647

Draft
wants to merge 16 commits into
base: dashboard_client
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions FusionIIIT/applications/visitor_hostel/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from rest_framework import serializers
from applications.visitor_hostel.models import Inventory, InventoryBill

class InventorySerializer(serializers.ModelSerializer):
class Meta:
model = Inventory
fields = ['item_name', 'quantity', 'consumable']

class InventoryBillSerializer(serializers.ModelSerializer):
class Meta:
model = InventoryBill
fields = ['item_name', 'bill_number', 'cost']
class InventoryItemSerializer(serializers.ModelSerializer):
class Meta:
model = Inventory
fields = ['item_name', 'quantity']
50 changes: 50 additions & 0 deletions FusionIIIT/applications/visitor_hostel/api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from applications.visitor_hostel.models import Inventory, InventoryBill
from .serializers import InventorySerializer, InventoryBillSerializer, InventoryItemSerializer
from rest_framework.generics import ListAPIView
class AddToInventory(APIView):
def post(self, request):
# Extract data from request
item_name = request.data.get('item_name')
bill_number = request.data.get('bill_number')
quantity = request.data.get('quantity')
cost = request.data.get('cost')
consumable = request.data.get('consumable')

# Validate and save Inventory item
inventory_data = {
'item_name': item_name,
'quantity': quantity,
'consumable': consumable,
}
inventory_serializer = InventorySerializer(data=inventory_data)

if inventory_serializer.is_valid():
inventory_item = Inventory.objects.filter(item_name=item_name).first()
if inventory_item:
inventory_item.quantity = quantity
inventory_item.consumable = consumable
inventory_item.save()
else:
inventory_item = inventory_serializer.save()

# Save InventoryBill
bill_data = {
'item_name': inventory_item.id, # Link to inventory item
'bill_number': bill_number,
'cost': cost,
}
bill_serializer = InventoryBillSerializer(data=bill_data)
if bill_serializer.is_valid():
bill_serializer.save()
return Response({"message": "Item added successfully!"}, status=status.HTTP_201_CREATED)
else:
return Response(bill_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
else:
return Response(inventory_serializer.errors, status=status.HTTP_400_BAD_REQUEST)

class InventoryListView(ListAPIView):
queryset = Inventory.objects.all()
serializer_class = InventorySerializer
1 change: 1 addition & 0 deletions FusionIIIT/applications/visitor_hostel/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

class VisitorHostelConfig(AppConfig):
name = 'applications.visitor_hostel'

31 changes: 31 additions & 0 deletions FusionIIIT/applications/visitor_hostel/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from rest_framework import serializers
from .models import Inventory, InventoryBill
from .models import BookingDetail, Bill

class InventorySerializer(serializers.ModelSerializer):
class Meta:
model = Inventory
fields = '__all__'

class InventoryBillSerializer(serializers.ModelSerializer):
class Meta:
model = InventoryBill
fields = '__all__'

class BillSerializer(serializers.ModelSerializer):
total_bill = serializers.SerializerMethodField()

class Meta:
model = Bill
fields = ['id', 'booking', 'meal_bill', 'room_bill', 'payment_status', 'bill_date', 'total_bill']

def get_total_bill(self, obj):
return obj.meal_bill + obj.room_bill

class BookingDetailSerializer(serializers.ModelSerializer):
intender_name = serializers.CharField(source='intender.username') # Assuming User model has a username field
bill = BillSerializer()

class Meta:
model = BookingDetail
fields = ['intender_name', 'booking_from', 'booking_to', 'bill']
31 changes: 31 additions & 0 deletions FusionIIIT/applications/visitor_hostel/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf.urls import url
from applications.visitor_hostel.api.views import AddToInventory, InventoryListView

from . import views

Expand All @@ -9,6 +10,8 @@
url(r'^$', views.visitorhostel, name='visitorhostel'),
url(r'^get-booking-requests/', views.get_booking_requests, name='get_booking_requests'),
url(r'^get-active-bookings/', views.get_active_bookings, name='get_active_bookings'),
url(r'^get-inactive-bookings/', views.get_inactive_bookings, name='get_inactive_bookings'),
url(r'^get-completed-bookings/', views.get_completed_bookings, name='get_completed_bookings'),
url(r'^get-booking-form/', views.get_booking_form, name='get_booking_form'),
url(r'^request-booking/' , views.request_booking , name ='request_booking'),
url(r'^confirm-booking/' , views.confirm_booking , name ='confirm_booking'),
Expand All @@ -23,9 +26,37 @@

url(r'^bill_between_date_range/', views.bill_between_dates, name = 'generate_records'),
url(r'^room-availability/', views.room_availabity, name = 'room_availabity'),
url(r'^room_availabity_new/', views.room_availabity_new, name = 'room_availabity_new'),

url(r'^check-partial-booking/', views.check_partial_booking, name='check_partial_booking'),


url(r'^add-to-inventory/', views.add_to_inventory, name = 'add_to_inventory'),
url(r'^update-inventory/', views.update_inventory, name = 'update_inventory'),
url(r'^edit-room-status/', views.edit_room_status, name = 'edit_room_status'),
url(r'^booking-details/', views.booking_details, name = 'booking_details'),
url(r'^forward-booking/', views.forward_booking, name = 'forward_booking'),
url(r'^intenders/', views.get_intenders, name='get_intenders'), #
url(r'^user-details/', views.get_user_details, name='get_user_details'), #
url(r'^get-booking-details/(?P<booking_id>\d+)/$', views.get_booking_details, name='get_booking_details'), #
url(r'^forward-booking-new/$', views.forward_booking_new, name='forward_booking_new'),

url(r'^confirm-booking-new/$', views.confirm_booking_new, name='confirm_booking_new'), #

url(r'^inventory/$', views.get_inventory_items, name='get_inventory_items'),
url(r'^inventory/(?P<pk>\d+)/$', views.get_inventory_item, name='get_inventory_item'),
url(r'^inventory-bills/$', views.get_inventory_bills, name='get_inventory_bills'),
url(r'^inventory-bills/(?P<pk>\d+)/$', views.get_inventory_bill, name='get_inventory_bill'),

url(r'^accounts-income/$', views.get_all_bills, name='get_all_bills'),
url(r'^accounts-income/(?P<pk>\d+)/$', views.get_bills_id, name='get_bills_id'),

# url(r'^confirm-booking-new/$', views.confirm_booking_new, name='confirm_booking_new'), #
#api
url('api/inventory_add/', AddToInventory.as_view(), name='add-to-inventory'),
url('api/inventory_list/', InventoryListView.as_view(), name='inventory-list'),
# completed bookings
url(r'^completed-bookings/', views.completed_bookings, name='completed_bookings'),

]

Loading