From eb5258b0532b18bc3245cc3391f5de817d734cd7 Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 16 Jan 2024 14:21:53 +0530 Subject: [PATCH] [ADD] LEAVE: Comment section for leave allocation request and its group view --- leave/admin.py | 2 + leave/forms.py | 15 +++ leave/models.py | 18 ++++ .../allocation_request_comment_form.html | 27 ++++++ .../comment_view.html | 56 +++++++++++ .../leave_allocation_request_group_by.html | 34 +++++++ .../leave_allocation_request_list.html | 85 +++++++++++++++- leave/urls.py | 16 ++++ leave/views.py | 96 +++++++++++++++++++ 9 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 leave/templates/leave/leave_allocation_request/allocation_request_comment_form.html create mode 100644 leave/templates/leave/leave_allocation_request/comment_view.html diff --git a/leave/admin.py b/leave/admin.py index 794c48d12..d4396c3c7 100644 --- a/leave/admin.py +++ b/leave/admin.py @@ -11,6 +11,7 @@ from .models import ( Holiday, CompanyLeave, LeaveAllocationRequest, + LeaveallocationrequestComment, LeaverequestComment, ) @@ -24,3 +25,4 @@ admin.site.register(CompanyLeave) admin.site.register(LeaveAllocationRequest) admin.site.register(LeaveRequestConditionApproval) admin.site.register(LeaverequestComment) +admin.site.register(LeaveallocationrequestComment) diff --git a/leave/forms.py b/leave/forms.py index cee862d4d..aeda8d9c5 100644 --- a/leave/forms.py +++ b/leave/forms.py @@ -19,6 +19,7 @@ from .models import ( Holiday, CompanyLeave, LeaveAllocationRequest, + LeaveallocationrequestComment, LeaverequestComment, ) from .methods import ( @@ -806,3 +807,17 @@ class LeaverequestcommentForm(ModelForm): model = LeaverequestComment fields = ('comment',) + + +class LeaveallocationrequestcommentForm(ModelForm): + """ + Leave Allocation Requestcomment form + """ + + class Meta: + """ + Meta class for additional options + """ + + model = LeaveallocationrequestComment + fields = ('comment',) diff --git a/leave/models.py b/leave/models.py index 233a760ba..c9bc8b8ad 100644 --- a/leave/models.py +++ b/leave/models.py @@ -695,6 +695,24 @@ class LeaveAllocationRequest(models.Model): super().save(*args, **kwargs) +class LeaveallocationrequestComment(models.Model): + """ + LeaveallocationrequestComment Model + """ + + request_id = models.ForeignKey(LeaveAllocationRequest, on_delete=models.CASCADE) + employee_id = models.ForeignKey(Employee, on_delete=models.CASCADE) + comment = models.TextField(null=True, verbose_name=_("Comment")) + created_at = models.DateTimeField( + auto_now_add=True, + verbose_name=_("Created At"), + null=True, + ) + + def __str__(self) -> str: + return f"{self.comment}" + + class LeaveRequestConditionApproval(models.Model): sequence = models.IntegerField() is_approved = models.BooleanField(default=False) diff --git a/leave/templates/leave/leave_allocation_request/allocation_request_comment_form.html b/leave/templates/leave/leave_allocation_request/allocation_request_comment_form.html new file mode 100644 index 000000000..6aa3b0918 --- /dev/null +++ b/leave/templates/leave/leave_allocation_request/allocation_request_comment_form.html @@ -0,0 +1,27 @@ +{% load i18n %} +{% if form.errors %} + +
+
+ {% for error in form.non_field_errors %} +
+ {{ error }} +
+ {% endfor %} +
+
+{% endif %} +
+ {% csrf_token %} + {{form.as_p}} + +
\ No newline at end of file diff --git a/leave/templates/leave/leave_allocation_request/comment_view.html b/leave/templates/leave/leave_allocation_request/comment_view.html new file mode 100644 index 000000000..efd6f3e70 --- /dev/null +++ b/leave/templates/leave/leave_allocation_request/comment_view.html @@ -0,0 +1,56 @@ +{% load basefilters %} +{% load i18n %} + +{% if no_comments %} + +
+
+
+ {% trans "There is no comments to show." %} + +
+
+
+ +{% else %} + + {% for comment in comments %} +
+
+
+ {% trans "Comment" %} + + + +
+ {{comment.comment}} +
+
+
+
+
+
+
+ {% trans "By" %} + + {{ comment.employee_id }} +
+
+ {% trans "Date & Time" %} + + {% trans "on" %}  {{ comment.created_at|date:"F j, Y" }}   + {% trans "at" %}   {{ comment.created_at|time:"g:i A" }} + +
+ +
+
+
+ + + {% endfor %} + +{% endif %} + + diff --git a/leave/templates/leave/leave_allocation_request/leave_allocation_request_group_by.html b/leave/templates/leave/leave_allocation_request/leave_allocation_request_group_by.html index eecc97427..6ef92cb6f 100644 --- a/leave/templates/leave/leave_allocation_request/leave_allocation_request_group_by.html +++ b/leave/templates/leave/leave_allocation_request/leave_allocation_request_group_by.html @@ -35,6 +35,7 @@
{% trans "Created By" %}
{% trans "Status" %}
{% trans "Description" %}
+
{% trans "Comment" %}
{% trans "Actions" %}
@@ -68,6 +69,22 @@
{{leave_allocation_request.created_by}}
{{leave_allocation_request.get_status_display}}
{{ leave_allocation_request.description}}
+ +
+
+ + + +
+
+
{% if leave_allocation_request.status == 'requested' %} @@ -196,6 +213,7 @@
{% trans "Created By" %}
{% trans "Status" %}
{% trans "Description" %}
+
{% trans "Comment" %}
{% trans "Actions" %}
{% trans "Options" %}
@@ -230,6 +248,22 @@
{{leave_allocation_request.created_by}}
{{leave_allocation_request.get_status_display}}
{{ leave_allocation_request.description}}
+ +
+
+ + + +
+
+
{% if leave_allocation_request.status == 'requested' %} diff --git a/leave/templates/leave/leave_allocation_request/leave_allocation_request_list.html b/leave/templates/leave/leave_allocation_request/leave_allocation_request_list.html index d2a16d376..9c10a5c45 100644 --- a/leave/templates/leave/leave_allocation_request/leave_allocation_request_list.html +++ b/leave/templates/leave/leave_allocation_request/leave_allocation_request_list.html @@ -16,6 +16,7 @@
{% trans "Created By" %}
{% trans "Status" %}
{% trans "Description" %}
+
{% trans "Comment" %}
{% trans "Actions" %}
@@ -49,6 +50,22 @@
{{leave_allocation_request.created_by}}
{{leave_allocation_request.get_status_display}}
{{ leave_allocation_request.description}}
+ +
+
+ + + +
+
+
{% if leave_allocation_request.status == 'requested' %} @@ -154,6 +171,7 @@
{% trans "Created By" %}
{% trans "Status" %}
{% trans "Description" %}
+
{% trans "Comment" %}
{% trans "Actions" %}
{% trans "Options" %}
@@ -188,6 +206,22 @@
{{leave_allocation_request.created_by}}
{{leave_allocation_request.get_status_display}}
{{ leave_allocation_request.description}}
+ +
+
+ + + +
+
+
{% if leave_allocation_request.status == 'requested' %} @@ -315,7 +349,56 @@
{% endif %}
- + + + + + + + + ") + return render( + request, + "leave/leave_allocation_request/allocation_request_comment_form.html", + { + "form": form, "request_id":leave_id + }, + ) + + +@login_required +def view_allocationrequest_comment(request, leave_id): + """ + This method is used to show Allocation request comments + """ + comments = LeaveallocationrequestComment.objects.filter(request_id=leave_id).order_by('-created_at') + no_comments = False + if not comments.exists(): + no_comments = True + + return render( + request, + "leave/leave_allocation_request/comment_view.html", + {"comments": comments, 'no_comments': no_comments } + ) + + +@login_required +def delete_allocationrequest_comment(request, comment_id): + """ + This method is used to delete Allocation request comments + """ + LeaveallocationrequestComment.objects.get(id=comment_id).delete() + + messages.success(request, _("Comment deleted successfully!")) + return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))