From 5c74b8bc894da1f7b936ff16f6e743b4c46e000e Mon Sep 17 00:00:00 2001 From: Kanha Tiwari Date: Sun, 12 Mar 2023 18:31:35 +0530 Subject: [PATCH 1/5] new db tables has been added to suppport multiple items in same indent --- FusionIIIT/applications/ps1/models.py | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/FusionIIIT/applications/ps1/models.py b/FusionIIIT/applications/ps1/models.py index bee76f36e..f8ecc8ec9 100644 --- a/FusionIIIT/applications/ps1/models.py +++ b/FusionIIIT/applications/ps1/models.py @@ -27,6 +27,47 @@ class IndentFile(models.Model): class Meta: db_table = 'IndentFile' + +class IndentFile2(models.Model): + + file_info = models.OneToOneField( + File, on_delete=models.CASCADE, primary_key=True) + indent_title=models.CharField(max_length=250,blank=False,default="") + budgetary_head = models.CharField(max_length=250) + expected_delivery = models.DateField(blank=False) + sources_of_supply = models.CharField(max_length=250) + head_approval = models.BooleanField(default=False) + director_approval = models.BooleanField(default=False) + financial_approval = models.BooleanField(default=False) + procured = models.BooleanField(default=False) + description = models.CharField(max_length=250,blank=False,default="") + + class Meta: + db_table = 'IndentFile2' + + +class Item(models.Model): + item_id = models.AutoField(primary_key=True) + indent_id = models.ForeignKey( + IndentFile2, on_delete=models.CASCADE, null=True, blank=False) + file_info = models.OneToOneField( + File, on_delete=models.CASCADE) + item_name = models.CharField(max_length=250, blank=False) + quantiy = models.IntegerField(blank=False) + present_stock = models.IntegerField(blank=False) + estimated_cost = models.IntegerField(null=True, blank=False) + purpose = models.CharField(max_length=250, blank=False) + specification = models.CharField(max_length=250) + indent_type = models.CharField(max_length=250) + nature = models.BooleanField(default=False) + indigenous = models.BooleanField(default=False) + replaced = models.BooleanField(default=False) + purchased = models.BooleanField(default=False) + + class Meta: + db_table = 'Item' + + class StockEntry(models.Model): item_id=models.OneToOneField(IndentFile, on_delete=models.CASCADE,primary_key=True) From 860da4f193f50f754de332034b2106bfe571f54f Mon Sep 17 00:00:00 2001 From: Kanha Tiwari Date: Sun, 12 Mar 2023 19:05:13 +0530 Subject: [PATCH 2/5] completed the endpoint for filing multiple item in single indent --- FusionIIIT/applications/ps1/urls.py | 3 +- FusionIIIT/applications/ps1/views.py | 164 ++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 2 deletions(-) diff --git a/FusionIIIT/applications/ps1/urls.py b/FusionIIIT/applications/ps1/urls.py index e8b3ad417..ddc4426e3 100644 --- a/FusionIIIT/applications/ps1/urls.py +++ b/FusionIIIT/applications/ps1/urls.py @@ -24,5 +24,6 @@ url(r'^stock_edit/$', views.stock_edit, name='stock_edit'), url(r'^stock_update/$', views.stock_update, name='stock_update'), url(r'^entry/$', views.entry, name='entry'), - url(r'^stock_login/$', views.dealing_assistant, name='dealing_assistant') + url(r'^stock_login/$', views.dealing_assistant, name='dealing_assistant'), + url(r'^create_indent_multiple/$',views.create_indent_multiple, name='create_indent_multiple') ] diff --git a/FusionIIIT/applications/ps1/views.py b/FusionIIIT/applications/ps1/views.py index 4755149ab..32b9d5456 100644 --- a/FusionIIIT/applications/ps1/views.py +++ b/FusionIIIT/applications/ps1/views.py @@ -1,7 +1,7 @@ from django.contrib import messages from django.shortcuts import render, get_object_or_404, redirect from applications.filetracking.models import File, Tracking -from applications.ps1.models import IndentFile,StockEntry +from applications.ps1.models import IndentFile,StockEntry,IndentFile2,Item from applications.globals.models import ExtraInfo, HoldsDesignation, Designation from django.template.defaulttags import csrf_token from django.http import HttpResponse, HttpResponseRedirect, JsonResponse @@ -11,6 +11,168 @@ from django.contrib.auth.models import User from timeit import default_timer as time from notification.views import office_module_notif +from django.views.decorators.csrf import csrf_exempt +import json + + + +@login_required(login_url = "/accounts/login/") +def create_indent_multiple(request): + """ + The function is used to create indents by faculty. + It adds the indent datails to the IndentFile2 table and Item details to Item table + for tracking the indent we are using filetracking module + @param: + request - trivial. + @variables: + uploader - Employee who creates file. + subject - Title of the file. + description - Description of the file. + upload_file - Attachment uploaded while creating file. + file - The file object. + extrainfo - The Extrainfo object. + holdsdesignations - The HoldsDesignation object. + context - Holds data needed to make necessary changes in the template. + item_name- Name of the item to be procured + quantity - Qunat of the item to be procured + present_stock=request.POST.get('present_stock') + estimated_cost=request.POST.get('estimated_cost') + purpose=request.POST.get('purpose') + specification=request.POST.get('specification') + indent_type=request.POST.get('indent_type') + nature=request.POST.get('nature') + indigenous=request.POST.get('indigenous') + replaced =request.POST.get('replaced') + budgetary_head=request.POST.get('budgetary_head') + expected_delivery=request.POST.get('expected_delivery') + sources_of_supply=request.POST.get('sources_of_supply') + head_approval=False + director_approval=False + financial_approval=False + purchased =request.POST.get('purchased') + items= List of details of all the item + """ + des = HoldsDesignation.objects.all().select_related().filter(user = request.user).first() + if str(des.designation) == "student": + return redirect('/dashboard') + if request.user.extrainfo.id == '132': + return redirect("/purchase-and-store/entry/") + if request.method == 'POST': + try: + uploader = request.user.extrainfo + upload_file = request.FILES.get('myfile') + design = request.POST.get('design') + designation = Designation.objects.get(id = HoldsDesignation.objects.select_related('user','working','designation').get(id = design).designation_id) + description=request.POST.get('desc') + subject=request.POST.get('title') + budgetary_head = request.POST.get('budgetary_head') + sources_of_supply = request.POST.get('sources_of_supply') + expected_delivery = request.POST.get('expected_delivery') + # information related to reciever + remarks = request.POST.get('remarks') + receiver = request.POST.get('receiver') + reciever_designation = request.POST.get('reciever_designation') + # items related information + item_list = json.loads(request.POST.get('items')) # this will contain the list of all the item details + + # First we will create the file for IndentFile table + file=File.objects.create( + uploader=uploader, + description=description, + subject=subject, + designation=designation, + upload_file=upload_file + ) + + # Now we will create Indent Table and add to file + + created_indent_file = IndentFile2.objects.create( + file_info = file, + indent_title = subject, + budgetary_head = budgetary_head, + expected_delivery = expected_delivery, + sources_of_supply = sources_of_supply, + description = description + ) + for i in range(len(item_list)) : + # upload_file = temp[i]['file'] + item_name = item_list[i]["item_name"] + quantiy = item_list[i]["quantiy"] + present_stock = item_list[i]["present_stock"] + estimated_cost = item_list[i]["estimated_cost"] + purpose = item_list[i]["purpose"] + specification = item_list[i]["specification"] + indent_type = item_list[i]["indent_type"] + nature =item_list[i]["nature"] + indigenous = item_list[i]["indigenous"] + replaced = item_list[i]["replaced"] + item_file = request.FILES.get(f"item_file{i}") + file_item=File.objects.create( + uploader=uploader, + description=purpose, + subject=item_name, + designation=designation, + upload_file=item_file + ) + Item.objects.create( + indent_id = created_indent_file, + file_info = file_item, + item_name = item_name, + quantiy = quantiy, + present_stock = present_stock, + estimated_cost = estimated_cost, + purpose = purpose , + specification = specification, + indent_type = indent_type, + nature = nature, + indigenous = indigenous, + replaced = replaced, + ) + + if (receiver is not None) and (reciever_designation is not None): + current_design = HoldsDesignation.objects.select_related('user','working','designation').get(id=design) + try: + receiver_id = User.objects.get(username=receiver) + except Exception as e: + messages.error(request, 'Enter a valid Username') + return redirect('/filetracking/') + try: + receive_design = Designation.objects.get(name=reciever_designation) + except Exception as e: + messages.error(request, 'Enter a valid Designation') + return redirect('/ps1/') + + Tracking.objects.create( + file_id=file, + current_id=uploader, + current_design=current_design, + receive_design=receive_design, + receiver_id=receiver_id, + remarks=remarks, + upload_file=upload_file, + ) + office_module_notif(request.user, receiver_id) + messages.success(request,'Indent Filed Successfully!') + finally: + message = 'File Already taken' + + file = File.objects.select_related('uploader__user','uploader__department','designation').all() + extrainfo = ExtraInfo.objects.select_related('user','department').all() + holdsdesignations = HoldsDesignation.objects.select_related('user','working','designation').all() + designations = HoldsDesignation.objects.select_related('user','working','designation').filter(user = request.user) + + context = { + 'file': file, + 'extrainfo': extrainfo, + 'holdsdesignations': holdsdesignations, + 'designations': designations, + } + return render(request, 'ps1/composeIndentMultiple.html', context) + + + + + @login_required(login_url = "/accounts/login/") def ps1(request): From fddb67c2b3e88ce6dc24d006cb2a1b18855af61d Mon Sep 17 00:00:00 2001 From: Kanha Tiwari Date: Sun, 12 Mar 2023 19:06:59 +0530 Subject: [PATCH 3/5] added new page for filling indent with multiple items --- .../templates/ps1/ComposeIndentMultiple.html | 537 ++++++++++++++++++ FusionIIIT/templates/ps1/composeIndent.html | 27 +- FusionIIIT/templates/ps1/ps1.html | 4 + 3 files changed, 544 insertions(+), 24 deletions(-) create mode 100644 FusionIIIT/templates/ps1/ComposeIndentMultiple.html diff --git a/FusionIIIT/templates/ps1/ComposeIndentMultiple.html b/FusionIIIT/templates/ps1/ComposeIndentMultiple.html new file mode 100644 index 000000000..5336b76f7 --- /dev/null +++ b/FusionIIIT/templates/ps1/ComposeIndentMultiple.html @@ -0,0 +1,537 @@ +{% extends 'ps1/ps1.html' %} {% load static %} {% block filetracking_tab %} +{% comment %}the compounder prescription tab starts here {% endcomment %} + + +{% comment %}the ambulance schedule tab starts here {% endcomment %} +
+
+
+ {% csrf_token %} + +
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+ + + + + + + + + + + + + + + + + + +
Item NameQuantity & StocksPurpose & SpecificationFileActions
+
+ Add Item +
+
+
+ +
+ + + +
+ +
+
+ +
+ +
+ +
+ +
+ +
+ + +
+ + + +
+
+ +
+
+
+{% comment %}the compounder prescription tab ends here {% endcomment %} + + + + + +{% endblock %} + + \ No newline at end of file diff --git a/FusionIIIT/templates/ps1/composeIndent.html b/FusionIIIT/templates/ps1/composeIndent.html index 864010cf6..216a64b38 100644 --- a/FusionIIIT/templates/ps1/composeIndent.html +++ b/FusionIIIT/templates/ps1/composeIndent.html @@ -150,11 +150,7 @@
Replaced*

-
-
- Add More -
-
+
@@ -164,19 +160,7 @@
Replaced*
- - - - - -
-
@@ -206,8 +190,8 @@
Replaced*
-
- +
+