Skip to content

Commit

Permalink
Vacation production version (fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Heibert committed Nov 5, 2024
1 parent c951b5a commit 53473e0
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 221 deletions.
2 changes: 1 addition & 1 deletion INSIGHTSAPI/payslip/templates/payslip.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
alt="logo-cyc"
src="data:image/png;base64,{{ logo }}"
width="200px"
/>
/>

<table width="100%">
<thead>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.8 on 2024-11-05 11:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('vacation', '0021_vacationrequest_user_job_position'),
]

operations = [
migrations.AlterField(
model_name='vacationrequest',
name='sat_is_working',
field=models.BooleanField(),
),
]
6 changes: 3 additions & 3 deletions INSIGHTSAPI/vacation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from notifications.utils import create_notification
from users.models import User
from vacation.utils import get_return_date
from vacation.utils import get_return_date, get_working_days


class VacationRequest(models.Model):
Expand All @@ -20,7 +20,7 @@ class VacationRequest(models.Model):
)
start_date = models.DateField()
end_date = models.DateField()
sat_is_working = models.BooleanField(default=True)
sat_is_working = models.BooleanField()
boss_is_approved = models.BooleanField(null=True, blank=True)
boss_approved_at = models.DateTimeField(null=True, blank=True)
manager_is_approved = models.BooleanField(null=True, blank=True)
Expand Down Expand Up @@ -58,7 +58,7 @@ class Meta:
@property
def duration(self):
"""Return the duration of the vacation request."""
return (self.end_date - self.start_date).days
return get_working_days(self.start_date, self.end_date, self.sat_is_working)

@property
def return_date(self):
Expand Down
28 changes: 21 additions & 7 deletions INSIGHTSAPI/vacation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from rest_framework import serializers

from hierarchy.models import JobPosition

from .models import VacationRequest
from .utils import get_working_days, is_working_day

Expand Down Expand Up @@ -32,14 +34,19 @@ class Meta:
"hr_approved_at",
"payroll_is_approved",
"payroll_approved_at",
"sat_is_working",
"status",
"comment",
"user_job_position",
]
read_only_fields = [
"boss_approved_at",
"manager_approved_at",
"hr_approved_at",
"payroll_approved_at",
"created_at",
"user",
"user_job_position",
]

def to_representation(self, instance):
Expand All @@ -50,6 +57,7 @@ def to_representation(self, instance):
data.pop("manager_approved_at")
data.pop("hr_approved_at")
data.pop("payroll_approved_at")
data.pop("user_job_position")
return data

def validate(self, attrs):
Expand All @@ -59,32 +67,32 @@ def validate(self, attrs):
# Creation
created_at = datetime.now()
request = self.context["request"]
if request.data.get("mon_to_sat") is None:
if request.data.get("sat_is_working") is None:
raise serializers.ValidationError(
"Debes especificar si trabajas los sábados."
)
else:
try:
mon_to_sat = bool(strtobool(request.data["mon_to_sat"]))
sat_is_working = bool(strtobool(request.data["sat_is_working"]))
except ValueError:
raise serializers.ValidationError(
"Debes especificar si trabajas los sábados o no."
)
if not is_working_day(attrs["start_date"], mon_to_sat):
if not is_working_day(attrs["start_date"], sat_is_working):
raise serializers.ValidationError(
"No puedes iniciar tus vacaciones un día no laboral."
)
if not is_working_day(attrs["end_date"], mon_to_sat):
if not is_working_day(attrs["end_date"], sat_is_working):
raise serializers.ValidationError(
"No puedes terminar tus vacaciones un día no laboral."
)
if request.data["mon_to_sat"] == True:
if request.data["sat_is_working"] == True:
if attrs["start_date"].weekday() == 5:
raise serializers.ValidationError(
"No puedes iniciar tus vacaciones un sábado."
)
if (
get_working_days(attrs["start_date"], attrs["end_date"], mon_to_sat)
get_working_days(attrs["start_date"], attrs["end_date"], sat_is_working)
> 15
):
raise serializers.ValidationError(
Expand Down Expand Up @@ -126,11 +134,17 @@ def validate(self, attrs):

def create(self, validated_data):
"""Create the vacation request."""
# Remove the is_approved fields from the validated data
# Remove the is_approved fields from the validated data (security check)
validated_data.pop("boss_is_approved", None)
validated_data.pop("manager_is_approved", None)
validated_data.pop("hr_is_approved", None)
validated_data.pop("payroll_is_approved", None)
# Add the user job position to the validated data
job_position = JobPosition.objects.get(
id=validated_data["user"].job_position_id
)
validated_data["user_job_position"] = job_position
# Create the vacation request
vacation_request = super().create(validated_data)
return vacation_request

Expand Down
141 changes: 84 additions & 57 deletions INSIGHTSAPI/vacation/templates/vacation_request.html
Original file line number Diff line number Diff line change
@@ -1,67 +1,94 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Solicitud de Vacaciones</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.header {
text-align: right;
margin-bottom: 20px;
}
.content {
margin-bottom: 20px;
}
.signature {
margin-top: 40px;
}
.signature-line {
border-bottom: 1px solid #000;
width: 200px;
height: 20px;
margin-bottom: 5px;
}
</style>
</head>
<body>
<div class="header">
<p>Fecha de envío de la solicitud: {{ fecha_solicitud }}</p>
</div>

<div class="content">
<p>Estimado(a) {{ nombre_destinatario }},</p>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Solicitud de Vacaciones</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.8;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
height: 1330px;
/* Fixed height for PDF */
font-size: 18px;
position: relative;
/* Make the body a containing block */
}

