From b763d44e97d125aa8be03ce7150eabc7a5e39e06 Mon Sep 17 00:00:00 2001 From: Horilla Date: Wed, 7 Feb 2024 13:00:09 +0530 Subject: [PATCH] [ADD] ASSET: Asset history tracking --- asset/filters.py | 65 +++++ asset/forms.py | 10 +- asset/models.py | 8 + asset/templates/asset/asset_return_form.html | 6 +- .../asset_history/asset_history_filter.html | 115 ++++++++ .../asset_history/asset_history_list.html | 141 +++++++++ .../asset_history/asset_history_nav.html | 159 ++++++++++ .../asset_history_single_view.html | 153 ++++++++++ .../asset_history/asset_history_view.html | 13 + asset/templates/asset_history/group_by.html | 272 ++++++++++++++++++ .../asset_allocation_creation.html | 7 +- asset/urls.py | 15 + asset/views.py | 106 ++++++- templates/sidebar.html | 9 + 14 files changed, 1067 insertions(+), 12 deletions(-) create mode 100644 asset/templates/asset_history/asset_history_filter.html create mode 100644 asset/templates/asset_history/asset_history_list.html create mode 100644 asset/templates/asset_history/asset_history_nav.html create mode 100644 asset/templates/asset_history/asset_history_single_view.html create mode 100644 asset/templates/asset_history/asset_history_view.html create mode 100644 asset/templates/asset_history/group_by.html diff --git a/asset/filters.py b/asset/filters.py index e0da7cb05..82d396af4 100644 --- a/asset/filters.py +++ b/asset/filters.py @@ -230,3 +230,68 @@ class AssetAllocationReGroup: ("assigned_date", "Assigned Date"), ("return_date", "Return Date"), ] + + +class AssetHistoryFilter(CustomFilterSet): + """ + Custom filter set for AssetAssignment instances for filtering in asset history view. + """ + + search = django_filters.CharFilter( + field_name="asset_id__asset_name", lookup_expr="icontains" + ) + returned_assets = django_filters.CharFilter( + field_name="return_status", method="exclude_none" + ) + return_date_gte = django_filters.DateFilter( + field_name="return_date", + lookup_expr="gte", + widget=forms.DateInput(attrs={"type": "date"}), + ) + return_date_lte = django_filters.DateFilter( + field_name="return_date", + lookup_expr="lte", + widget=forms.DateInput(attrs={"type": "date"}), + ) + assigned_date_gte = django_filters.DateFilter( + field_name="assigned_date", + lookup_expr="gte", + widget=forms.DateInput(attrs={"type": "date"}), + ) + assigned_date_lte = django_filters.DateFilter( + field_name="assigned_date", + lookup_expr="lte", + widget=forms.DateInput(attrs={"type": "date"}), + ) + + def exclude_none(self, queryset, name, value): + if value == "True": + queryset = queryset.filter(return_status__isnull=False) + return queryset + + class Meta: + """ + Specifies the model and fields to be used for filtering AssetAllocation instances. + + Attributes: + model (class): The model class AssetAssignment to be filtered. + fields (str): A special value "__all__" to include all fields + of the model in the filter. + """ + + model = AssetAssignment + fields = "__all__" + + +class AssetHistoryReGroup: + """ + Class to keep the field name for group by option + """ + + fields = [ + ("", "Select"), + ("asset_id", "Asset"), + ("assigned_to_employee_id", "Employee"), + ("assigned_date", "Assigned Date"), + ("return_date", "Return Date"), + ] diff --git a/asset/forms.py b/asset/forms.py index 958741503..b3a7fb902 100644 --- a/asset/forms.py +++ b/asset/forms.py @@ -11,6 +11,7 @@ from django import forms from base.forms import ModelForm from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ +from employee.forms import MultipleFileField from employee.models import Employee from asset.models import Asset, AssetDocuments, AssetReport, AssetRequest, AssetAssignment, AssetCategory, AssetLot from base.methods import reload_queryset @@ -255,6 +256,9 @@ class AssetAllocationForm(ModelForm): self.fields["asset_id"].queryset = Asset.objects.filter( asset_status="Available" ) + + self.fields["assign_images"] = MultipleFileField() + self.fields["assign_images"].required = True class Meta: """ @@ -269,7 +273,7 @@ class AssetAllocationForm(ModelForm): model = AssetAssignment fields = "__all__" - exclude = ["return_date", "return_condition", "assigned_date"] + exclude = ["return_date", "return_condition", "assigned_date", "return_images"] widgets = { "asset_id": forms.Select(attrs={"class": "oh-select oh-select-2 "}), "assigned_to_employee_id": forms.Select( @@ -300,7 +304,7 @@ class AssetReturnForm(ModelForm): """ model = AssetAssignment - fields = ["return_date", "return_condition", "return_status"] + fields = ["return_date", "return_condition", "return_status", "return_images"] widgets = { "return_date": forms.DateInput( attrs={"type": "date", "class": "oh-input w-100", "required": "true"} @@ -324,6 +328,8 @@ class AssetReturnForm(ModelForm): super(AssetReturnForm, self).__init__(*args, **kwargs) self.fields["return_date"].initial = date.today() + self.fields["return_images"] = MultipleFileField(label="Images") + self.fields["return_images"].required = True def clean_return_date(self): return_date = self.cleaned_data.get("return_date") diff --git a/asset/models.py b/asset/models.py index 4dd818a00..3be96c83c 100644 --- a/asset/models.py +++ b/asset/models.py @@ -103,6 +103,9 @@ class AssetDocuments(models.Model): return f'document for {self.asset_report}' +class ReturnImages(models.Model): + image = models.FileField(upload_to="asset/return_images/", blank=True, null=True) + class AssetAssignment(models.Model): """ Represents the allocation and return of assets to and from employees. @@ -130,6 +133,11 @@ class AssetAssignment(models.Model): ) return_request = models.BooleanField(default = False) objects = HorillaCompanyManager("asset_id__asset_lot_number_id__company_id") + return_images = models.ManyToManyField(ReturnImages,blank=True,related_name="return_images") + assign_images = models.ManyToManyField(ReturnImages,blank=True,related_name="assign_images") + + def __str__(self): + return f"{self.assigned_to_employee_id} --- {self.asset_id} --- {self.return_status}" class AssetRequest(models.Model): diff --git a/asset/templates/asset/asset_return_form.html b/asset/templates/asset/asset_return_form.html index d410b9cf6..5518e8c5a 100644 --- a/asset/templates/asset/asset_return_form.html +++ b/asset/templates/asset/asset_return_form.html @@ -1,6 +1,6 @@ {% load i18n %}
{% trans "Asset Return Form" %}
-
+ {% csrf_token %}
@@ -16,6 +16,10 @@ {{asset_return_form.return_condition}}
+
+ + {{asset_return_form.return_images}} +
+ + diff --git a/asset/templates/asset_history/asset_history_list.html b/asset/templates/asset_history/asset_history_list.html new file mode 100644 index 000000000..61b774b04 --- /dev/null +++ b/asset/templates/asset_history/asset_history_list.html @@ -0,0 +1,141 @@ +{% load i18n %} +{% load static %} +{% load basefilters %} +{% include 'filter_tags.html' %} +
+
+
+
+
+
{% trans "Asset" %}
+
{% trans "Employee" %}
+
{% trans "Assigned Date" %}
+
{% trans "Returned Date" %}
+
{% trans "Return Status" %}
+
+
+
+ {% for asset_assignement in asset_assignments %} +
+
+
+
+ +
+ {{asset_assignement.asset_id}} +
+
+
+ {{asset_assignement.assigned_to_employee_id}} +
+
{{asset_assignement.assigned_date}}
+
{{asset_assignement.return_date}}
+
{{asset_assignement.return_status}}
+ +
+ {% endfor %} +
+
+
+
+ + {% trans "Page" %} {{ asset_assignments.number }} {% trans "of" %} {{ asset_assignments.paginator.num_pages }}. + + +
+
+ + + + + + \ No newline at end of file diff --git a/asset/templates/asset_history/asset_history_nav.html b/asset/templates/asset_history/asset_history_nav.html new file mode 100644 index 000000000..6d27714a4 --- /dev/null +++ b/asset/templates/asset_history/asset_history_nav.html @@ -0,0 +1,159 @@ + +{% load i18n %} +{% load basefilters %} +{% if perms.attendance.add_attendanceovertime or request.user|is_reportingmanager %} + +
+{% endif %} + + +
+ +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ +
diff --git a/asset/templates/asset_history/asset_history_single_view.html b/asset/templates/asset_history/asset_history_single_view.html new file mode 100644 index 000000000..7338566c2 --- /dev/null +++ b/asset/templates/asset_history/asset_history_single_view.html @@ -0,0 +1,153 @@ +{% load static %} {% load i18n %} +{% comment %}
+ + + +
{% endcomment %} + + +
+
+ Mary Magdalene +
+
+ {{asset_assignment.asset_id}} + + {{asset_assignment.asset_id.asset_category_id}} +
+
+
+ +
+
+ {% trans "Allocated User" %} + {{asset_assignment.assigned_to_employee_id}} +
+
+ {% trans "Returned Status" %} + + {{asset_assignment.return_status}} +
+
+ +
+
+ {% trans "Allocated Date" %} + + {{asset_assignment.assigned_date}} +
+
+ {% trans "Returned Date" %} + + {{asset_assignment.return_date}} +
+
+
+
+ {% trans "Asset" %} + {{asset_assignment.asset_id}} +
+
+ {% trans "Return Description" %} +
+ {{asset_assignment.return_condition}} +
+
+
+ +
+
+ {% trans "Assign Condition Images" %} + +
+ {% for doc in asset_assignment.assign_images.all %} + + {% endfor %} +
+
+
+
+ {% trans "Return Condition Images" %} +
+
+ {% for doc in asset_assignment.return_images.all %} + + {% endfor %} +
+ +
+
+
+
+ diff --git a/asset/templates/asset_history/asset_history_view.html b/asset/templates/asset_history/asset_history_view.html new file mode 100644 index 000000000..9170bfb01 --- /dev/null +++ b/asset/templates/asset_history/asset_history_view.html @@ -0,0 +1,13 @@ +{% extends 'index.html' %}{% block content %} +{% load static %}{% load i18n %} +{% include 'asset_history/asset_history_nav.html' %} + + + +
+ {% include 'asset_history/asset_history_list.html' %} +
+ +{% endblock %} diff --git a/asset/templates/asset_history/group_by.html b/asset/templates/asset_history/group_by.html new file mode 100644 index 000000000..1069592ac --- /dev/null +++ b/asset/templates/asset_history/group_by.html @@ -0,0 +1,272 @@ +{% load attendancefilters %} {% load basefilters %} {% load static %} +{% load i18n %} {% include 'filter_tags.html' %} +
+ {% for asset_history_list in asset_assignments %} +
+
+
+ +
+ + {{asset_history_list.list|length}} + + {{asset_history_list.grouper}} +
+
+
+
+
+
+
+
+
+
+ {% trans "Asset" %} +
+
+ {% trans "Employee" %} +
+
+ {% trans "Assigned Date" %} +
+
+ {% trans "Returned Date" %} +
+
+ {% trans "Return Status" %} +
+
+
+
+ {% for asset_assignement in asset_history_list.list %} +
+
+
+
+ +
+ {{asset_assignement.asset_id}} +
+
+
+ {{asset_assignement.assigned_to_employee_id}} +
+
+ {{asset_assignement.assigned_date}} +
+
+ {{asset_assignement.return_date}} +
+
+ {{asset_assignement.return_status}} +
+
+ {% endfor %} +
+
+
+
+ +
+ + {% trans "Page" %} {{ asset_history_list.list.number }} + {%trans "of" %} {{asset_history_list.list.paginator.num_pages }}. + + +
+
+
+
+ {% endfor %} +
+ + {% trans "Page" %} {{ asset_assignments.number }} {% trans "of" %} + {{ asset_assignments.paginator.num_pages }}. + + +
+
+ + diff --git a/asset/templates/request_allocation/asset_allocation_creation.html b/asset/templates/request_allocation/asset_allocation_creation.html index 3b77d8ce9..d3d5568fa 100644 --- a/asset/templates/request_allocation/asset_allocation_creation.html +++ b/asset/templates/request_allocation/asset_allocation_creation.html @@ -1,6 +1,6 @@ {% load i18n %}
{% trans "Asset Allocation" %}
-
+ {% csrf_token %}
@@ -18,6 +18,11 @@ {{asset_allocation_form.assigned_by_employee_id}} {{asset_allocation_form.assigned_by_employee_id.errors}}
+
+ + {{asset_allocation_form.assign_images}} + {{asset_allocation_form.assign_images.errors}} +