Skip to content

Commit

Permalink
Merge branch 'development_1.1' into development_1.1_load_users
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud-Emad committed Feb 8, 2024
2 parents 163c1a8 + f770a3f commit 1f6a8d3
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 271 deletions.
6 changes: 6 additions & 0 deletions client/src/components/CshrToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export default {
setup() {
const $api = useApi()
const user = useAsyncState(() => $api.myprofile.getUser(), null)
setTimeout(() => {
if(!user.state.value){
window.location.href = "/login"
}
}, 1000)
const notifications = useAsyncState(() => $api.notifications.list(), [])
const selectedNotification = ref<Api.Returns.Notification>()
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/cards/vacationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,17 @@ export default {
})
const couldApprove = computed(() => {
if (user.value) {
if (
user.value.fullUser.user_type === 'Admin' ||
user.value.fullUser.user_type === 'Supervisor'
) {
) {
if (props.vacation.user.id == user.value.fullUser.id) {
return true
}
if (
props.vacation.user.reporting_to.includes(user.value.fullUser.id) &&
props.vacation.user.reporting_to[0].id === props.vacation.user?.id &&
props.vacation.user.location.name === user.value.fullUser.location.name
) {
return true
Expand Down
1 change: 0 additions & 1 deletion client/src/components/personalInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<script lang="ts">
import { computed, ref } from 'vue'
import { onMounted } from 'vue'
export default {
name: 'personalInformation',
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/vacationBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default {
name: 'vacationBalance',
props: ['balance'],
setup(props) {
setup() {
const vacationInfoHeaders = ['Annuals', 'Emergencies', 'Excuses']
return {
Expand Down
49 changes: 25 additions & 24 deletions client/src/views/ProfileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<v-col cols="12" sm="12" md="8" class="pa-2 border rounded position-relative ma-2">
<div>
<personalInformation :user="user.state.value" />
<vacationBalance :balance="balance.state.value" v-if="showBalance" />
<!-- v-if="showBalance" -->
<vacationBalance :balance="balance.state.value" />
</div>
</v-col>
</v-row>
Expand Down Expand Up @@ -53,33 +54,33 @@ export default defineComponent({
{ immediate: false }
)
const showBalance = computed(() => {
if (storedUser.value?.fullUser) {
if (
user.state.value &&
storedUser.value?.fullUser &&
user.state.value.id === storedUser.value?.fullUser.id
) {
return true
} else if (storedUser.value?.fullUser && storedUser.value?.fullUser.user_type === 'Admin') {
if (user.state.value.reporting_to) {
if (
user.state.value.reporting_to.includes(storedUser.value?.fullUser.id) &&
user.state.value.location.name === storedUser.value?.fullUser.location.name
) {
return true
}
}
return false
}
}
return false
})
// const showBalance = computed(() => {
// if (storedUser.value?.fullUser) {
// if (
// user.state.value &&
// storedUser.value?.fullUser &&
// user.state.value.id === storedUser.value?.fullUser.id
// ) {
// return true
// } else if (storedUser.value?.fullUser && storedUser.value?.fullUser.user_type === 'Admin') {
// if (user.state.value.reporting_to) {
// if (
// user.state.value.reporting_to.includes(storedUser.value?.fullUser.id) &&
// user.state.value.location.name === storedUser.value?.fullUser.location.name
// ) {
// return true
// }
// }
// return false
// }
// }
// return false
// })
return {
user,
balance,
showBalance,
// showBalance,
vacationBalance,
personalInformation,
profileImage
Expand Down
4 changes: 2 additions & 2 deletions client/src/views/TeamView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export default {
const headers = [
{ title: 'Name', sortable: false, key: 'full_name' },
{ title: 'Email', key: 'email' },
{ title: 'Phone', key: 'phone' },
{ title: 'Position', key: 'position' },
{ title: 'Phone', key: 'mobile_number' },
{ title: 'Position', key: 'job_title' },
{ title: 'Telegram', key: 'telegram_link' },
{ title: 'Department', key: 'team' }
] as any[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.9 on 2024-02-08 10:04

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("cshr", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name="vacation",
name="actual_days",
),
migrations.RemoveField(
model_name="vacationbalance",
name="actual_balance",
),
migrations.AddField(
model_name="vacationbalance",
name="office_vacation_balance",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="cshr.officevacationbalance",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.9 on 2024-02-08 11:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("cshr", "0002_remove_vacation_actual_days_and_more"),
]

operations = [
migrations.RemoveField(
model_name="vacationbalance",
name="office_vacation_balance",
),
migrations.AddField(
model_name="vacation",
name="actual_days",
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name="vacationbalance",
name="actual_balance",
field=models.JSONField(default=dict, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.9 on 2024-02-08 11:17

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("cshr", "0003_remove_vacationbalance_office_vacation_balance_and_more"),
]

operations = [
migrations.RemoveField(
model_name="vacationbalance",
name="actual_balance",
),
migrations.AddField(
model_name="vacationbalance",
name="office_vacation_balance",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="cshr.officevacationbalance",
),
),
]
5 changes: 1 addition & 4 deletions server/cshr/models/vacations.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Vacation(Requests):
end_date = models.DateField()
change_log = models.JSONField(default=list)
actual_days = models.IntegerField(default=0)
# taked_from_old_balance = models.BooleanField(default=False)

def ___str__(self):
return self.reason
Expand All @@ -53,9 +52,7 @@ class VacationBalance(models.Model):
annual_leaves = models.IntegerField()
emergency_leaves = models.IntegerField()
leave_excuses = models.IntegerField()
actual_balance = models.JSONField(default=dict, null=True)
# date = models.DateField(auto_now=True)
# old_balance = models.JSONField(default=dict, null=True)
office_vacation_balance = models.ForeignKey("OfficeVacationBalance", on_delete=models.SET_NULL, null=True)

def __str__(self):
return str(self.user.email)
Expand Down
1 change: 1 addition & 0 deletions server/cshr/serializers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class Meta:
"address",
"location",
"is_active",
"telegram_link",
]

def get_image(self, obj):
Expand Down
25 changes: 12 additions & 13 deletions server/cshr/serializers/vacations.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,49 +189,48 @@ def get_user(self, obj: VacationBalance):
def get_sick_leaves(self, obj: VacationBalance):
"""This method returns the actual user balance values."""
value = {
"reserved": obj.actual_balance.get("sick_leaves") - obj.sick_leaves,
"all": obj.actual_balance.get("sick_leaves"),
"reserved": obj.sick_leaves,
"all": obj.office_vacation_balance.sick_leaves,
}
return UserBalanceVlaueSerializer(value).data

def get_compensation(self, obj: VacationBalance):
"""This method returns the actual user balance values."""
value = {
"reserved": obj.actual_balance.get("compensation") - obj.compensation,
"all": obj.actual_balance.get("compensation"),
"reserved": obj.compensation,
"all": obj.office_vacation_balance.compensation,
}
return UserBalanceVlaueSerializer(value).data

def get_unpaid(self, obj: VacationBalance):
"""This method returns the actual user balance values."""
value = {
"reserved": obj.actual_balance.get("unpaid") - obj.unpaid,
"all": obj.actual_balance.get("unpaid"),
"reserved": obj.unpaid,
"all": obj.office_vacation_balance.unpaid,
}
return UserBalanceVlaueSerializer(value).data

def get_annual_leaves(self, obj: VacationBalance):
"""This method returns the actual user balance values."""
value = {
"reserved": obj.actual_balance.get("annual_leaves") - obj.annual_leaves,
"all": obj.actual_balance.get("annual_leaves"),
"reserved": obj.annual_leaves,
"all": obj.office_vacation_balance.annual_leaves,
}
return UserBalanceVlaueSerializer(value).data

def get_emergency_leaves(self, obj: VacationBalance):
"""This method returns the actual user balance values."""
value = {
"reserved": obj.actual_balance.get("emergency_leaves")
- obj.emergency_leaves,
"all": obj.actual_balance.get("emergency_leaves"),
"reserved": obj.emergency_leaves,
"all": obj.office_vacation_balance.emergency_leaves,
}
return UserBalanceVlaueSerializer(value).data

def get_leave_excuses(self, obj: VacationBalance):
"""This method returns the actual user balance values."""
value = {
"reserved": obj.actual_balance.get("leave_excuses") - obj.leave_excuses,
"all": obj.actual_balance.get("leave_excuses"),
"reserved": obj.leave_excuses,
"all": obj.office_vacation_balance.leave_excuses,
}
return UserBalanceVlaueSerializer(value).data

Expand Down
14 changes: 0 additions & 14 deletions server/cshr/services/vacations.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,6 @@ def filter_user_vacations(user: User) -> Vacation:
return Vacation.objects.filter(applying_user=user).order_by("created_at")


def update_user_actual_balance(user_balance: VacationBalance) -> VacationBalance:
"""Update user actual balance field with the current balance."""
user_balance.actual_balance = {
"annual_leaves": user_balance.annual_leaves,
"sick_leaves": user_balance.sick_leaves,
"compensation": 100,
"unpaid": 100,
"emergency_leaves": user_balance.emergency_leaves,
"leave_excuses": user_balance.leave_excuses,
}
user_balance.save()
return user_balance


def send_vacation_to_calendar(vacation: Vacation) -> Dict[str, Any]:
from cshr.services.landing_page import (
LandingPageClassNameEnum,
Expand Down
Loading

0 comments on commit 1f6a8d3

Please sign in to comment.