From 0dd614db7ad09679cf4fbf85f83b8ff669b79ba0 Mon Sep 17 00:00:00 2001 From: Horilla Date: Thu, 28 Mar 2024 10:03:31 +0530 Subject: [PATCH] [UPDT] PAYROLL: Comment section updation in reimbursement,leave and bonus encashment request and updation with multiple file uploading comment both card and list view --- payroll/forms/forms.py | 46 ++++- payroll/models/models.py | 11 ++ .../payroll/reimbursement/filter.html | 2 +- .../reimbursement/reimbursement_comment.html | 175 ++++++++++++++++++ .../reimbursement/reimbursement_list.html | 81 ++++---- .../payroll/reimbursement/request_cards.html | 125 +++---------- .../reimbursement/view_reimbursement.html | 47 ++++- payroll/urls/urls.py | 5 + payroll/views/views.py | 143 ++++++++++---- 9 files changed, 446 insertions(+), 189 deletions(-) create mode 100644 payroll/templates/payroll/reimbursement/reimbursement_comment.html diff --git a/payroll/forms/forms.py b/payroll/forms/forms.py index a0194a9ef..65f89774b 100644 --- a/payroll/forms/forms.py +++ b/payroll/forms/forms.py @@ -3,17 +3,20 @@ forms.py """ from datetime import date +from typing import Any from django import forms from django.forms import widgets from django.utils.translation import gettext_lazy as trans from django.template.loader import render_to_string from base import thread_local_middleware from base.forms import Form +from employee.forms import MultipleFileField from employee.models import Employee from payroll.context_processors import get_active_employees from payroll.models.models import ( EncashmentGeneralSettings, PayrollGeneralSetting, + ReimbursementFile, ReimbursementrequestComment, WorkRecord, ) @@ -176,7 +179,48 @@ class ReimbursementRequestCommentForm(ModelForm): model = ReimbursementrequestComment fields = ("comment",) - exclude = ["is_active"] + + +class reimbursementCommentForm(ModelForm): + """ + Reimbursement request comment model form + """ + + verbose_name = "Add Comment" + + class Meta: + model = ReimbursementrequestComment + fields = "__all__" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["files"] = MultipleFileField(label="files") + self.fields["files"].required = False + + def as_p(self): + """ + Render the form fields as HTML table rows with Bootstrap styling. + """ + context = {"form": self} + table_html = render_to_string("common_form.html", context) + return table_html + + def save(self, commit: bool = ...) -> Any: + multiple_files_ids = [] + files = None + if self.files.getlist("files"): + files = self.files.getlist("files") + self.instance.attachemnt = files[0] + multiple_files_ids = [] + for attachemnt in files: + file_instance = ReimbursementFile() + file_instance.file = attachemnt + file_instance.save() + multiple_files_ids.append(file_instance.pk) + instance = super().save(commit) + if commit: + instance.files.add(*multiple_files_ids) + return instance, files class EncashmentGeneralSettingsForm(ModelForm): diff --git a/payroll/models/models.py b/payroll/models/models.py index 88d6420f6..5bfaec7b4 100644 --- a/payroll/models/models.py +++ b/payroll/models/models.py @@ -1757,6 +1757,11 @@ except: pass +class ReimbursementFile(models.Model): + file = models.FileField(upload_to="payroll/request_files") + objects = models.Manager() + + class ReimbursementrequestComment(HorillaModel): """ ReimbursementRequestComment Model @@ -1765,6 +1770,12 @@ class ReimbursementrequestComment(HorillaModel): request_id = models.ForeignKey(Reimbursement, on_delete=models.CASCADE) employee_id = models.ForeignKey(Employee, on_delete=models.CASCADE) comment = models.TextField(null=True, verbose_name=_("Comment"), max_length=255) + files = models.ManyToManyField(ReimbursementFile, blank=True) + created_at = models.DateTimeField( + auto_now_add=True, + verbose_name=_("Created At"), + null=True, + ) def __str__(self) -> str: return f"{self.comment}" diff --git a/payroll/templates/payroll/reimbursement/filter.html b/payroll/templates/payroll/reimbursement/filter.html index 79cc8e7f9..1bd54451d 100644 --- a/payroll/templates/payroll/reimbursement/filter.html +++ b/payroll/templates/payroll/reimbursement/filter.html @@ -1,7 +1,7 @@ {% load i18n %}
-
+ #enlargeImageContainer { + position: absolute; + left: -300px; + top: 100px; + height: 200px; + width: 200px; + } + + +{% if messages %} +
+ {% for message in messages %} +
{{ message }}
+ {% endfor %} +
+ +{% endif %} + +
+ + + + {% trans "Comments" %} +
+ +
+ {% csrf_token %} + +
+ + +
+ + +
+ + +{% if comments %} +
    + {% for comment in comments %} +
  1. + {{ comment.comment }} + + + + +
    + {% for file in comment.files.all %} + + {% endfor %} + +
    + {% csrf_token %} + + + +
    +
    + + {% trans 'by' %} + + {{ comment.employee_id.get_full_name }} @ {{comment.request_id.employee_id.get_full_name }} + {% trans "'s reimbursement request" %} + +
    +
    +
    +
  2. + + {% endfor %} +
+{% else %} +
+
+
+ {% trans "There are no comments to show." %} + +
+
+
+{% endif %} + + + + + + + \ No newline at end of file diff --git a/payroll/templates/payroll/reimbursement/reimbursement_list.html b/payroll/templates/payroll/reimbursement/reimbursement_list.html index 6ebd83f52..a122aaa97 100644 --- a/payroll/templates/payroll/reimbursement/reimbursement_list.html +++ b/payroll/templates/payroll/reimbursement/reimbursement_list.html @@ -110,6 +110,7 @@ > {% trans "Description" %}
+
{% trans "Comment" %}
{% trans "Actions" %}
{% trans "Confirmation" %}
@@ -159,6 +160,12 @@
{{req.description}} +
+
+
@@ -394,6 +401,7 @@ > {% trans "Description" %}
+
{% trans "Comment" %}
{% trans "Actions" %}
{% trans "Confirmation" %}
@@ -438,7 +446,7 @@
@@ -455,7 +463,14 @@
{{req.description}} -
+ +
+ +
+
{% if perms.payroll.change_reimbursement or request.user %} @@ -684,6 +699,7 @@ > {% trans "Description" %}
+
{% trans "Comment" %}
{% trans "Actions" %}
{% trans "Confirmation" %}
@@ -728,7 +744,7 @@
@@ -739,7 +755,13 @@
{{req.description}} -
+ +
+ +
{% if perms.payroll.change_reimbursement or request.user %} @@ -908,55 +930,16 @@
+ - -