Fix: Employee things were not working
This commit is contained in:
parent
26c412e169
commit
0fd84135dd
@ -19,12 +19,12 @@ class Fingerprint:
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, insert_default=uuid.uuid4)
|
||||
employee_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("employees.id"), nullable=False)
|
||||
date_: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
date_: Mapped[datetime] = mapped_column("date", DateTime, nullable=False)
|
||||
|
||||
employee: Mapped["Employee"] = relationship("Employee", back_populates="fingerprints")
|
||||
|
||||
def __init__(self, employee_id: uuid.UUID, date_: datetime, id_: uuid.UUID | None = None) -> None:
|
||||
self.employee_id = employee_id
|
||||
self.date = date_
|
||||
self.date_ = date_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
@ -4,7 +4,6 @@ from decimal import Decimal
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import (
|
||||
DECIMAL,
|
||||
ColumnElement,
|
||||
ForeignKey,
|
||||
Numeric,
|
||||
|
@ -200,7 +200,7 @@ def employee_blank() -> schemas.EmployeeBlank:
|
||||
designation="",
|
||||
salary=0,
|
||||
points=Decimal(0),
|
||||
joining_date=datetime.today(),
|
||||
joining_date=datetime.today().date(),
|
||||
leaving_date=None,
|
||||
)
|
||||
|
||||
|
@ -109,10 +109,10 @@ def get_prints(employee_id: uuid.UUID, date_: date, db: Session) -> tuple[str, s
|
||||
select(Fingerprint)
|
||||
.where(
|
||||
Fingerprint.employee_id == employee_id,
|
||||
Fingerprint.date >= datetime.combine(date_, time(hour=7)),
|
||||
Fingerprint.date < datetime.combine(date_ + timedelta(days=1), time(hour=7)),
|
||||
Fingerprint.date_ >= datetime.combine(date_, time(hour=7)),
|
||||
Fingerprint.date_ < datetime.combine(date_ + timedelta(days=1), time(hour=7)),
|
||||
)
|
||||
.order_by(Fingerprint.date)
|
||||
.order_by(Fingerprint.date_)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
@ -120,7 +120,7 @@ def get_prints(employee_id: uuid.UUID, date_: date, db: Session) -> tuple[str, s
|
||||
|
||||
last = None
|
||||
for i in range(len(prints), 0, -1):
|
||||
item = prints[i - 1].date
|
||||
item = prints[i - 1].date_
|
||||
if last is not None and last - item < timedelta(minutes=10):
|
||||
prints.remove(prints[i - 1])
|
||||
else:
|
||||
@ -129,15 +129,15 @@ def get_prints(employee_id: uuid.UUID, date_: date, db: Session) -> tuple[str, s
|
||||
if len(prints) == 0:
|
||||
hours_worked, full_day = "", False
|
||||
elif len(prints) == 2:
|
||||
time_worked = prints[1].date - prints[0].date
|
||||
time_worked = prints[1].date_ - prints[0].date_
|
||||
hours_worked, full_day = working_hours(time_worked)
|
||||
elif len(prints) == 4:
|
||||
time_worked = (prints[1].date - prints[0].date) + (prints[3].date - prints[2].date)
|
||||
time_worked = (prints[1].date_ - prints[0].date_) + (prints[3].date_ - prints[2].date_)
|
||||
hours_worked, full_day = working_hours(time_worked)
|
||||
else:
|
||||
hours_worked, full_day = "Error", False
|
||||
return (
|
||||
", ".join([x.date.strftime("%H:%M") for x in prints]) + " ",
|
||||
", ".join([x.date_.strftime("%H:%M") for x in prints]) + " ",
|
||||
hours_worked,
|
||||
full_day,
|
||||
)
|
||||
|
@ -56,7 +56,7 @@ class EmployeeIn(AccountBase):
|
||||
self.leaving_date = None
|
||||
if (not self.is_active) and (self.leaving_date is None):
|
||||
raise ValueError("Need leaving date for employee")
|
||||
if self.leaving_date < self.joining_date:
|
||||
if self.leaving_date is not None and self.leaving_date < self.joining_date:
|
||||
raise ValueError("Leaving Date cannot be less than Joining Date")
|
||||
return self
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user