2020-06-14 13:13:10 +00:00
|
|
|
import uuid
|
2020-10-11 05:26:29 +00:00
|
|
|
|
2020-06-14 13:13:10 +00:00
|
|
|
from datetime import date, datetime
|
|
|
|
from decimal import Decimal
|
|
|
|
|
2023-07-22 03:49:48 +00:00
|
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
2020-10-11 15:23:43 +00:00
|
|
|
|
|
|
|
from . import to_camel
|
2020-06-14 13:13:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AccountBase(BaseModel):
|
|
|
|
name: str = Field(..., min_length=1)
|
|
|
|
is_starred: bool
|
|
|
|
is_active: bool
|
2023-07-22 03:49:48 +00:00
|
|
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel)
|
2020-06-14 13:13:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AccountIn(AccountBase):
|
|
|
|
type: int
|
|
|
|
is_reconcilable: bool
|
|
|
|
|
|
|
|
|
|
|
|
class Account(AccountIn):
|
|
|
|
id_: uuid.UUID
|
|
|
|
code: int
|
|
|
|
is_fixture: bool
|
|
|
|
|
|
|
|
|
|
|
|
class EmployeeIn(AccountBase):
|
|
|
|
designation: str
|
|
|
|
salary: int = Field(ge=0)
|
|
|
|
points: Decimal = Field(ge=0, lt=1000, multiple_of=0.01)
|
|
|
|
joining_date: date
|
2023-07-22 03:49:48 +00:00
|
|
|
leaving_date: date | None = None
|
2020-06-14 13:13:10 +00:00
|
|
|
|
2023-07-22 03:49:48 +00:00
|
|
|
@field_validator("joining_date", mode="before")
|
|
|
|
@classmethod
|
2020-06-14 13:13:10 +00:00
|
|
|
def parse_joining_date(cls, value):
|
|
|
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
|
|
|
|
2023-07-22 03:49:48 +00:00
|
|
|
@field_validator("leaving_date", mode="before")
|
|
|
|
@classmethod
|
2020-06-14 13:13:10 +00:00
|
|
|
def parse_leaving_date(cls, value):
|
|
|
|
if value is None or value == "":
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
|
|
|
|
2023-07-22 03:49:48 +00:00
|
|
|
@model_validator(mode="after")
|
|
|
|
def leaving_date_more_than_joining_date(self) -> "EmployeeIn":
|
|
|
|
if self.is_active:
|
|
|
|
self.leaving_date = None
|
|
|
|
elif self.leaving_date < self.joining_date:
|
2020-06-14 13:13:10 +00:00
|
|
|
raise ValueError("Leaving Date cannot be less than Joining Date")
|
2023-07-22 03:49:48 +00:00
|
|
|
return self
|
2020-06-14 13:13:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Employee(EmployeeIn):
|
|
|
|
id_: uuid.UUID
|
|
|
|
code: int
|
|
|
|
is_fixture: bool
|
|
|
|
|
|
|
|
|
|
|
|
class DbSetting(BaseModel):
|
|
|
|
id_: uuid.UUID
|
|
|
|
name: str
|
|
|
|
data: bytes
|
|
|
|
|
|
|
|
|
|
|
|
class AccountType(BaseModel):
|
|
|
|
id_: int
|
|
|
|
name: str
|
2023-07-22 03:49:48 +00:00
|
|
|
model_config = ConfigDict(alias_generator=to_camel)
|