From 3d53e523892d63170ac19f4c8c5f9c0a8f141ca4 Mon Sep 17 00:00:00 2001 From: Mohit Saini Date: Wed, 24 Apr 2024 00:07:30 +0530 Subject: [PATCH 1/9] Introduces Subtype option and implemented generate report --- .../ps1/migrations/0002_auto_20240423_0459.py | 69 ++++ .../0003_indentfile_item_subtype.py | 18 + FusionIIIT/applications/ps1/models.py | 1 + FusionIIIT/applications/ps1/urls.py | 3 +- FusionIIIT/applications/ps1/views.py | 96 ++++- FusionIIIT/templates/ps1/composeIndent.html | 5 + FusionIIIT/templates/ps1/createdindent.html | 2 +- .../templates/ps1/current_stock_view.html | 2 + .../ps1/current_stock_view_filter.html | 3 + FusionIIIT/templates/ps1/forwardedIndent.html | 2 +- FusionIIIT/templates/ps1/forwardindent.html | 2 +- FusionIIIT/templates/ps1/generate_report.html | 361 +++++------------- .../templates/ps1/generate_report_filter.html | 82 ++++ FusionIIIT/templates/ps1/ps2.html | 11 +- .../templates/ps1/stock_item_details.html | 224 +++++++++++ FusionIIIT/templates/ps1/stock_item_view.html | 17 +- FusionIIIT/templates/ps1/stock_transfer.html | 4 +- FusionIIIT/templates/ps1/view_transfer.html | 2 + 18 files changed, 615 insertions(+), 289 deletions(-) create mode 100644 FusionIIIT/applications/ps1/migrations/0002_auto_20240423_0459.py create mode 100644 FusionIIIT/applications/ps1/migrations/0003_indentfile_item_subtype.py create mode 100644 FusionIIIT/templates/ps1/generate_report_filter.html create mode 100644 FusionIIIT/templates/ps1/stock_item_details.html diff --git a/FusionIIIT/applications/ps1/migrations/0002_auto_20240423_0459.py b/FusionIIIT/applications/ps1/migrations/0002_auto_20240423_0459.py new file mode 100644 index 000000000..43bf897d0 --- /dev/null +++ b/FusionIIIT/applications/ps1/migrations/0002_auto_20240423_0459.py @@ -0,0 +1,69 @@ +# Generated by Django 3.1.5 on 2024-04-23 04:59 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('globals', '0001_initial'), + ('ps1', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='StockItem', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nomenclature', models.CharField(max_length=100, unique=True)), + ('inUse', models.BooleanField(default=True)), + ('location', models.CharField(choices=[('SR1', 'LHTC'), ('SR2', 'Computer Center'), ('SR3', 'Panini Hostel'), ('SR4', 'Lab complex'), ('SR5', 'Admin Block')], default='SR1', max_length=100)), + ('isTransferred', models.BooleanField(default=False)), + ], + options={ + 'db_table': 'StockItem', + }, + ), + migrations.RenameField( + model_name='indentfile', + old_name='indent_type', + new_name='item_type', + ), + migrations.RemoveField( + model_name='stockentry', + name='item_name', + ), + migrations.AddField( + model_name='stockentry', + name='location', + field=models.CharField(choices=[('SR1', 'LHTC'), ('SR2', 'Computer Center'), ('SR3', 'Panini Hostel'), ('SR4', 'Lab complex'), ('SR5', 'Admin Block')], default='SR1', max_length=100), + ), + migrations.CreateModel( + name='StockTransfer', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('src_location', models.CharField(choices=[('SR1', 'LHTC'), ('SR2', 'Computer Center'), ('SR3', 'Panini Hostel'), ('SR4', 'Lab complex'), ('SR5', 'Admin Block')], default='SR1', max_length=100)), + ('dest_location', models.CharField(choices=[('SR1', 'LHTC'), ('SR2', 'Computer Center'), ('SR3', 'Panini Hostel'), ('SR4', 'Lab complex'), ('SR5', 'Admin Block')], default='SR2', max_length=100)), + ('dateTime', models.DateTimeField(default=django.utils.timezone.now)), + ('dest_dept', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='dept_dest_transfers', to='globals.departmentinfo')), + ('indent_file', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ps1.indentfile')), + ('src_dept', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='dept_src_transfers', to='globals.departmentinfo')), + ('stockItem', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ps1.stockitem')), + ], + options={ + 'db_table': 'StockTransfer', + }, + ), + migrations.AddField( + model_name='stockitem', + name='StockEntryId', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ps1.stockentry'), + ), + migrations.AddField( + model_name='stockitem', + name='department', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='globals.departmentinfo'), + ), + ] diff --git a/FusionIIIT/applications/ps1/migrations/0003_indentfile_item_subtype.py b/FusionIIIT/applications/ps1/migrations/0003_indentfile_item_subtype.py new file mode 100644 index 000000000..8e9d97dd1 --- /dev/null +++ b/FusionIIIT/applications/ps1/migrations/0003_indentfile_item_subtype.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.5 on 2024-04-23 05:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ps1', '0002_auto_20240423_0459'), + ] + + operations = [ + migrations.AddField( + model_name='indentfile', + name='item_subtype', + field=models.CharField(default='computers', max_length=250), + ), + ] diff --git a/FusionIIIT/applications/ps1/models.py b/FusionIIIT/applications/ps1/models.py index ffbe50020..b34683836 100644 --- a/FusionIIIT/applications/ps1/models.py +++ b/FusionIIIT/applications/ps1/models.py @@ -16,6 +16,7 @@ class IndentFile(models.Model): purpose=models.CharField(max_length=250,blank=False ) specification=models.CharField(max_length=250) item_type=models.CharField(max_length=250) + item_subtype = models.CharField(max_length=250,blank=False,default='computers') nature=models.BooleanField(default = False) indigenous= models.BooleanField(default = False) replaced =models.BooleanField(default = False) diff --git a/FusionIIIT/applications/ps1/urls.py b/FusionIIIT/applications/ps1/urls.py index 148e0c753..dc0b33bae 100644 --- a/FusionIIIT/applications/ps1/urls.py +++ b/FusionIIIT/applications/ps1/urls.py @@ -68,7 +68,8 @@ url(r'^outboxview/$', views.outboxview, name='outboxview'), - url(r'^update_stock_item_inUse/$', views.updateStockItemInUse, name='outboxview'), + url(r'^update_stock_item_inUse/$', views.updateStockItemInUse, name='stockItemInUse'), + url(r'^item_detail/(?P\d+)/$', views.item_detail, name='item_detail'), # BASE API url(r'^api/',include('applications.ps1.api.urls')), diff --git a/FusionIIIT/applications/ps1/views.py b/FusionIIIT/applications/ps1/views.py index 7efeb869e..465156ef4 100644 --- a/FusionIIIT/applications/ps1/views.py +++ b/FusionIIIT/applications/ps1/views.py @@ -20,6 +20,7 @@ import json from django.db.models import Q,Count +from datetime import datetime dept_admin_to_dept = { "deptadmin_cse": "CSE", @@ -29,9 +30,10 @@ "deptadmin_design": "Design", "deptadmin_liberalarts": "Liberal Arts", "deptadmin_ns": "Natural Science", + "Admin IWD":"IWD" } -dept_admin_design = ["deptadmin_cse", "deptadmin_ece", "deptadmin_me","deptadmin_sm", "deptadmin_design", "deptadmin_liberalarts","deptadmin_ns" ] +dept_admin_design = ["deptadmin_cse", "deptadmin_ece", "deptadmin_me","deptadmin_sm", "deptadmin_design", "deptadmin_liberalarts","deptadmin_ns" ,"Admin IWD"] @login_required(login_url = "/accounts/login/") @@ -118,6 +120,8 @@ def create_proposal(request): purpose=request.POST.get('purpose') specification=request.POST.get('specification') item_type=request.POST.get('item_type') + item_subtype=request.POST.get('item_subtype') + nature=request.POST.get('nature') indigenous=request.POST.get('indigenous') replaced =request.POST.get('replaced') @@ -150,6 +154,7 @@ def create_proposal(request): purpose=purpose, specification=specification, item_type=item_type, + item_subtype=item_subtype, nature=nature, indigenous=indigenous, replaced = replaced , @@ -191,6 +196,8 @@ def create_proposal(request): purpose=request.POST.get('purpose') specification=request.POST.get('specification') item_type=request.POST.get('item_type') + item_subtype=request.POST.get('item_subtype') + nature=request.POST.get('nature') indigenous=request.POST.get('indigenous') replaced =request.POST.get('replaced') @@ -249,6 +256,7 @@ def create_proposal(request): purpose=purpose, specification=specification, item_type=item_type, + item_subtype=item_subtype, nature=nature, indigenous=indigenous, replaced = replaced , @@ -1104,11 +1112,12 @@ def current_stock_view(request): StockEntryId__item_id__item_type=type ) - grouped_items = StockItems.values('StockEntryId__item_id__item_type', 'department').annotate(total_quantity=Count('id')) + grouped_items = StockItems.values('StockEntryId__item_id__item_type','StockEntryId__item_id__item_subtype', 'department').annotate(total_quantity=Count('id')) grouped_items_list = [ { 'item_type': item['StockEntryId__item_id__item_type'], + 'item_subtype': item['StockEntryId__item_id__item_subtype'], 'department': DepartmentInfo.objects.get(id=department), 'total_quantity': item['total_quantity'] } @@ -1118,6 +1127,7 @@ def current_stock_view(request): firstStock=StockItems.first() + print(grouped_items_list) return render(request,'ps1/current_stock_view.html',{'stocks':grouped_items_list,'first_stock':firstStock, @@ -1149,11 +1159,12 @@ def current_stock_view(request): return redirect('/dashboard') - grouped_items = StockItems.values('StockEntryId__item_id__item_type','department').annotate(total_quantity=Count('id')) + grouped_items = StockItems.values('StockEntryId__item_id__item_type','StockEntryId__item_id__item_subtype','department').annotate(total_quantity=Count('id')) grouped_items_list = [ { 'item_type': item['StockEntryId__item_id__item_type'], + 'item_subtype': item['StockEntryId__item_id__item_subtype'], 'department': DepartmentInfo.objects.values('id','name').get(id=item['department']), 'departmentId': item['department'], 'total_quantity': item['total_quantity'] @@ -1178,11 +1189,13 @@ def stock_item_view(request): if request.method=="POST": departmentId = request.POST.get('departmentId') type = request.POST.get('item_type') + subtype = request.POST.get('item_subtype') # StockEntryId__item_id__file_info_grade StockItems = StockItem.objects.filter( department=departmentId, - StockEntryId__item_id__item_type=type + StockEntryId__item_id__item_type=type, + StockEntryId__item_id__item_subtype=subtype ) return render(request,'ps1/stock_item_view.html',{'stocks':StockItems}) @@ -1344,16 +1357,56 @@ def generate_report(request): if request.session['currentDesignationSelected'] not in dept_admin_design + ["ps_admin"]: return redirect('/dashboard') + - des = HoldsDesignation.objects.all().select_related().filter(user = request.user).first() - department = request.user.extrainfo.department.name + if request.method =='GET': + if request.session['currentDesignationSelected'] in dept_admin_design: - if request.session['currentDesignationSelected'] in dept_admin_design: - sto=StockEntry.objects.filter(item_id__file_info__uploader__department__name=dept_admin_to_dept[request.session['currentDesignationSelected']]) - else: - sto=StockEntry.objects.all() + deptId = DepartmentInfo.objects.values('id', 'name').get(name=dept_admin_to_dept[request.session['currentDesignationSelected']]) + departments=[deptId] + + elif request.session['currentDesignationSelected'] == "ps_admin": + departments=DepartmentInfo.objects.values('id','name').all() + + return render(request,'ps1/generate_report_filter.html',{'departments':departments}) - return render(request,'ps1/generate_report.html',{'sto':sto}) + + if request.method=="POST": + + + departments = request.POST.getlist('departments') + start_date = request.POST.get('start_date'); + finish_date = request.POST.get('finish_date'); + + + + start_date = datetime.strptime(start_date, '%Y-%m-%d').date() + finish_date = datetime.strptime(finish_date, '%Y-%m-%d').date() + + if(departments[0]=='all'): + StockItems = StockItem.objects.filter(StockEntryId__recieved_date__range=(start_date, finish_date)) + else : + StockItems = StockItem.objects.filter(department__in=departments, StockEntryId__recieved_date__range=(start_date, finish_date)) + + + grouped_items = StockItems.values('StockEntryId__item_id__item_type','department').annotate(total_quantity=Count('id')) + + grouped_items_list = [ + { + 'item_type': item['StockEntryId__item_id__item_type'], + 'department': DepartmentInfo.objects.values('id','name').get(id=item['department']), + 'departmentId': item['department'], + 'total_quantity': item['total_quantity'], + 'StockItems': StockItem.objects.filter( + department=item['department'], + StockEntryId__item_id__item_type=item['StockEntryId__item_id__item_type'] + ) + } + for item in grouped_items + ] + + + return render(request,'ps1/generate_report.html',{'departments':departments,'stocks':grouped_items_list}) @login_required(login_url = "/accounts/login") @@ -1542,6 +1595,8 @@ def outboxview(request): @login_required(login_url="/accounts/login") def updateStockItemInUse(request): + print("updatestockiteminuse"); + if request.session['currentDesignationSelected'] not in dept_admin_design + ["ps_admin"]: return redirect('/dashboard') @@ -1568,4 +1623,21 @@ def updateStockItemInUse(request): return JsonResponse({'success': True}) - # return HttpResponseRedirect('../current_stock_view') \ No newline at end of file + # return HttpResponseRedirect('../current_stock_view') + + +@login_required(login_url="/accounts/login") +def item_detail(request, id): + if request.session['currentDesignationSelected'] not in dept_admin_design + ["ps_admin"]: + return redirect('/dashboard') + + stock_transfers = StockTransfer.objects.filter(stockItem=id).order_by('dateTime') + stock_item = StockItem.objects.filter(id=id).first(); + # Do something with the stock_transfers + + context = { + 'transfers': stock_transfers, + 'item': stock_item + } + + return render(request, 'ps1/stock_item_details.html', context) diff --git a/FusionIIIT/templates/ps1/composeIndent.html b/FusionIIIT/templates/ps1/composeIndent.html index 8c406a8b6..d71d826e9 100644 --- a/FusionIIIT/templates/ps1/composeIndent.html +++ b/FusionIIIT/templates/ps1/composeIndent.html @@ -80,6 +80,11 @@

+
+ + +
+
diff --git a/FusionIIIT/templates/ps1/createdindent.html b/FusionIIIT/templates/ps1/createdindent.html index dd5c06a75..f88edfeb1 100644 --- a/FusionIIIT/templates/ps1/createdindent.html +++ b/FusionIIIT/templates/ps1/createdindent.html @@ -59,7 +59,7 @@ +
+ + +
+
diff --git a/FusionIIIT/templates/ps1/createdindent.html b/FusionIIIT/templates/ps1/createdindent.html index dd5c06a75..f88edfeb1 100644 --- a/FusionIIIT/templates/ps1/createdindent.html +++ b/FusionIIIT/templates/ps1/createdindent.html @@ -59,7 +59,7 @@