diff --git a/FusionIIIT/applications/central_mess/migrations/0003_auto_20250209_1736.py b/FusionIIIT/applications/central_mess/migrations/0003_auto_20250209_1736.py index 181e0e991..18d9402d6 100644 --- a/FusionIIIT/applications/central_mess/migrations/0003_auto_20250209_1736.py +++ b/FusionIIIT/applications/central_mess/migrations/0003_auto_20250209_1736.py @@ -15,4 +15,4 @@ class Migration(migrations.Migration): name='img', field=models.ImageField(default=None, upload_to='mess/images/registration_request/%Y/%m/%d/'), ), - ] + ] \ No newline at end of file diff --git a/FusionIIIT/applications/filetracking/api/views.py b/FusionIIIT/applications/filetracking/api/views.py index 2eb442d29..0cd178741 100644 --- a/FusionIIIT/applications/filetracking/api/views.py +++ b/FusionIIIT/applications/filetracking/api/views.py @@ -68,7 +68,7 @@ def post(self, request): class ViewFileView(APIView): authentication_classes = [TokenAuthentication] permission_classes = [permissions.IsAuthenticated] - + def get(self, request, file_id): try: file_details = view_file(int(file_id)) diff --git a/FusionIIIT/applications/online_cms/migrations/0001_initial.py b/FusionIIIT/applications/online_cms/migrations/0001_initial.py index 23293a797..2688a9059 100644 --- a/FusionIIIT/applications/online_cms/migrations/0001_initial.py +++ b/FusionIIIT/applications/online_cms/migrations/0001_initial.py @@ -272,4 +272,4 @@ class Migration(migrations.Migration): ('student_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='academic_information.student')), ], ), - ] + ] \ No newline at end of file diff --git a/FusionIIIT/applications/online_cms/migrations/0003_auto_20250402_1850.py b/FusionIIIT/applications/online_cms/migrations/0003_auto_20250402_1850.py index ea1705e51..a5c61bf0b 100644 --- a/FusionIIIT/applications/online_cms/migrations/0003_auto_20250402_1850.py +++ b/FusionIIIT/applications/online_cms/migrations/0003_auto_20250402_1850.py @@ -29,4 +29,4 @@ class Migration(migrations.Migration): name='verified', field=models.BooleanField(default=False), ), - ] + ] \ No newline at end of file diff --git a/FusionIIIT/applications/ps1/api/urls.py b/FusionIIIT/applications/ps1/api/urls.py index f15f69bab..9624d2a4b 100644 --- a/FusionIIIT/applications/ps1/api/urls.py +++ b/FusionIIIT/applications/ps1/api/urls.py @@ -67,4 +67,5 @@ path('archieveview//', views.archieveview, name='archievedview'), path('outboxview2//', views.outboxview2, name='outboxview2'), path('stockEntry//', views.stockEntry, name='stock-entry'), + path('my-indents//', views.my_indents_view, name='my-indents-view'), ] \ No newline at end of file diff --git a/FusionIIIT/applications/ps1/api/views.py b/FusionIIIT/applications/ps1/api/views.py index c0c308b89..354817c53 100644 --- a/FusionIIIT/applications/ps1/api/views.py +++ b/FusionIIIT/applications/ps1/api/views.py @@ -11,6 +11,7 @@ from notification.views import office_module_notif from django.contrib import messages from django.contrib.auth.models import User +from notification.views import purchase_notif,iwd_notif from applications.filetracking.sdk.methods import * from datetime import datetime from django.http import HttpResponseForbidden,JsonResponse @@ -52,26 +53,6 @@ def getDesignations(request): @api_view(['POST']) @permission_classes([IsAuthenticated]) -# def getOneFiledIndent(request): -# try: -# file_id = request.data.get('file_id') -# # console.log(file_id) -# indent = IndentFile.objects.get(file_info_id=file_id) -# fileinfo = File.objects.get(pk=file_id) -# # console.log(indent) -# serializer = IndentFileSerializer(indent) -# serializer_file = FileSerializer(fileinfo) -# department = request.user.extrainfo.department.name -# return Response({ -# 'indent': serializer.data, -# 'file': serializer_file.data, -# 'department': department -# }, status=status.HTTP_200_OK) -# # return Response(serializer.data, status=status.HTTP_200_OK) -# except IndentFile.DoesNotExist: -# return Response({"error": "Indent not found."}, status=status.HTTP_404_NOT_FOUND) -# except Exception as e: -# return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST) def getOneFiledIndent(request): try: file_id = request.data.get('file_id') @@ -101,6 +82,7 @@ def getOneFiledIndent(request): + @api_view(['POST']) @permission_classes([IsAuthenticated]) def delete_indent(request): @@ -165,7 +147,6 @@ def createDraft(request): file_extra_JSON={"value": 2}, attached_file=upload_file ) - # Create IndentFile object indent_file = IndentFile.objects.create( file_info=get_object_or_404(File, pk=file_id), @@ -199,10 +180,6 @@ def createDraft(request): 'message': 'Indent Filed Successfully!', }, status=status.HTTP_201_CREATED) - # except HoldsDesignation.DoesNotExist: - # return Response({ - # 'error': 'The specified designation does not exist.' - # }, status=status.HTTP_404_NOT_FOUND) except Exception as e: return Response({ @@ -337,7 +314,7 @@ def draftView(request, username): indents = IndentFile.objects.filter(file_info__in=request.user.extrainfo.uploaded_files.all()).select_related('file_info') department = request.user.extrainfo.department.name # print("gaurva") - print(department) + print(department) indent_ids = [indent.file_info for indent in indents] filed_indents = Tracking.objects.filter(file_id__in=indent_ids) filed_indent_ids = [indent.file_id for indent in filed_indents] @@ -427,7 +404,7 @@ def ForwardIndentFile(request, id): print('hdfjaldfalk' , request.data) try: indent = IndentFile.objects.select_related('file_info').get(file_info=id) - file = indent.file_info + file = indent.file_info_id track = Tracking.objects.select_related('file_id__uploader__user','file_id__uploader__department','file_id__designation','current_id__user','current_id__department','current_design__user','current_design__working','current_design__designation','receiver_id','receive_design').filter(file_id=file) except IndentFile.DoesNotExist: return Response({"message": "Indent file does not exist"}, status=status.HTTP_404_NOT_FOUND) @@ -496,6 +473,7 @@ def ForwardIndentFile(request, id): return Response({"message": "Method not allowed"}, status=status.HTTP_405_METHOD_NOT_ALLOWED) + @api_view(['GET']) @permission_classes([IsAuthenticated]) def archieve_file(request,id): @@ -557,6 +535,7 @@ def entry(request,id): except IndentFile.DoesNotExist: return Response({"message": "Corresponding indent file does not exist"}, status=status.HTTP_404_NOT_FOUND) + @api_view(['GET']) @permission_classes([IsAuthenticated]) def stockEntryView(request,id): @@ -954,7 +933,7 @@ def stockEntry(request,username): print("location-",location) try: # temp1 = File.objects.get(id=id) - temp = IndentItem.objects.get(indent_file_id=id) + temp = IndentItem.objects.get(id=id) except (File.DoesNotExist, IndentFile.DoesNotExist): return Response({"message": "File with given ID does not exist"}, status=status.HTTP_404_NOT_FOUND) @@ -987,12 +966,13 @@ def forwardIndent(request, id): try: indent=IndentFile.objects.select_related('file_info').get(file_info=id) file=indent.file_info - + print("file details",file); upload_file = request.FILES.get('file') receiverName = request.data.get('forwardTo') receiver_id = User.objects.get(username=receiverName) receive_design = request.data.get('receiverDesignation') remarks = request.data.get('remarks') + print("remarks",remarks); sender_designation_name = request.data.get('role') # vkjain -> director print(receiver_id) #bhartenduks @@ -1012,20 +992,25 @@ def forwardIndent(request, id): remarks=remarks, file_attachment=upload_file ) - - office_module_notif(request.user, receiver_id) + print("noti",request.user); + print("noti2",receiver_id); + # iwd_notif(request.user, receiver_id, "Request_added") + purchase_notif(request.user,receiver_id) + # office_module_notif(request.user, receiver_id) if((sender_designation_name in ["HOD (CSE)", "HOD (ECE)", "HOD (ME)", "HOD (SM)", "HOD (Design)", "HOD (Liberal Arts)", "HOD (Natural Science)"]) and (str(receive_design) in ["Director","Registrar"])): indent.head_approval=True - elif ((sender_designation_name in ["Director","Registrar"]) and (str(receive_design) in ["Professor","Accounts Admin"]) and indent.purchased==True): + elif ((sender_designation_name in ["Director","Registrar"]) and (str(receive_design) in ["ps_admin"]) ): indent.director_approval=True - indent.financial_approval=True - elif ((sender_designation_name in ["Director","Registrar"]) and (str(receive_design) in ["Professor"]) ): - indent.director_approval=True - elif ((sender_designation_name in ["Professor"]) and (str(receive_design) in ["ps_admin"] )): + elif ((sender_designation_name in ["Professor","Assistant Professor"]) and (str(receive_design) in ["ps_admin"] )): indent.purchased=True - elif ((sender_designation_name in ["ps_admin"]) and str(receive_design) in ["Director","Registrar"]): - indent.head_approval=True + elif ((sender_designation_name in ["Director","Registrar"]) and (str(receive_design) in ["Professor","Accounts Admin","Assistant Professor"]) and indent.purchased==True): + print("financial approval"); indent.director_approval=True + indent.financial_approval=True + + # elif ((sender_designation_name in ["ps_admin"]) and str(receive_design) in ["Director","Registrar"]): + # indent.head_approval=True + # indent.director_approval=True elif ((sender_designation_name == "Accounts Admin") and ((str(receive_design) in dept_admin_design) or str(receive_design) == "ps_admin")): indent.financial_approval=True @@ -1111,8 +1096,7 @@ def createProposal(request): sources_of_supply=item.get('sources_of_supply', ''), ) - # Notify the receiver - office_module_notif(request.user, receiver) + purchase_notif(request.user,receiver) # Auto-approve if receiver is 'ps_admin' if receiver_designation == "ps_admin": @@ -1148,4 +1132,64 @@ def user_suggestions(request): # user = Faculty.objects.all().values('id') # print(users) # print(user) - return JsonResponse({'users': list(users)}) \ No newline at end of file + return JsonResponse({'users': list(users)}) + +@api_view(['GET']) +@permission_classes([IsAuthenticated]) +def my_indents_view(request, username): + try: + # Validate user + user = User.objects.get(username=username) + if user != request.user: + return Response({'error': 'Unauthorized access'}, status=status.HTTP_403_FORBIDDEN) + + # Get all files created by this user + created_files = File.objects.filter(uploader=user.extrainfo).order_by('-upload_date') + + # Get associated indent files + indent_files = IndentFile.objects.filter( + file_info__in=created_files + ).select_related( + 'file_info' + ).prefetch_related( + 'items' + ).order_by('-file_info__upload_date') + + # Serialize the data + data = [] + for indent in indent_files: + # Get last tracking info if exists + tracking = Tracking.objects.filter(file_id=indent.file_info_id).select_related( + 'receiver_id' + ).last() + + indent_data = { + 'id': indent.file_info_id, + 'indent_name': indent.indent_name, + 'description': indent.description, + 'upload_date': indent.file_info.upload_date, + 'status': { + 'head_approval': indent.head_approval, + 'director_approval': indent.director_approval, + 'financial_approval': indent.financial_approval, + 'purchased': indent.purchased + }, + 'current_receiver': tracking.receiver_id.username if tracking else None, + 'items': [{ + 'name': item.item_name, + 'quantity': item.quantity, + 'estimated_cost': item.estimated_cost + } for item in indent.items.all()] + } + data.append(indent_data) + + return Response({ + 'count': len(data), + 'results': data, + 'department': user.extrainfo.department.name + }) + + except User.DoesNotExist: + return Response({'error': 'User not found'}, status=status.HTTP_404_NOT_FOUND) + except Exception as e: + return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file diff --git a/FusionIIIT/applications/ps1/models.py b/FusionIIIT/applications/ps1/models.py index 04cdb0080..6b73e1b30 100644 --- a/FusionIIIT/applications/ps1/models.py +++ b/FusionIIIT/applications/ps1/models.py @@ -14,7 +14,6 @@ class IndentFile(models.Model): director_approval = models.BooleanField(default=False) financial_approval = models.BooleanField(default=False) purchased = models.BooleanField(default=False) - class Meta: db_table = 'IndentFile' @@ -37,7 +36,6 @@ class IndentItem(models.Model): class Meta: db_table = 'IndentItem' - class Constants: Locations = ( ('SR1', 'LHTC'), @@ -112,6 +110,9 @@ def create_stock_items(sender, instance, created, **kwargs): if created: # Automatically create 'n' number of StockItem instances based on current_stock of StockEntry # instance is stockEntry + department = instance.item_id.indent_file.file_info.uploader.department current_stock = int(instance.current_stock) - for _ in range(current_stock): - StockItem.objects.create(StockEntryId=instance,location=instance.location,department=instance.item_id.file_info.uploader.department) \ No newline at end of file + for _ in range(current_stock): + StockItem.objects.create(StockEntryId=instance,location=instance.location,department=department) + # for _ in range(current_stock): + # StockItem.objects.create(StockEntryId=instance,location=instance.location,department=instance.item_id.file_info.uploader.department) \ No newline at end of file diff --git a/FusionIIIT/notification/views.py b/FusionIIIT/notification/views.py index 479d1cf68..314e04e1f 100644 --- a/FusionIIIT/notification/views.py +++ b/FusionIIIT/notification/views.py @@ -714,4 +714,10 @@ def iwd_notif(sender,recipient,type): verb = "Request approved by " + sender.username + "." if type == "Request_rejected": verb = "Request rejected by " + sender.username + "." + notify.send(sender=sender,recipient=recipient,url=url,module=module,verb=verb) + +def purchase_notif(sender,recipient): + module= 'purchase-and-store' + url= 'purchase' + verb="A new Indent Received" notify.send(sender=sender,recipient=recipient,url=url,module=module,verb=verb) \ No newline at end of file