<p>
Mediante la presente carta, yo, {{ nombre_solicitante }} identificado(a) con la cédula de ciudadanía {{ numero_cedula }} y ocupando el cargo en la empresa de {{
cargo_empresa }}, me permito solicitar {{ dias_vacaciones }} días de vacaciones, que corresponden al período del año {{ año }}.
</p>
.header {
text-align: right;
margin-bottom: 20px;
}

<p>
Me remito con respeto a mi jefe inmediato {{ nombre_jefe_inmediato }} para informar que los días para este periodo serán a partir del {{ fecha_inicio_vacaciones
}} hasta el día {{ fecha_fin_vacaciones }}, para retomar a mis labores el día {{ fecha_retorno_trabajo }}.
</p>
.signature {
margin-top: 60px;
}

<p>
Decido notificar mi solicitud con antelación con el fin de realizar los cambios o acuerdos correspondientes para el normal funcionamiento de las actividades
empresariales en mi ausencia.
</p>
.content {
position: absolute;
/* Absolute positioning */
top: 50%;
/* Move to the middle of the container */
left: 50%;
transform: translate(-50%, -50%);
/* Center it by adjusting */
width: 100%;
/* Ensure the content takes full width */
max-width: 800px;
}

<p>Quedo agradecido(a) ante su pronta respuesta.</p>
</div>
.content p {
margin-bottom: 35px;
font-size: 20px;
}

.centered-image {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0.1;
width: 100%;
max-width: 800px;
}
</style>
</head>

<body>
<img class="centered-image" alt="Logo de la empresa C&C SERVICES S.A.S"
src="data:image/png;base64,{{ company_logo }}" />

<div class="header">
<p>{{ vacation.created_at|date }}</p>
</div>

<div class="content">
<p>
Por la presente yo, <strong>{{ vacation.user }}</strong>, identificado(a) con la cédula de ciudadanía
<strong>{{ vacation.user.cedula }}</strong>, y desempeñando
el cargo de <strong>{{ vacation.user_job_position }}</strong> en la empresa, me permito solicitar <strong>{{ vacation.duration }}</strong> días de vacaciones.
</p>

<p>
Los días solicitados serán a partir del <strong>{{ vacation.start_date }}</strong> hasta el <strong>{{ vacation.end_date }}</strong>, y retomaré mis labores el
<strong>{{ vacation.return_date }}</strong>.
</p>

<p>Notifico con antelación mi solicitud para que se realicen los ajustes o acuerdos necesarios para el normal
funcionamiento de las actividades en mi ausencia.</p>

<p>Agradezco de antemano su pronta respuesta.</p>
<div class="signature">
<p>Atentamente:</p>
<div class="signature-line"></div>
<p>{{ nombre_solicitante }}</p>
<p>C.C {{ numero_cedula }}</p>
<p>Atentamente,</p>
<p>{{ vacation.user }}</p>
<p>C.C {{ vacation.user.cedula }}</p>
</div>
</body>
</html>
</div>
</body>

</html>
Loading

0 comments on commit 53473e0

Please sign in to comment.