Skip to content

Commit

Permalink
Add employment certification bonuses field and related changes in mod…
Browse files Browse the repository at this point in the history
…els, migrations, serializers, views, and URLs
  • Loading branch information
Heibert committed Apr 9, 2024
1 parent 8fe7ccf commit 2182f58
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-04-09 10:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('employment_management', '0002_alter_employmentcertification_options'),
]

operations = [
migrations.AddField(
model_name='employmentcertification',
name='bonuses',
field=models.DecimalField(decimal_places=2, max_digits=10, null=True, verbose_name='Bonificaciones'),
),
]
3 changes: 3 additions & 0 deletions INSIGHTSAPI/employment_management/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class EmploymentCertification(models.Model):
salary = models.DecimalField(
max_digits=10, decimal_places=2, verbose_name="Salario"
)
bonuses = models.DecimalField(
max_digits=10, decimal_places=2, null=True, verbose_name="Bonificaciones"
)
contract_type = models.CharField(max_length=100, verbose_name="Tipo de contrato")
expedition_city = models.CharField(
max_length=100, verbose_name="Ciudad de expedición"
Expand Down
12 changes: 12 additions & 0 deletions INSIGHTSAPI/employment_management/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""This module contains the serializers for the employment_management app. """

from rest_framework import serializers
from .models import EmploymentCertification


class EmploymentCertificationSerializer(serializers.ModelSerializer):
"""Employment certification serializer."""

class Meta:
model = EmploymentCertification
fields = "__all__"
7 changes: 6 additions & 1 deletion INSIGHTSAPI/employment_management/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import path
from .views import send_employment_certification, upload_old_certifications
from .views import send_employment_certification, upload_old_certifications, get_employment_certifications

urlpatterns = [
path(
Expand All @@ -12,4 +12,9 @@
upload_old_certifications,
name="upload-old-certifications",
),
path(
"get-employment-certifications/",
get_employment_certifications,
name="get-employment-certifications",
),
]
11 changes: 11 additions & 0 deletions INSIGHTSAPI/employment_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@
from services.emails import send_email
from users.models import User
from .models import EmploymentCertification
from .serializers import EmploymentCertificationSerializer


logger = logging.getLogger("requests")


@api_view(["GET"])
@permission_classes([IsAuthenticated])
def get_employment_certifications(request):
"""Retrieve all employment certifications."""
certifications = EmploymentCertification.objects.all()
serializer = EmploymentCertificationSerializer(certifications, many=True)
return Response(serializer.data)

def read_and_encode_image(file_path):
"""Read an image and encode it to base64."""
if os.path.exists(file_path):
Expand Down Expand Up @@ -68,6 +77,7 @@ def create_employment_certification(request):
"""Create an employment certification."""
identification = request.data.get("identification") or request.user.cedula
months = request.data.get("months")
bonus_amount = None
if months:
months = int(months)
# Get the last X bonus in the payslips
Expand Down Expand Up @@ -139,6 +149,7 @@ def create_employment_certification(request):
start_date=employee[0],
position=employee_info["position"],
salary=employee[2],
bonuses=bonus_amount,
contract_type=employee_info["contract_type"],
expedition_city=employee_info["expedition_city"],
)
Expand Down
6 changes: 2 additions & 4 deletions INSIGHTSAPI/excels_processing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ def call_transfer_list(request):
else:
return Response({"error": "Invalid campaign"}, status=400)

search_path = path_old.format(date=date)
if not os.path.commonpath([search_path, paths[f"{campaign}_old"]]) == paths[
f"{campaign}_old"
]:
search_path = os.path.normpath(path_old.format(date=date))
if not search_path.startswith(paths[f"{campaign}_old"]):
return Response({"error": "Invalid folder path"}, status=400)
if not os.path.exists(search_path):
return Response(
Expand Down
6 changes: 3 additions & 3 deletions INSIGHTSAPI/payslip/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class Payslip(models.Model):
days = models.IntegerField()
biweekly_period = models.DecimalField(max_digits=12, decimal_places=2)
transport_allowance = models.DecimalField(max_digits=12, decimal_places=2)
night_shift_allowance = models.DecimalField(max_digits=12, decimal_places=2)
night_shift_overtime_hours = models.DecimalField(max_digits=12, decimal_places=2)
night_shift_holiday_hours = models.DecimalField(max_digits=12, decimal_places=2)
# night_shift_allowance = models.DecimalField(max_digits=12, decimal_places=2)
# night_shift_overtime_hours = models.DecimalField(max_digits=12, decimal_places=2)
# night_shift_holiday_hours = models.DecimalField(max_digits=12, decimal_places=2)

bonus_paycheck = models.DecimalField(max_digits=12, decimal_places=2)
biannual_bonus = models.DecimalField(max_digits=12, decimal_places=2)
Expand Down
17 changes: 17 additions & 0 deletions INSIGHTSAPI/users/migrations/0022_alter_user_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.0.2 on 2024-04-09 10:28

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('users', '0021_alter_user_last_name_alter_user_username'),
]

operations = [
migrations.AlterModelOptions(
name='user',
options={'permissions': [('upload_robinson_list', 'Can upload robinson list')]},
),
]

0 comments on commit 2182f58

Please sign in to comment.