From 0fd84135ddf1557da3411d8feade41326cfe9fdf Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Fri, 4 Aug 2023 19:15:41 +0530 Subject: [PATCH] Fix: Employee things were not working --- brewman/brewman/models/fingerprint.py | 4 ++-- brewman/brewman/models/inventory.py | 1 - brewman/brewman/routers/employee.py | 2 +- brewman/brewman/routers/fingerprint.py | 14 +++++++------- brewman/brewman/schemas/employee.py | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/brewman/brewman/models/fingerprint.py b/brewman/brewman/models/fingerprint.py index 2634c1d2..6f235bc2 100644 --- a/brewman/brewman/models/fingerprint.py +++ b/brewman/brewman/models/fingerprint.py @@ -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_ diff --git a/brewman/brewman/models/inventory.py b/brewman/brewman/models/inventory.py index 858b7d9d..0e0ba3fa 100644 --- a/brewman/brewman/models/inventory.py +++ b/brewman/brewman/models/inventory.py @@ -4,7 +4,6 @@ from decimal import Decimal from typing import TYPE_CHECKING from sqlalchemy import ( - DECIMAL, ColumnElement, ForeignKey, Numeric, diff --git a/brewman/brewman/routers/employee.py b/brewman/brewman/routers/employee.py index b222f60c..2a5fd4bd 100644 --- a/brewman/brewman/routers/employee.py +++ b/brewman/brewman/routers/employee.py @@ -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, ) diff --git a/brewman/brewman/routers/fingerprint.py b/brewman/brewman/routers/fingerprint.py index c25852d7..635a1ef3 100644 --- a/brewman/brewman/routers/fingerprint.py +++ b/brewman/brewman/routers/fingerprint.py @@ -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, ) diff --git a/brewman/brewman/schemas/employee.py b/brewman/brewman/schemas/employee.py index 6cd5eb90..6ecee5ca 100644 --- a/brewman/brewman/schemas/employee.py +++ b/brewman/brewman/schemas/employee.py @@ -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