Extensive mypy checking.
This commit is contained in:
1 parent
529e50b3ba
commit
9d088aa95e
72 files changed
+539
-463
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Tuple
|
||||||
|
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ class Account(AccountBase):
|
|||||||
"Product", primaryjoin="Account.id==Product.account_id", back_populates="account"
|
"Product", primaryjoin="Account.id==Product.account_id", back_populates="account"
|
||||||
)
|
)
|
||||||
|
|
||||||
def can_delete(self, advanced_delete):
|
def can_delete(self, advanced_delete: bool) -> Tuple[bool, str]:
|
||||||
if len(self.products) > 0:
|
if len(self.products) > 0:
|
||||||
return False, "Account has products"
|
return False, "Account has products"
|
||||||
return super(Account, self).can_delete(advanced_delete)
|
return super(Account, self).can_delete(advanced_delete)
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, List, Optional
|
from typing import TYPE_CHECKING, List, Optional, Tuple
|
||||||
|
|
||||||
from sqlalchemy import Boolean, Column, ForeignKey, Integer, Unicode, func, select
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, Unicode, func, select
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from sqlalchemy.orm import Mapped, Session, relationship
|
from sqlalchemy.orm import Mapped, Session, relationship
|
||||||
|
|
||||||
|
from ..schemas.account import AccountLink
|
||||||
from .account_type import AccountType
|
from .account_type import AccountType
|
||||||
from .meta import Base
|
from .meta import Base
|
||||||
|
|
||||||
@@ -49,21 +50,21 @@ class AccountBase(Base):
|
|||||||
rate_contracts: List["RateContract"] = relationship("RateContract", back_populates="vendor")
|
rate_contracts: List["RateContract"] = relationship("RateContract", back_populates="vendor")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __name__(self):
|
def __name__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
code=None,
|
code: int,
|
||||||
name=None,
|
name: str,
|
||||||
type_id=None,
|
type_id: int,
|
||||||
is_starred=None,
|
is_starred: bool,
|
||||||
is_active=None,
|
is_active: bool,
|
||||||
is_reconcilable=False,
|
is_reconcilable: bool,
|
||||||
cost_centre_id=None,
|
cost_centre_id: uuid.UUID,
|
||||||
id_=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
is_fixture=False,
|
is_fixture: bool = False,
|
||||||
):
|
) -> None:
|
||||||
self.code = code
|
self.code = code
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type_id = type_id
|
self.type_id = type_id
|
||||||
@@ -71,31 +72,18 @@ class AccountBase(Base):
|
|||||||
self.is_active = is_active
|
self.is_active = is_active
|
||||||
self.is_reconcilable = is_reconcilable
|
self.is_reconcilable = is_reconcilable
|
||||||
self.cost_centre_id = cost_centre_id
|
self.cost_centre_id = cost_centre_id
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
self.is_fixture = is_fixture
|
self.is_fixture = is_fixture
|
||||||
|
|
||||||
@classmethod
|
def create(self, db: Session) -> "AccountBase":
|
||||||
def query(cls, q: str, type_: Optional[int], reconcilable: Optional[bool], active: Optional[bool], db: Session):
|
|
||||||
query_ = select(cls)
|
|
||||||
if type_ is not None:
|
|
||||||
query_ = query_.where(cls.type_id == type_)
|
|
||||||
if reconcilable is not None:
|
|
||||||
query_ = query_.where(cls.is_reconcilable == reconcilable)
|
|
||||||
if active is not None:
|
|
||||||
query_ = query_.where(cls.is_active == active)
|
|
||||||
if q is not None:
|
|
||||||
for item in q.split():
|
|
||||||
query_ = query_.where(cls.name.ilike(f"%{item}%"))
|
|
||||||
return db.execute(query_.order_by(cls.name)).scalars().all()
|
|
||||||
|
|
||||||
def create(self, db: Session):
|
|
||||||
self.code = db.execute(
|
self.code = db.execute(
|
||||||
select(func.coalesce(func.max(AccountBase.code), 0) + 1).where(AccountBase.type_id == self.type_id)
|
select(func.coalesce(func.max(AccountBase.code), 0) + 1).where(AccountBase.type_id == self.type_id)
|
||||||
).scalar_one()
|
).scalar_one()
|
||||||
db.add(self)
|
db.add(self)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def can_delete(self, advanced_delete: bool):
|
def can_delete(self, advanced_delete: bool) -> Tuple[bool, str]:
|
||||||
if self.is_fixture:
|
if self.is_fixture:
|
||||||
return False, f"{self.name} is a fixture and cannot be edited or deleted."
|
return False, f"{self.name} is a fixture and cannot be edited or deleted."
|
||||||
if self.is_active:
|
if self.is_active:
|
||||||
@@ -105,47 +93,48 @@ class AccountBase(Base):
|
|||||||
return True, ""
|
return True, ""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_code(cls, type_: int, db: Session):
|
def get_code(cls, type_: int, db: Session) -> int:
|
||||||
return db.execute(
|
code: int = db.execute(
|
||||||
select(func.coalesce(func.max(AccountBase.code), 0) + 1).where(AccountBase.type_id == type_)
|
select(func.coalesce(func.max(AccountBase.code), 0) + 1).where(AccountBase.type_id == type_)
|
||||||
).scalar_one()
|
).scalar_one()
|
||||||
|
return code
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def all_purchases(cls):
|
def all_purchases(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("240dd899-c413-854c-a7eb-67a29d154490")
|
return uuid.UUID("240dd899-c413-854c-a7eb-67a29d154490")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cash_in_hand(cls):
|
def cash_in_hand(cls) -> AccountLink:
|
||||||
return {"id": "ed2341bb-80b8-9649-90db-f9aaca183bb3", "name": "Cash in Hand"}
|
return AccountLink(id=uuid.UUID("ed2341bb-80b8-9649-90db-f9aaca183bb3"), name="Cash in Hand")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def local_purchase(cls):
|
def local_purchase(cls) -> AccountLink:
|
||||||
return {"id": "d2b75912-505f-2548-9093-466dfff6a0f9", "name": "Local Purchase"}
|
return AccountLink(id=uuid.UUID("d2b75912-505f-2548-9093-466dfff6a0f9"), name="Local Purchase")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def salary(cls):
|
def salary(cls) -> AccountLink:
|
||||||
return {"id": "5c2b54d0-c174-004d-a0d5-92cdaadcefa7", "name": "Staff Salary"}
|
return AccountLink(id=uuid.UUID("5c2b54d0-c174-004d-a0d5-92cdaadcefa7"), name="Staff Salary")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def salary_id(cls):
|
def salary_id(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("5c2b54d0-c174-004d-a0d5-92cdaadcefa7")
|
return uuid.UUID("5c2b54d0-c174-004d-a0d5-92cdaadcefa7")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def incentive(cls):
|
def incentive(cls) -> AccountLink:
|
||||||
return {"id": "b7eff754-e8ba-e047-ab06-9132c15c7640", "name": "Incentives"}
|
return AccountLink(id=uuid.UUID("b7eff754-e8ba-e047-ab06-9132c15c7640"), name="Incentives")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def incentive_id(cls):
|
def incentive_id(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("b7eff754-e8ba-e047-ab06-9132c15c7640")
|
return uuid.UUID("b7eff754-e8ba-e047-ab06-9132c15c7640")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def esi_pf_expense(cls):
|
def esi_pf_expense(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("d2a1a286-e900-764b-a1a5-9f4b00dbb940")
|
return uuid.UUID("d2a1a286-e900-764b-a1a5-9f4b00dbb940")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def esi_pf_payable(cls):
|
def esi_pf_payable(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("42277912-cc18-854b-b134-9f4b00dba419")
|
return uuid.UUID("42277912-cc18-854b-b134-9f4b00dba419")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def suspense(cls):
|
def suspense(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("3854e317-6f3b-5142-ab26-9c44d4cddd08")
|
return uuid.UUID("3854e317-6f3b-5142-ab26-9c44d4cddd08")
|
||||||
@@ -2,7 +2,7 @@ import datetime
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import (
|
from sqlalchemy import (
|
||||||
Boolean,
|
Boolean,
|
||||||
@@ -53,25 +53,26 @@ class Attendance(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id_=None,
|
employee_id: uuid.UUID,
|
||||||
employee_id=None,
|
date: datetime.date,
|
||||||
date=None,
|
attendance_type: int,
|
||||||
attendance_type=None,
|
user_id: uuid.UUID,
|
||||||
amount=None,
|
amount: Decimal = Decimal(0),
|
||||||
creation_date=None,
|
creation_date: Optional[datetime.datetime] = None,
|
||||||
user_id=None,
|
is_valid: bool = True,
|
||||||
is_valid=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
):
|
):
|
||||||
self.id = id_
|
|
||||||
self.employee_id = employee_id
|
self.employee_id = employee_id
|
||||||
self.date = date
|
self.date = date
|
||||||
self.attendance_type = attendance_type
|
self.attendance_type = attendance_type
|
||||||
self.amount = amount if amount is not None else 0
|
|
||||||
self.creation_date = creation_date or datetime.datetime.utcnow()
|
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
self.is_valid = is_valid if is_valid is not None else True
|
self.amount = amount
|
||||||
|
self.creation_date = creation_date or datetime.datetime.utcnow()
|
||||||
|
self.is_valid = is_valid
|
||||||
|
if id_ is not None:
|
||||||
|
self.id = id_
|
||||||
|
|
||||||
def create(self, db: Session):
|
def create(self, db: Session) -> None:
|
||||||
old = (
|
old = (
|
||||||
db.execute(
|
db.execute(
|
||||||
select(Attendance)
|
select(Attendance)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
class AttendanceType:
|
class AttendanceType:
|
||||||
@@ -6,13 +7,13 @@ class AttendanceType:
|
|||||||
name: str
|
name: str
|
||||||
value: Decimal
|
value: Decimal
|
||||||
|
|
||||||
def __init__(self, id_: int, name: str, value: Decimal):
|
def __init__(self, id_: int, name: str, value: Decimal) -> None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
self.name = name
|
self.name = name
|
||||||
self.value = value
|
self.value = value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def list(cls):
|
def list(cls) -> List["AttendanceType"]:
|
||||||
return [
|
return [
|
||||||
AttendanceType(0, "Not Set", Decimal(0)),
|
AttendanceType(0, "Not Set", Decimal(0)),
|
||||||
AttendanceType(1, "Present", Decimal(1)),
|
AttendanceType(1, "Present", Decimal(1)),
|
||||||
@@ -29,9 +30,9 @@ class AttendanceType:
|
|||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def by_name(cls, name):
|
def by_name(cls, name: str) -> "AttendanceType":
|
||||||
return next(i for i in cls.list() if i.name == name)
|
return next(i for i in cls.list() if i.name == name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def by_id(cls, id_):
|
def by_id(cls, id_: int) -> "AttendanceType":
|
||||||
return next(i for i in cls.list() if i.id == id_)
|
return next(i for i in cls.list() if i.id == id_)
|
||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, Date, ForeignKey, Numeric
|
from sqlalchemy import Column, Date, ForeignKey, Numeric
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -34,29 +34,28 @@ class Batch(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name=None,
|
name: date,
|
||||||
sku_id=None,
|
quantity_remaining: Decimal,
|
||||||
quantity_remaining=None,
|
rate: Decimal,
|
||||||
rate=None,
|
tax: Decimal,
|
||||||
tax=None,
|
discount: Decimal,
|
||||||
discount=None,
|
sku_id: Optional[uuid.UUID] = None,
|
||||||
sku=None,
|
sku: Optional["StockKeepingUnit"] = None,
|
||||||
):
|
):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
if sku_id is not None and sku is None:
|
||||||
self.sku_id = sku_id
|
self.sku_id = sku_id
|
||||||
self.quantity_remaining = quantity_remaining
|
self.quantity_remaining = quantity_remaining
|
||||||
self.rate = rate
|
self.rate = rate
|
||||||
self.tax = tax
|
self.tax = tax
|
||||||
self.discount = discount
|
self.discount = discount
|
||||||
if sku is None:
|
if sku is not None:
|
||||||
self.sku_id = sku_id
|
|
||||||
else:
|
|
||||||
self.sku_id = sku.id
|
self.sku_id = sku.id
|
||||||
self.sku = sku
|
self.sku = sku
|
||||||
|
|
||||||
def amount(self):
|
def amount(self) -> Decimal:
|
||||||
return self.quantity_remaining * self.rate * (1 + self.tax) * (1 - self.discount)
|
return self.quantity_remaining * self.rate * (1 + self.tax) * (1 - self.discount)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def suspense(cls):
|
def suspense(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("a955790e-93cf-493c-a816-c7d92b127383")
|
return uuid.UUID("a955790e-93cf-493c-a816-c7d92b127383")
|
||||||
@@ -5,7 +5,7 @@ import string
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List
|
from typing import List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Boolean, Column, DateTime, Integer, Unicode, desc
|
from sqlalchemy import Boolean, Column, DateTime, Integer, Unicode, desc
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -31,22 +31,23 @@ class Client(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
code=None,
|
code: int,
|
||||||
name=None,
|
name: str,
|
||||||
enabled=False,
|
enabled: bool,
|
||||||
otp=None,
|
otp: int,
|
||||||
creation_date=None,
|
creation_date: Optional[datetime] = None,
|
||||||
id_=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
):
|
) -> None:
|
||||||
self.code = code
|
self.code = code
|
||||||
self.name = name
|
self.name = name
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self.otp = otp
|
self.otp = otp
|
||||||
self.creation_date = datetime.utcnow() if creation_date is None else creation_date
|
self.creation_date = datetime.utcnow() if creation_date is None else creation_date
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, db: Session):
|
def create(cls, db: Session) -> "Client":
|
||||||
client_code = random.randint(1000, 9999)
|
client_code = random.randint(1000, 9999)
|
||||||
otp = random.randint(1000, 9999)
|
otp = random.randint(1000, 9999)
|
||||||
name = "".join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
|
name = "".join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import datetime
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, Date, ForeignKey, Numeric, UniqueConstraint
|
from sqlalchemy import Column, Date, ForeignKey, Numeric, UniqueConstraint
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -22,7 +22,7 @@ class ClosingStock(Base):
|
|||||||
__tablename__ = "closing_stocks"
|
__tablename__ = "closing_stocks"
|
||||||
__table_args__ = (UniqueConstraint("date", "cost_centre_id", "sku_id"),)
|
__table_args__ = (UniqueConstraint("date", "cost_centre_id", "sku_id"),)
|
||||||
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
date: datetime.date = Column("date", Date, nullable=False)
|
date_: datetime.date = Column("date", Date, nullable=False)
|
||||||
cost_centre_id: uuid.UUID = Column(
|
cost_centre_id: uuid.UUID = Column(
|
||||||
"cost_centre_id",
|
"cost_centre_id",
|
||||||
UUID(as_uuid=True),
|
UUID(as_uuid=True),
|
||||||
@@ -37,18 +37,20 @@ class ClosingStock(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
date_=None,
|
date_: datetime.date,
|
||||||
cost_centre_id=None,
|
cost_centre_id: uuid.UUID,
|
||||||
sku_id=None,
|
quantity: Decimal,
|
||||||
quantity=None,
|
sku_id: Optional[uuid.UUID] = None,
|
||||||
sku=None,
|
sku: Optional["StockKeepingUnit"] = None,
|
||||||
id_=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
):
|
):
|
||||||
self.date = date_
|
self.date_ = date_
|
||||||
self.cost_centre_id = cost_centre_id
|
self.cost_centre_id = cost_centre_id
|
||||||
self.sku_id = sku_id
|
|
||||||
self.quantity = quantity
|
self.quantity = quantity
|
||||||
|
if sku_id is not None:
|
||||||
|
self.sku_id = sku_id
|
||||||
if sku is not None:
|
if sku is not None:
|
||||||
self.sku = sku
|
self.sku = sku
|
||||||
self.sku_id = sku.id
|
self.sku_id = sku.id
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Boolean, Column, Unicode
|
from sqlalchemy import Boolean, Column, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from ..schemas.cost_centre import CostCentreLink
|
||||||
from .meta import Base
|
from .meta import Base
|
||||||
|
|
||||||
|
|
||||||
@@ -27,29 +28,27 @@ class CostCentre(Base):
|
|||||||
journals: List["Journal"] = relationship("Journal", back_populates="cost_centre")
|
journals: List["Journal"] = relationship("Journal", back_populates="cost_centre")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __name__(self):
|
def __name__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def __init__(self, name=None, id_=None, is_fixture=False):
|
def __init__(self, name: str, id_: Optional[uuid.UUID] = None, is_fixture: bool = False) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
self.is_fixture = is_fixture
|
self.is_fixture = is_fixture
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cost_centre_purchase(cls):
|
def cost_centre_purchase(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("7b845f95-dfef-fa4a-897c-f0baf15284a3")
|
return uuid.UUID("7b845f95-dfef-fa4a-897c-f0baf15284a3")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cost_centre_kitchen(cls):
|
def cost_centre_kitchen(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("b2d398ce-e3cc-c542-9feb-5d7783e899df")
|
return uuid.UUID("b2d398ce-e3cc-c542-9feb-5d7783e899df")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cost_centre_overall(cls):
|
def cost_centre_overall(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d")
|
return uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def overall(cls):
|
def overall(cls) -> CostCentreLink:
|
||||||
return {
|
return CostCentreLink(id=uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d"), name="Overall")
|
||||||
"id": uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d"),
|
|
||||||
"name": "Overall",
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, DateTime, Unicode
|
from sqlalchemy import Column, DateTime, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import BYTEA, UUID
|
from sqlalchemy.dialects.postgresql import BYTEA, UUID
|
||||||
@@ -20,16 +21,17 @@ class DbImage(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
resource_id=None,
|
resource_id: uuid.UUID,
|
||||||
resource_type=None,
|
resource_type: str,
|
||||||
image=None,
|
image: bytes,
|
||||||
thumbnail=None,
|
thumbnail: bytes,
|
||||||
creation_date=None,
|
creation_date: Optional[datetime] = None,
|
||||||
id_=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
):
|
) -> None:
|
||||||
self.resource_id = resource_id
|
self.resource_id = resource_id
|
||||||
self.resource_type = resource_type
|
self.resource_type = resource_type
|
||||||
self.image = image
|
self.image = image
|
||||||
self.thumbnail = thumbnail
|
self.thumbnail = thumbnail
|
||||||
self.creation_date = creation_date or datetime.utcnow()
|
self.creation_date = creation_date or datetime.utcnow()
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
@@ -15,13 +15,22 @@ class DbSetting(Base):
|
|||||||
|
|
||||||
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
name: str = Column("name", Unicode(255), unique=True, nullable=False)
|
name: str = Column("name", Unicode(255), unique=True, nullable=False)
|
||||||
data = Column("data", PickleType)
|
data: dict = Column("data", PickleType)
|
||||||
setting_type: SettingType = Column("setting_type", Enum(SettingType), nullable=False)
|
setting_type: SettingType = Column("setting_type", Enum(SettingType), nullable=False)
|
||||||
|
|
||||||
valid_from: Optional[date] = Column("valid_from", Date(), nullable=True)
|
valid_from: Optional[date] = Column("valid_from", Date(), nullable=True)
|
||||||
valid_till: Optional[date] = Column("valid_till", Date(), nullable=True)
|
valid_till: Optional[date] = Column("valid_till", Date(), nullable=True)
|
||||||
|
|
||||||
def __init__(self, id_=None, setting_type=None, name=None, data=None, valid_from=None, valid_till=None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
setting_type: SettingType,
|
||||||
|
name: str,
|
||||||
|
data: dict,
|
||||||
|
valid_from: Optional[date] = None,
|
||||||
|
valid_till: Optional[date] = None,
|
||||||
|
id_: Optional[uuid.UUID] = None,
|
||||||
|
) -> None:
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
self.setting_type = setting_type
|
self.setting_type = setting_type
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING, List, Optional
|
from typing import TYPE_CHECKING, List, Optional, Tuple
|
||||||
|
|
||||||
from sqlalchemy import Column, Date, ForeignKey, Integer, Numeric, Unicode, func, select
|
from sqlalchemy import Column, Date, ForeignKey, Integer, Numeric, Unicode, func, select
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -34,24 +34,24 @@ class Employee(AccountBase):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
code=None,
|
code: Optional[int],
|
||||||
name=None,
|
name: str,
|
||||||
is_starred=None,
|
is_starred: bool,
|
||||||
is_active=None,
|
is_active: bool,
|
||||||
cost_centre_id=None,
|
cost_centre_id: uuid.UUID,
|
||||||
designation=None,
|
designation: str,
|
||||||
salary=None,
|
salary: int,
|
||||||
points=None,
|
points: Decimal,
|
||||||
joining_date=None,
|
joining_date: date,
|
||||||
leaving_date=None,
|
leaving_date: Optional[date] = None,
|
||||||
):
|
) -> None:
|
||||||
self.designation = designation
|
self.designation = designation
|
||||||
self.salary = salary
|
self.salary = salary
|
||||||
self.points = points
|
self.points = points
|
||||||
self.joining_date = joining_date
|
self.joining_date = joining_date
|
||||||
self.leaving_date = leaving_date
|
self.leaving_date = leaving_date
|
||||||
super().__init__(
|
super().__init__(
|
||||||
code=code,
|
code=code if code is not None else 0,
|
||||||
name=name,
|
name=name,
|
||||||
type_id=10,
|
type_id=10,
|
||||||
is_starred=is_starred,
|
is_starred=is_starred,
|
||||||
@@ -60,7 +60,7 @@ class Employee(AccountBase):
|
|||||||
cost_centre_id=cost_centre_id,
|
cost_centre_id=cost_centre_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
def create(self, db: Session):
|
def create(self, db: Session) -> "Employee":
|
||||||
self.code = db.execute(
|
self.code = db.execute(
|
||||||
select(func.coalesce(func.max(AccountBase.code), 0) + 1).filter(AccountBase.type_id == self.type_id)
|
select(func.coalesce(func.max(AccountBase.code), 0) + 1).filter(AccountBase.type_id == self.type_id)
|
||||||
).scalar_one()
|
).scalar_one()
|
||||||
@@ -68,5 +68,5 @@ class Employee(AccountBase):
|
|||||||
db.add(self)
|
db.add(self)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def can_delete(self, advanced_delete):
|
def can_delete(self, advanced_delete: bool) -> Tuple[bool, str]:
|
||||||
return super(Employee, self).can_delete(advanced_delete)
|
return super(Employee, self).can_delete(advanced_delete)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Integer
|
from sqlalchemy import Column, ForeignKey, Integer
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -31,18 +31,19 @@ class EmployeeBenefit(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id_=None,
|
gross_salary: int,
|
||||||
voucher_id=None,
|
days_worked: int,
|
||||||
journal_id=None,
|
esi_ee: int,
|
||||||
journal=None,
|
pf_ee: int,
|
||||||
gross_salary=None,
|
esi_er: int,
|
||||||
days_worked=None,
|
pf_er: int,
|
||||||
esi_ee=None,
|
journal: "Journal",
|
||||||
pf_ee=None,
|
voucher_id: Optional[uuid.UUID] = None,
|
||||||
esi_er=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
pf_er=None,
|
) -> None:
|
||||||
):
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
|
if voucher_id is not None:
|
||||||
self.voucher_id = voucher_id
|
self.voucher_id = voucher_id
|
||||||
self.gross_salary = gross_salary
|
self.gross_salary = gross_salary
|
||||||
self.days_worked = days_worked
|
self.days_worked = days_worked
|
||||||
@@ -50,7 +51,4 @@ class EmployeeBenefit(Base):
|
|||||||
self.pf_ee = pf_ee
|
self.pf_ee = pf_ee
|
||||||
self.esi_er = esi_er
|
self.esi_er = esi_er
|
||||||
self.pf_er = pf_er
|
self.pf_er = pf_er
|
||||||
if journal is None:
|
|
||||||
self.journal_id = journal_id
|
|
||||||
else:
|
|
||||||
self.journal = journal
|
self.journal = journal
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, DateTime, ForeignKey
|
from sqlalchemy import Column, DateTime, ForeignKey
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -25,8 +25,8 @@ class Fingerprint(Base):
|
|||||||
|
|
||||||
employee: Mapped["Employee"] = relationship("Employee", back_populates="fingerprints")
|
employee: Mapped["Employee"] = relationship("Employee", back_populates="fingerprints")
|
||||||
|
|
||||||
def __init__(self, id_=None, employee_id=None, date=None):
|
def __init__(self, employee_id: uuid.UUID, date: datetime, id_: Optional[uuid.UUID] = None) -> None:
|
||||||
self.id = id_
|
|
||||||
self.employee_id = employee_id
|
self.employee_id = employee_id
|
||||||
self.date = date
|
self.date = date
|
||||||
self.fingerprint_type = 0
|
if id_ is not None:
|
||||||
|
self.id = id_
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Numeric
|
from sqlalchemy import Column, ForeignKey, Numeric
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -28,18 +28,16 @@ class Incentive(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id_=None,
|
journal: "Journal",
|
||||||
voucher_id=None,
|
days_worked: Decimal,
|
||||||
journal_id=None,
|
points: Decimal,
|
||||||
journal=None,
|
voucher_id: Optional[uuid.UUID] = None,
|
||||||
days_worked=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
points=None,
|
) -> None:
|
||||||
):
|
|
||||||
self.id = id_
|
|
||||||
self.voucher_id = voucher_id
|
|
||||||
if journal is None:
|
|
||||||
self.journal_id = journal_id
|
|
||||||
else:
|
|
||||||
self.journal = journal
|
self.journal = journal
|
||||||
self.days_worked = days_worked
|
self.days_worked = days_worked
|
||||||
self.points = points
|
self.points = points
|
||||||
|
if voucher_id is not None:
|
||||||
|
self.voucher_id = voucher_id
|
||||||
|
if id_ is not None:
|
||||||
|
self.id = id_
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Numeric, UniqueConstraint
|
from sqlalchemy import Column, ForeignKey, Numeric, UniqueConstraint
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -40,25 +40,23 @@ class Inventory(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id_=None,
|
quantity: Decimal,
|
||||||
voucher_id=None,
|
rate: Decimal,
|
||||||
batch_id=None,
|
tax: Decimal,
|
||||||
quantity=None,
|
discount: Decimal,
|
||||||
rate=None,
|
batch: "Batch",
|
||||||
tax=None,
|
voucher_id: Optional[uuid.UUID] = None,
|
||||||
discount=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
batch=None,
|
) -> None:
|
||||||
):
|
|
||||||
self.id = id_
|
|
||||||
self.voucher_id = voucher_id
|
|
||||||
if batch is None:
|
|
||||||
self.batch_id = batch_id
|
|
||||||
else:
|
|
||||||
self.batch = batch
|
self.batch = batch
|
||||||
self.quantity = quantity
|
self.quantity = quantity
|
||||||
self.rate = rate
|
self.rate = rate
|
||||||
self.tax = tax
|
self.tax = tax
|
||||||
self.discount = discount
|
self.discount = discount
|
||||||
|
if id_ is not None:
|
||||||
|
self.id = id_
|
||||||
|
if voucher_id is not None:
|
||||||
|
self.voucher_id = voucher_id
|
||||||
|
|
||||||
@hybrid_property
|
@hybrid_property
|
||||||
def amount(self) -> Decimal:
|
def amount(self) -> Decimal:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Integer, Numeric
|
from sqlalchemy import Column, ForeignKey, Integer, Numeric
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -49,25 +49,27 @@ class Journal(Base):
|
|||||||
incentive: Mapped["Incentive"] = relationship("Incentive", back_populates="journal")
|
incentive: Mapped["Incentive"] = relationship("Incentive", back_populates="journal")
|
||||||
|
|
||||||
@hybrid_property
|
@hybrid_property
|
||||||
def signed_amount(self):
|
def _signed_amount(self) -> Decimal:
|
||||||
return self.debit * self.amount
|
return self.debit * self.amount
|
||||||
|
|
||||||
@property
|
@_signed_amount.expression
|
||||||
def __name__(self):
|
def signed_amount(cls) -> Decimal:
|
||||||
return self.name
|
return cls.debit * cls.amount
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id_=None,
|
debit: int,
|
||||||
debit=None,
|
amount: Decimal,
|
||||||
amount=None,
|
account_id: uuid.UUID,
|
||||||
voucher_id=None,
|
cost_centre_id: uuid.UUID,
|
||||||
account_id=None,
|
voucher_id: Optional[uuid.UUID] = None,
|
||||||
cost_centre_id=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
):
|
) -> None:
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
self.debit = debit
|
self.debit = debit
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
|
if voucher_id is not None:
|
||||||
self.voucher_id = voucher_id
|
self.voucher_id = voucher_id
|
||||||
self.account_id = account_id
|
self.account_id = account_id
|
||||||
self.cost_centre_id = cost_centre_id
|
self.cost_centre_id = cost_centre_id
|
||||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
import datetime
|
import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, DateTime, UniqueConstraint
|
from sqlalchemy import Column, DateTime, UniqueConstraint
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -36,8 +36,15 @@ class LoginHistory(Base):
|
|||||||
user: Mapped["User"] = relationship("User", back_populates="login_history")
|
user: Mapped["User"] = relationship("User", back_populates="login_history")
|
||||||
client: Mapped["Client"] = relationship("Client", back_populates="login_history")
|
client: Mapped["Client"] = relationship("Client", back_populates="login_history")
|
||||||
|
|
||||||
def __init__(self, user_id=None, client_id=None, date=None, id_=None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
user_id: uuid.UUID,
|
||||||
|
client_id: uuid.UUID,
|
||||||
|
date: Optional[datetime.datetime] = None,
|
||||||
|
id_: Optional[uuid.UUID] = None,
|
||||||
|
) -> None:
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
self.client_id = client_id
|
self.client_id = client_id
|
||||||
self.date = datetime.datetime.utcnow() if date is None else date
|
self.date = datetime.datetime.utcnow() if date is None else date
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import List
|
from typing import List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, Unicode
|
from sqlalchemy import Column, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -21,6 +21,7 @@ class Permission(Base):
|
|||||||
|
|
||||||
roles: List[Role] = relationship("Role", secondary=role_permission, back_populates="permissions")
|
roles: List[Role] = relationship("Role", secondary=role_permission, back_populates="permissions")
|
||||||
|
|
||||||
def __init__(self, name=None, id_=None):
|
def __init__(self, name: str, id_: Optional[uuid.UUID] = None) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Boolean, Column, ForeignKey, Integer, Unicode
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -42,17 +42,18 @@ class Product(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
code=None,
|
name: str,
|
||||||
name=None,
|
fraction_units: str,
|
||||||
fraction_units=None,
|
product_group_id: uuid.UUID,
|
||||||
product_group_id=None,
|
account_id: uuid.UUID,
|
||||||
account_id=None,
|
is_active: bool,
|
||||||
is_active=None,
|
is_purchased: bool,
|
||||||
is_purchased=None,
|
is_sold: bool,
|
||||||
is_sold=None,
|
code: Optional[int] = None,
|
||||||
id_=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
is_fixture=False,
|
is_fixture: Optional[bool] = False,
|
||||||
):
|
) -> None:
|
||||||
|
if code is not None:
|
||||||
self.code = code
|
self.code = code
|
||||||
self.name = name
|
self.name = name
|
||||||
self.fraction_units = fraction_units
|
self.fraction_units = fraction_units
|
||||||
@@ -61,9 +62,11 @@ class Product(Base):
|
|||||||
self.is_active = is_active
|
self.is_active = is_active
|
||||||
self.is_purchased = is_purchased
|
self.is_purchased = is_purchased
|
||||||
self.is_sold = is_sold
|
self.is_sold = is_sold
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
|
if is_fixture is not None:
|
||||||
self.is_fixture = is_fixture
|
self.is_fixture = is_fixture
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def suspense(cls):
|
def suspense(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("aa79a643-9ddc-4790-ac7f-a41f9efb4c15")
|
return uuid.UUID("aa79a643-9ddc-4790-ac7f-a41f9efb4c15")
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Boolean, Column, Unicode
|
from sqlalchemy import Boolean, Column, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -24,15 +24,17 @@ class ProductGroup(Base):
|
|||||||
|
|
||||||
products: List["Product"] = relationship("Product", back_populates="product_group")
|
products: List["Product"] = relationship("Product", back_populates="product_group")
|
||||||
|
|
||||||
def __init__(self, name=None, id_=None, is_fixture=False):
|
def __init__(self, name: str, id_: Optional[uuid.UUID] = None, is_fixture: Optional[bool] = False) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
|
if is_fixture is not None:
|
||||||
self.is_fixture = is_fixture
|
self.is_fixture = is_fixture
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def menu_item(cls):
|
def menu_item(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("dad46805-f577-4e5b-8073-9b788e0173fc")
|
return uuid.UUID("dad46805-f577-4e5b-8073-9b788e0173fc")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def semi(cls):
|
def semi(cls) -> uuid.UUID:
|
||||||
return uuid.UUID("e6bf81b9-1e9b-499f-81d5-ab5662e9d9b1")
|
return uuid.UUID("e6bf81b9-1e9b-499f-81d5-ab5662e9d9b1")
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, Date, DateTime, ForeignKey, Unicode
|
from sqlalchemy import Column, Date, DateTime, ForeignKey, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -24,8 +24,8 @@ class RateContract(Base):
|
|||||||
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
date: datetime.date = Column("date", Date, nullable=False, index=True)
|
date: datetime.date = Column("date", Date, nullable=False, index=True)
|
||||||
vendor_id: uuid.UUID = Column("vendor_id", UUID(as_uuid=True), ForeignKey("accounts.id"), nullable=False)
|
vendor_id: uuid.UUID = Column("vendor_id", UUID(as_uuid=True), ForeignKey("accounts.id"), nullable=False)
|
||||||
valid_from: datetime.date = Column("valid_from", Date(), nullable=True)
|
valid_from: Optional[datetime.date] = Column("valid_from", Date(), nullable=True)
|
||||||
valid_till: datetime.date = Column("valid_till", Date(), nullable=True)
|
valid_till: Optional[datetime.date] = Column("valid_till", Date(), nullable=True)
|
||||||
narration: str = Column("narration", Unicode(1000), nullable=False)
|
narration: str = Column("narration", Unicode(1000), nullable=False)
|
||||||
|
|
||||||
user_id: uuid.UUID = Column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
user_id: uuid.UUID = Column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
||||||
@@ -38,15 +38,15 @@ class RateContract(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
date=None,
|
date: datetime.date,
|
||||||
vendor_id=None,
|
vendor_id: uuid.UUID,
|
||||||
valid_from=None,
|
valid_from: Optional[datetime.date],
|
||||||
valid_till=None,
|
valid_till: Optional[datetime.date],
|
||||||
narration="",
|
user_id: uuid.UUID,
|
||||||
user_id=None,
|
narration: str = "",
|
||||||
creation_date=None,
|
creation_date: Optional[datetime.datetime] = None,
|
||||||
last_edit_date=None,
|
last_edit_date: Optional[datetime.datetime] = None,
|
||||||
id_=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
):
|
):
|
||||||
self.date = date
|
self.date = date
|
||||||
self.vendor_id = vendor_id
|
self.vendor_id = vendor_id
|
||||||
@@ -56,4 +56,5 @@ class RateContract(Base):
|
|||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
self.creation_date = creation_date or datetime.datetime.utcnow()
|
self.creation_date = creation_date or datetime.datetime.utcnow()
|
||||||
self.last_edit_date = last_edit_date or datetime.datetime.utcnow()
|
self.last_edit_date = last_edit_date or datetime.datetime.utcnow()
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Numeric, UniqueConstraint
|
from sqlalchemy import Column, ForeignKey, Numeric, UniqueConstraint
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -37,12 +37,13 @@ class RateContractItem(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
rate_contract_id=None,
|
rate_contract_id: uuid.UUID,
|
||||||
sku_id=None,
|
sku_id: uuid.UUID,
|
||||||
price=None,
|
price: Decimal,
|
||||||
id_=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
):
|
) -> None:
|
||||||
self.rate_contract_id = rate_contract_id
|
self.rate_contract_id = rate_contract_id
|
||||||
self.sku_id = sku_id
|
self.sku_id = sku_id
|
||||||
self.price = price
|
self.price = price
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
@@ -2,7 +2,7 @@ import datetime
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, Date, ForeignKey, Numeric, Unicode
|
from sqlalchemy import Column, Date, ForeignKey, Numeric, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -37,26 +37,26 @@ class Recipe(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
sku_id=None,
|
recipe_yield: Decimal,
|
||||||
recipe_yield=None,
|
cost_price: Decimal,
|
||||||
cost_price=None,
|
sale_price: Decimal,
|
||||||
sale_price=None,
|
valid_from: datetime.date,
|
||||||
valid_from=None,
|
valid_till: datetime.date,
|
||||||
valid_till=None,
|
notes: str = "",
|
||||||
notes=None,
|
sku_id: Optional[uuid.UUID] = None,
|
||||||
sku=None,
|
sku: Optional["StockKeepingUnit"] = None,
|
||||||
id_=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
):
|
) -> None:
|
||||||
|
if sku_id is not None:
|
||||||
self.sku_id = sku_id
|
self.sku_id = sku_id
|
||||||
self.recipe_yield = recipe_yield
|
self.recipe_yield = recipe_yield
|
||||||
self.cost_price = cost_price
|
self.cost_price = cost_price
|
||||||
self.sale_price = sale_price
|
self.sale_price = sale_price
|
||||||
self.valid_from = valid_from
|
self.valid_from = valid_from
|
||||||
self.valid_till = valid_till
|
self.valid_till = valid_till
|
||||||
self.notes = "" if notes is None else notes
|
self.notes = notes
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
if sku is None:
|
if sku is not None:
|
||||||
self.sku_id = sku_id
|
|
||||||
else:
|
|
||||||
self.sku_id = sku.id
|
self.sku_id = sku.id
|
||||||
self.sku = sku
|
self.sku = sku
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from decimal import Decimal
|
||||||
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Numeric, UniqueConstraint
|
from sqlalchemy import Column, ForeignKey, Numeric, UniqueConstraint
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -23,20 +24,28 @@ class RecipeItem(Base):
|
|||||||
id: uuid.UUID = Column("recipe_item_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
id: uuid.UUID = Column("recipe_item_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
recipe_id: uuid.UUID = Column("recipe_id", UUID(as_uuid=True), ForeignKey("recipes.id"), nullable=False)
|
recipe_id: uuid.UUID = Column("recipe_id", UUID(as_uuid=True), ForeignKey("recipes.id"), nullable=False)
|
||||||
product_id: uuid.UUID = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
product_id: uuid.UUID = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||||
quantity: int = Column("quantity", Numeric(precision=15, scale=2), nullable=False)
|
quantity: Decimal = Column("quantity", Numeric(precision=15, scale=2), nullable=False)
|
||||||
price: int = Column("price", Numeric(precision=15, scale=5), nullable=False)
|
price: Decimal = Column("price", Numeric(precision=15, scale=5), nullable=False)
|
||||||
|
|
||||||
recipe: Mapped["Recipe"] = relationship("Recipe", back_populates="items")
|
recipe: Mapped["Recipe"] = relationship("Recipe", back_populates="items")
|
||||||
product: Mapped["Product"] = relationship("Product")
|
product: Mapped["Product"] = relationship("Product")
|
||||||
|
|
||||||
def __init__(self, recipe_id=None, product_id=None, quantity=None, price=None, recipe=None, id_=None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
product_id: uuid.UUID,
|
||||||
|
quantity: Decimal,
|
||||||
|
price: Decimal,
|
||||||
|
recipe: Optional["Recipe"] = None,
|
||||||
|
recipe_id: Optional[uuid.UUID] = None,
|
||||||
|
id_: Optional[uuid.UUID] = None,
|
||||||
|
) -> None:
|
||||||
|
if recipe_id is not None:
|
||||||
self.recipe_id = recipe_id
|
self.recipe_id = recipe_id
|
||||||
self.product_id = product_id
|
self.product_id = product_id
|
||||||
self.quantity = quantity
|
self.quantity = quantity
|
||||||
self.price = price
|
self.price = price
|
||||||
if recipe is None:
|
if recipe is not None:
|
||||||
self.recipe_id = recipe_id
|
|
||||||
else:
|
|
||||||
self.recipe_id = recipe.id
|
self.recipe_id = recipe.id
|
||||||
self.recipe = recipe
|
self.recipe = recipe
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, Unicode
|
from sqlalchemy import Column, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -26,6 +26,7 @@ class Role(Base):
|
|||||||
|
|
||||||
permissions: List["Permission"] = relationship("Permission", secondary=role_permission, back_populates="roles")
|
permissions: List["Permission"] = relationship("Permission", secondary=role_permission, back_populates="roles")
|
||||||
|
|
||||||
def __init__(self, name=None, id_=None):
|
def __init__(self, name: str, id_: Optional[uuid.UUID] = None) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
@@ -3,3 +3,4 @@ import enum
|
|||||||
|
|
||||||
class SettingType(enum.IntEnum):
|
class SettingType(enum.IntEnum):
|
||||||
VOUCHER_LOCK = 0
|
VOUCHER_LOCK = 0
|
||||||
|
MAINTENANCE_MODE = 1
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Numeric, Unicode, UniqueConstraint
|
from sqlalchemy import Column, ForeignKey, Numeric, Unicode, UniqueConstraint
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -36,15 +36,15 @@ class StockKeepingUnit(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
product_id=None,
|
units: str,
|
||||||
units=None,
|
fraction: Decimal,
|
||||||
fraction=None,
|
product_yield: Decimal,
|
||||||
product_yield=None,
|
cost_price: Decimal,
|
||||||
cost_price=None,
|
sale_price: Decimal,
|
||||||
sale_price=None,
|
product_id: Optional[uuid.UUID] = None,
|
||||||
id_=None,
|
product: Optional["Product"] = None,
|
||||||
product=None,
|
id_: Optional[uuid.UUID] = None,
|
||||||
):
|
) -> None:
|
||||||
if product_id is not None:
|
if product_id is not None:
|
||||||
self.product_id = product_id
|
self.product_id = product_id
|
||||||
self.units = units
|
self.units = units
|
||||||
@@ -52,6 +52,7 @@ class StockKeepingUnit(Base):
|
|||||||
self.product_yield = product_yield
|
self.product_yield = product_yield
|
||||||
self.cost_price = cost_price
|
self.cost_price = cost_price
|
||||||
self.sale_price = sale_price
|
self.sale_price = sale_price
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
if product is not None:
|
if product is not None:
|
||||||
self.product = product
|
self.product = product
|
||||||
@@ -24,8 +24,8 @@ class UTC(tzinfo):
|
|||||||
utc = UTC()
|
utc = UTC()
|
||||||
|
|
||||||
|
|
||||||
def get_age(old_date, now=None):
|
def get_age(old_date, now=None) -> str:
|
||||||
def is_naive(date):
|
def is_naive(date) -> bool:
|
||||||
return date.tzinfo is None or date.tzinfo.utcoffset(date) is None
|
return date.tzinfo is None or date.tzinfo.utcoffset(date) is None
|
||||||
|
|
||||||
if now is None:
|
if now is None:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from .role import Role
|
|||||||
from .user_role import user_role
|
from .user_role import user_role
|
||||||
|
|
||||||
|
|
||||||
def encrypt(val):
|
def encrypt(val: str) -> str:
|
||||||
return md5(val.encode("utf-8") + "Salt".encode("utf-8")).hexdigest()
|
return md5(val.encode("utf-8") + "Salt".encode("utf-8")).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
@@ -32,23 +32,24 @@ class User(Base):
|
|||||||
"LoginHistory", order_by=desc(LoginHistory.date), back_populates="user"
|
"LoginHistory", order_by=desc(LoginHistory.date), back_populates="user"
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_password(self):
|
def _get_password(self) -> str:
|
||||||
return self._password
|
return self._password
|
||||||
|
|
||||||
def _set_password(self, password):
|
def _set_password(self, password: str) -> None:
|
||||||
self._password = encrypt(password)
|
self._password = encrypt(password)
|
||||||
|
|
||||||
password = property(_get_password, _set_password) # type: ignore
|
password = property(_get_password, _set_password) # type: ignore
|
||||||
password = synonym("_password", descriptor=password)
|
password = synonym("_password", descriptor=password)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __name__(self):
|
def __name__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def __init__(self, name=None, password=None, locked_out=None, id_=None):
|
def __init__(self, name: str, password: str, locked_out: bool, id_: Optional[uuid.UUID] = None) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.password = password
|
self.password = password
|
||||||
self.locked_out = locked_out
|
self.locked_out = locked_out
|
||||||
|
if id_ is not None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import Boolean, Column, Date, DateTime, Enum, ForeignKey, Unicode
|
from sqlalchemy import Boolean, Column, Date, DateTime, Enum, ForeignKey, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
@@ -52,17 +52,17 @@ class Voucher(Base):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
date=None,
|
date: datetime.date,
|
||||||
is_reconciled=False,
|
voucher_type: VoucherType,
|
||||||
reconcile_date=None,
|
user_id: uuid.UUID,
|
||||||
is_starred=None,
|
narration: str = "",
|
||||||
narration="",
|
is_starred: bool = False,
|
||||||
posted=False,
|
posted: bool = False,
|
||||||
creation_date=None,
|
is_reconciled: bool = False,
|
||||||
last_edit_date=None,
|
reconcile_date: Optional[datetime.date] = None,
|
||||||
voucher_type=None,
|
poster_id: Optional[uuid.UUID] = None,
|
||||||
user_id=None,
|
creation_date: Optional[datetime.datetime] = None,
|
||||||
poster_id=None,
|
last_edit_date: Optional[datetime.datetime] = None,
|
||||||
):
|
):
|
||||||
self.date = date
|
self.date = date
|
||||||
self.is_reconciled = is_reconciled
|
self.is_reconciled = is_reconciled
|
||||||
@@ -74,4 +74,5 @@ class Voucher(Base):
|
|||||||
self.last_edit_date = last_edit_date or datetime.datetime.utcnow()
|
self.last_edit_date = last_edit_date or datetime.datetime.utcnow()
|
||||||
self.voucher_type = voucher_type
|
self.voucher_type = voucher_type
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
|
if poster_id is not None:
|
||||||
self.poster_id = poster_id
|
self.poster_id = poster_id
|
||||||
@@ -27,11 +27,11 @@ from ..schemas.user import UserToken
|
|||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.post("", response_model=schemas.Account)
|
@router.post("", response_model=None)
|
||||||
def save(
|
def save(
|
||||||
data: schemas.AccountIn,
|
data: schemas.AccountIn,
|
||||||
user: UserToken = Security(get_user, scopes=["accounts"]),
|
user: UserToken = Security(get_user, scopes=["accounts"]),
|
||||||
) -> schemas.Account:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
item = Account(
|
item = Account(
|
||||||
@@ -41,9 +41,12 @@ def save(
|
|||||||
is_active=data.is_active,
|
is_active=data.is_active,
|
||||||
is_reconcilable=data.is_reconcilable,
|
is_reconcilable=data.is_reconcilable,
|
||||||
cost_centre_id=data.cost_centre.id_,
|
cost_centre_id=data.cost_centre.id_,
|
||||||
).create(db)
|
)
|
||||||
|
item.code = db.execute(
|
||||||
|
select(func.coalesce(func.max(Account.code), 0) + 1).where(Account.type_id == item.type_id)
|
||||||
|
).scalar_one()
|
||||||
|
db.add(item)
|
||||||
db.commit()
|
db.commit()
|
||||||
return account_info(item)
|
|
||||||
except SQLAlchemyError as e:
|
except SQLAlchemyError as e:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
@@ -51,12 +54,12 @@ def save(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.put("/{id_}", response_model=schemas.Account)
|
@router.put("/{id_}", response_model=None)
|
||||||
def update_route(
|
def update_route(
|
||||||
id_: uuid.UUID,
|
id_: uuid.UUID,
|
||||||
data: schemas.AccountIn,
|
data: schemas.AccountIn,
|
||||||
user: UserToken = Security(get_user, scopes=["accounts"]),
|
user: UserToken = Security(get_user, scopes=["accounts"]),
|
||||||
) -> schemas.Account:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
item: Account = db.execute(select(Account).where(Account.id == id_)).scalar_one()
|
item: Account = db.execute(select(Account).where(Account.id == id_)).scalar_one()
|
||||||
@@ -74,7 +77,6 @@ def update_route(
|
|||||||
item.is_starred = data.is_starred
|
item.is_starred = data.is_starred
|
||||||
item.cost_centre_id = data.cost_centre.id_
|
item.cost_centre_id = data.cost_centre.id_
|
||||||
db.commit()
|
db.commit()
|
||||||
return account_info(item)
|
|
||||||
except SQLAlchemyError as e:
|
except SQLAlchemyError as e:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
@@ -125,19 +127,31 @@ async def show_list(user: UserToken = Depends(get_user)) -> List[schemas.Account
|
|||||||
@router.get("/query", response_model=List[schemas.AccountLink])
|
@router.get("/query", response_model=List[schemas.AccountLink])
|
||||||
async def show_term(
|
async def show_term(
|
||||||
q: str,
|
q: str,
|
||||||
t: int = None,
|
t: int = None, # AccountType
|
||||||
r: bool = None,
|
r: bool = None, # Reconcilable
|
||||||
a: bool = None,
|
a: bool = None, # Active
|
||||||
c: int = None,
|
c: int = None, # Count
|
||||||
current_user: UserToken = Depends(get_user),
|
current_user: UserToken = Depends(get_user),
|
||||||
) -> List[schemas.AccountLink]:
|
) -> List[schemas.AccountLink]:
|
||||||
count = c
|
|
||||||
list_: List[schemas.AccountLink] = []
|
list_: List[schemas.AccountLink] = []
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
for index, item in enumerate(AccountBase.query(q, t, r, a, db)):
|
query_ = select(AccountBase)
|
||||||
|
if t is not None:
|
||||||
|
query_ = query_.where(AccountBase.type_id == t)
|
||||||
|
if r is not None:
|
||||||
|
query_ = query_.where(AccountBase.is_reconcilable == r)
|
||||||
|
if a is not None:
|
||||||
|
query_ = query_.where(AccountBase.is_active == a)
|
||||||
|
if q is not None:
|
||||||
|
for name in q.split():
|
||||||
|
query_ = query_.where(AccountBase.name.ilike(f"%{name}%"))
|
||||||
|
query_ = query_.order_by(AccountBase.name)
|
||||||
|
if c is not None:
|
||||||
|
query_ = query_.limit(c)
|
||||||
|
data: List[AccountBase] = db.execute(query_).scalars().all()
|
||||||
|
|
||||||
|
for item in data:
|
||||||
list_.append(schemas.AccountLink(id=item.id, name=item.name))
|
list_.append(schemas.AccountLink(id=item.id, name=item.name))
|
||||||
if count is not None and index == count - 1:
|
|
||||||
break
|
|
||||||
return list_
|
return list_
|
||||||
|
|
||||||
|
|
||||||
@@ -229,6 +243,7 @@ def delete_with_data(account: Account, db: Session) -> None:
|
|||||||
if not others:
|
if not others:
|
||||||
db.delete(voucher)
|
db.delete(voucher)
|
||||||
else:
|
else:
|
||||||
|
assert acc_jnl is not None
|
||||||
if sus_jnl is None:
|
if sus_jnl is None:
|
||||||
acc_jnl.account = suspense_account
|
acc_jnl.account = suspense_account
|
||||||
voucher.narration += f"\nSuspense \u20B9{acc_jnl.amount:,.2f} is {account.name}"
|
voucher.narration += f"\nSuspense \u20B9{acc_jnl.amount:,.2f} is {account.name}"
|
||||||
|
|||||||
@@ -76,8 +76,9 @@ def salary_journals(start_date: date, finish_date: date, db: Session) -> List[Jo
|
|||||||
.scalars()
|
.scalars()
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
att = sum([AttendanceType.by_id(x.attendance_type).value for x in attendances])
|
att: Decimal
|
||||||
att = round(att * employee.salary / days)
|
att = sum(AttendanceType.by_id(x.attendance_type).value for x in attendances) # type: ignore[assignment]
|
||||||
|
att = round(att * employee.salary / days) # type: ignore[assignment]
|
||||||
if att != 0:
|
if att != 0:
|
||||||
amount += att
|
amount += att
|
||||||
journals.append(
|
journals.append(
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ def save(
|
|||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
item = Employee(
|
item = Employee(
|
||||||
name=data.name,
|
name=data.name,
|
||||||
|
code=None,
|
||||||
is_starred=data.is_starred,
|
is_starred=data.is_starred,
|
||||||
is_active=data.is_active,
|
is_active=data.is_active,
|
||||||
cost_centre_id=data.cost_centre.id_,
|
cost_centre_id=data.cost_centre.id_,
|
||||||
@@ -135,7 +136,16 @@ async def show_term(
|
|||||||
) -> List[schemas.EmployeeLink]:
|
) -> List[schemas.EmployeeLink]:
|
||||||
list_: List[schemas.EmployeeLink] = []
|
list_: List[schemas.EmployeeLink] = []
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
for index, item in enumerate(Employee.query(q=q, type_=10, reconcilable=None, active=None, db=db)):
|
query_ = select(Employee)
|
||||||
|
if q is not None:
|
||||||
|
for name in q.split():
|
||||||
|
query_ = query_.where(Employee.name.ilike(f"%{name}%"))
|
||||||
|
query_ = query_.order_by(Employee.name)
|
||||||
|
if c is not None:
|
||||||
|
query_ = query_.limit(c)
|
||||||
|
data: List[Employee] = db.execute(query_).scalars().all()
|
||||||
|
|
||||||
|
for item in data:
|
||||||
list_.append(
|
list_.append(
|
||||||
schemas.EmployeeLink(
|
schemas.EmployeeLink(
|
||||||
id=item.id,
|
id=item.id,
|
||||||
@@ -147,8 +157,6 @@ async def show_term(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if c is not None and index == c - 1:
|
|
||||||
break
|
|
||||||
return list_
|
return list_
|
||||||
|
|
||||||
|
|
||||||
@@ -220,6 +228,7 @@ def delete_with_data(employee: Employee, db: Session) -> None:
|
|||||||
if not others:
|
if not others:
|
||||||
db.delete(voucher)
|
db.delete(voucher)
|
||||||
else:
|
else:
|
||||||
|
assert acc_jnl is not None
|
||||||
if sus_jnl is None:
|
if sus_jnl is None:
|
||||||
acc_jnl.account = suspense_account
|
acc_jnl.account = suspense_account
|
||||||
voucher.narration += f"\nSuspense \u20B9 {acc_jnl.amount:,.2f} is {employee.name}"
|
voucher.narration += f"\nSuspense \u20B9 {acc_jnl.amount:,.2f} is {employee.name}"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
|
from decimal import Decimal
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ def save_employee_benefits(
|
|||||||
esi_ee, esi_er, esi_both = esi_contribution(gross_salary, days_worked, days_in_month)
|
esi_ee, esi_er, esi_both = esi_contribution(gross_salary, days_worked, days_in_month)
|
||||||
pf_ee, pf_er, pf_both = pf_contribution(gross_salary, days_worked, days_in_month)
|
pf_ee, pf_er, pf_both = pf_contribution(gross_salary, days_worked, days_in_month)
|
||||||
journal = Journal(
|
journal = Journal(
|
||||||
amount=esi_ee + pf_ee,
|
amount=Decimal(esi_ee + pf_ee),
|
||||||
debit=1,
|
debit=1,
|
||||||
account_id=account.id,
|
account_id=account.id,
|
||||||
cost_centre_id=account.cost_centre_id,
|
cost_centre_id=account.cost_centre_id,
|
||||||
@@ -128,7 +129,7 @@ def save_employee_benefits(
|
|||||||
def save_journals(voucher: Voucher, exp: int, total: int, db: Session) -> None:
|
def save_journals(voucher: Voucher, exp: int, total: int, db: Session) -> None:
|
||||||
account = db.execute(select(AccountBase).where(AccountBase.id == AccountBase.esi_pf_expense())).scalar_one()
|
account = db.execute(select(AccountBase).where(AccountBase.id == AccountBase.esi_pf_expense())).scalar_one()
|
||||||
journal = Journal(
|
journal = Journal(
|
||||||
amount=exp,
|
amount=Decimal(exp),
|
||||||
debit=1,
|
debit=1,
|
||||||
account_id=account.id,
|
account_id=account.id,
|
||||||
cost_centre_id=account.cost_centre_id,
|
cost_centre_id=account.cost_centre_id,
|
||||||
@@ -137,7 +138,7 @@ def save_journals(voucher: Voucher, exp: int, total: int, db: Session) -> None:
|
|||||||
voucher.journals.append(journal)
|
voucher.journals.append(journal)
|
||||||
account = db.execute(select(AccountBase).where(AccountBase.id == AccountBase.esi_pf_payable())).scalar_one()
|
account = db.execute(select(AccountBase).where(AccountBase.id == AccountBase.esi_pf_payable())).scalar_one()
|
||||||
journal = Journal(
|
journal = Journal(
|
||||||
amount=total,
|
amount=Decimal(total),
|
||||||
debit=-1,
|
debit=-1,
|
||||||
account_id=account.id,
|
account_id=account.id,
|
||||||
cost_centre_id=account.cost_centre_id,
|
cost_centre_id=account.cost_centre_id,
|
||||||
|
|||||||
@@ -92,9 +92,9 @@ def save_incentives(
|
|||||||
point_value: Decimal,
|
point_value: Decimal,
|
||||||
db: Session,
|
db: Session,
|
||||||
) -> None:
|
) -> None:
|
||||||
total_amount = 0
|
total_amount = Decimal(0)
|
||||||
for item in employees:
|
for item in employees:
|
||||||
item_amount = round(item.points * item.days_worked * point_value)
|
item_amount = Decimal(round(item.points * item.days_worked * point_value))
|
||||||
journal = Journal(
|
journal = Journal(
|
||||||
amount=item_amount,
|
amount=item_amount,
|
||||||
debit=-1,
|
debit=-1,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from sqlalchemy.orm import Session
|
|||||||
from ..core.security import get_current_active_user as get_user
|
from ..core.security import get_current_active_user as get_user
|
||||||
from ..db.session import SessionFuture
|
from ..db.session import SessionFuture
|
||||||
from ..models.db_setting import DbSetting
|
from ..models.db_setting import DbSetting
|
||||||
|
from ..models.setting_type import SettingType
|
||||||
from ..models.user import User
|
from ..models.user import User
|
||||||
from ..schemas.settings import Maintenance
|
from ..schemas.settings import Maintenance
|
||||||
from ..schemas.user import UserToken
|
from ..schemas.user import UserToken
|
||||||
@@ -33,14 +34,19 @@ def set_maintenance(
|
|||||||
maintenance: Optional[DbSetting] = db.execute(
|
maintenance: Optional[DbSetting] = db.execute(
|
||||||
select(DbSetting).where(DbSetting.name == "Maintenance")
|
select(DbSetting).where(DbSetting.name == "Maintenance")
|
||||||
).scalar_one_or_none()
|
).scalar_one_or_none()
|
||||||
if data.enabled is False and maintenance is not None:
|
if maintenance is None:
|
||||||
|
if data.enabled:
|
||||||
|
maintenance = DbSetting(
|
||||||
|
name="Maintenance", setting_type=SettingType.MAINTENANCE_MODE, data={"id": user.id_}
|
||||||
|
)
|
||||||
|
db.add(maintenance)
|
||||||
|
else:
|
||||||
|
if not data.enabled:
|
||||||
db.delete(maintenance)
|
db.delete(maintenance)
|
||||||
maintenance = None
|
maintenance = None
|
||||||
elif data.enabled is True and maintenance is None:
|
else:
|
||||||
maintenance = DbSetting(name="Maintenance", data=user.id_)
|
if maintenance.data["id"] != user.id_:
|
||||||
db.add(maintenance)
|
maintenance.data = {"id": user.id_}
|
||||||
elif data.enabled is True and maintenance.data != user.id_:
|
|
||||||
maintenance.data = user.id_
|
|
||||||
db.commit()
|
db.commit()
|
||||||
return info(maintenance, db)
|
return info(maintenance, db)
|
||||||
|
|
||||||
@@ -48,5 +54,5 @@ def set_maintenance(
|
|||||||
def info(data: Optional[DbSetting], db: Session) -> Maintenance:
|
def info(data: Optional[DbSetting], db: Session) -> Maintenance:
|
||||||
if data is None:
|
if data is None:
|
||||||
return Maintenance(enabled=False, user="")
|
return Maintenance(enabled=False, user="")
|
||||||
user = db.execute(select(User).where(User.id == data.data)).scalar_one()
|
user = db.execute(select(User).where(User.id == data.data["id"])).scalar_one()
|
||||||
return Maintenance(enabled=True, user=user.name)
|
return Maintenance(enabled=True, user=user.name)
|
||||||
@@ -166,7 +166,7 @@ def save_journals(voucher: Voucher, ven: schema_in.AccountLink, db: Session) ->
|
|||||||
debit=-1,
|
debit=-1,
|
||||||
cost_centre_id=vendor.cost_centre_id,
|
cost_centre_id=vendor.cost_centre_id,
|
||||||
account_id=vendor.id,
|
account_id=vendor.id,
|
||||||
amount=amount,
|
amount=amount, # type: ignore[arg-type]
|
||||||
)
|
)
|
||||||
for item in journals.values():
|
for item in journals.values():
|
||||||
voucher.journals.append(item)
|
voucher.journals.append(item)
|
||||||
@@ -315,7 +315,7 @@ def update_journals(voucher: Voucher, ven: schema_in.AccountLink, db: Session) -
|
|||||||
debit=1,
|
debit=1,
|
||||||
cost_centre_id=cc_id,
|
cost_centre_id=cc_id,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
amount=i_item.amount,
|
amount=i_item.amount, # type: ignore[arg-type]
|
||||||
)
|
)
|
||||||
journals[vendor.id] = Journal(
|
journals[vendor.id] = Journal(
|
||||||
debit=-1,
|
debit=-1,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from decimal import Decimal
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
import brewman.schemas.input as schema_in
|
import brewman.schemas.input as schema_in
|
||||||
@@ -133,7 +134,7 @@ def save_inventories(voucher: Voucher, inventories: List[InventorySchema], db: S
|
|||||||
def save_journals(voucher: Voucher, ven: schema_in.AccountLink, db: Session) -> None:
|
def save_journals(voucher: Voucher, ven: schema_in.AccountLink, db: Session) -> None:
|
||||||
vendor = db.execute(select(AccountBase).where(AccountBase.id == ven.id_)).scalar_one()
|
vendor = db.execute(select(AccountBase).where(AccountBase.id == ven.id_)).scalar_one()
|
||||||
journals: Dict[uuid.UUID, Journal] = {}
|
journals: Dict[uuid.UUID, Journal] = {}
|
||||||
amount = 0
|
amount = Decimal(0)
|
||||||
for v_item in voucher.inventories:
|
for v_item in voucher.inventories:
|
||||||
account_id, cc_id = db.execute(
|
account_id, cc_id = db.execute(
|
||||||
select(AccountBase.id, AccountBase.cost_centre_id)
|
select(AccountBase.id, AccountBase.cost_centre_id)
|
||||||
@@ -264,7 +265,7 @@ def update_inventory(voucher: Voucher, new_inventories: List[InventorySchema], d
|
|||||||
def update_journals(voucher: Voucher, ven: schema_in.AccountLink, db: Session) -> None:
|
def update_journals(voucher: Voucher, ven: schema_in.AccountLink, db: Session) -> None:
|
||||||
vendor = db.execute(select(AccountBase).where(AccountBase.id == ven.id_)).scalar_one()
|
vendor = db.execute(select(AccountBase).where(AccountBase.id == ven.id_)).scalar_one()
|
||||||
journals: Dict[uuid.UUID, Journal] = {}
|
journals: Dict[uuid.UUID, Journal] = {}
|
||||||
amount = 0
|
amount = Decimal(0)
|
||||||
for v_item in voucher.inventories:
|
for v_item in voucher.inventories:
|
||||||
account_id, cc_id = db.execute(
|
account_id, cc_id = db.execute(
|
||||||
select(AccountBase.id, AccountBase.cost_centre_id)
|
select(AccountBase.id, AccountBase.cost_centre_id)
|
||||||
@@ -280,7 +281,7 @@ def update_journals(voucher: Voucher, ven: schema_in.AccountLink, db: Session) -
|
|||||||
debit=-1,
|
debit=-1,
|
||||||
cost_centre_id=cc_id,
|
cost_centre_id=cc_id,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
amount=v_item.amount,
|
amount=v_item.amount, # type: ignore[arg-type]
|
||||||
)
|
)
|
||||||
journals[vendor.id] = Journal(
|
journals[vendor.id] = Journal(
|
||||||
debit=1,
|
debit=1,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from ..models.rate_contract_item import RateContractItem
|
|||||||
from ..schemas.product import ProductLink
|
from ..schemas.product import ProductLink
|
||||||
from ..schemas.rate_contract import AccountLink
|
from ..schemas.rate_contract import AccountLink
|
||||||
from ..schemas.rate_contract import RateContract as RateContractSchema
|
from ..schemas.rate_contract import RateContract as RateContractSchema
|
||||||
from ..schemas.rate_contract import RateContractIn as RateContractInSchema
|
from ..schemas.rate_contract import RateContractBlank, RateContractIn
|
||||||
from ..schemas.rate_contract import RateContractItem as RateContractItemSchema
|
from ..schemas.rate_contract import RateContractItem as RateContractItemSchema
|
||||||
from ..schemas.user import UserToken
|
from ..schemas.user import UserToken
|
||||||
from ..schemas.user_link import UserLink
|
from ..schemas.user_link import UserLink
|
||||||
@@ -32,7 +32,7 @@ router = APIRouter()
|
|||||||
|
|
||||||
@router.post("", response_model=RateContractSchema)
|
@router.post("", response_model=RateContractSchema)
|
||||||
async def save(
|
async def save(
|
||||||
data: RateContractInSchema,
|
data: RateContractIn,
|
||||||
request: Request,
|
request: Request,
|
||||||
user: UserToken = Security(get_user, scopes=["rate-contracts"]),
|
user: UserToken = Security(get_user, scopes=["rate-contracts"]),
|
||||||
) -> RateContractSchema:
|
) -> RateContractSchema:
|
||||||
@@ -69,7 +69,7 @@ def add_items(rate_contract: RateContract, items: List[RateContractItemSchema],
|
|||||||
@router.put("/{id_}", response_model=RateContractSchema)
|
@router.put("/{id_}", response_model=RateContractSchema)
|
||||||
async def update_route(
|
async def update_route(
|
||||||
id_: uuid.UUID,
|
id_: uuid.UUID,
|
||||||
data: RateContractInSchema,
|
data: RateContractIn,
|
||||||
request: Request,
|
request: Request,
|
||||||
user: UserToken = Security(get_user, scopes=["rate-contracts"]),
|
user: UserToken = Security(get_user, scopes=["rate-contracts"]),
|
||||||
) -> RateContractSchema:
|
) -> RateContractSchema:
|
||||||
@@ -108,12 +108,12 @@ def update_items(rate_contract: RateContract, items: List[RateContractItemSchema
|
|||||||
add_items(rate_contract, items, db)
|
add_items(rate_contract, items, db)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{id_}", response_model=RateContractInSchema)
|
@router.delete("/{id_}", response_model=RateContractBlank)
|
||||||
async def delete_route(
|
async def delete_route(
|
||||||
id_: uuid.UUID,
|
id_: uuid.UUID,
|
||||||
request: Request,
|
request: Request,
|
||||||
user: UserToken = Security(get_user, scopes=["rate-contracts"]),
|
user: UserToken = Security(get_user, scopes=["rate-contracts"]),
|
||||||
) -> RateContractInSchema:
|
) -> RateContractBlank:
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
db.execute(delete(RateContractItem).where(RateContractItem.rate_contract_id == id_))
|
db.execute(delete(RateContractItem).where(RateContractItem.rate_contract_id == id_))
|
||||||
db.execute(delete(RateContract).where(RateContract.id == id_))
|
db.execute(delete(RateContract).where(RateContract.id == id_))
|
||||||
@@ -121,11 +121,11 @@ async def delete_route(
|
|||||||
return rate_contract_blank(request.session)
|
return rate_contract_blank(request.session)
|
||||||
|
|
||||||
|
|
||||||
@router.get("", response_model=RateContractInSchema)
|
@router.get("", response_model=RateContractBlank)
|
||||||
async def show_blank(
|
async def show_blank(
|
||||||
request: Request,
|
request: Request,
|
||||||
user: UserToken = Security(get_user, scopes=["rate-contracts"]),
|
user: UserToken = Security(get_user, scopes=["rate-contracts"]),
|
||||||
) -> RateContractInSchema:
|
) -> RateContractBlank:
|
||||||
return rate_contract_blank(request.session)
|
return rate_contract_blank(request.session)
|
||||||
|
|
||||||
|
|
||||||
@@ -174,8 +174,8 @@ def rate_contract_info(item: RateContract) -> RateContractSchema:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def rate_contract_blank(session: dict) -> RateContractInSchema:
|
def rate_contract_blank(session: dict) -> RateContractBlank:
|
||||||
return RateContractInSchema(
|
return RateContractBlank(
|
||||||
date=get_date(session),
|
date=get_date(session),
|
||||||
validFrom=get_start_date(session),
|
validFrom=get_start_date(session),
|
||||||
validTill=get_finish_date(session),
|
validTill=get_finish_date(session),
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ def opening_accounts(date_: date, user_id: uuid.UUID, db: Session) -> Voucher:
|
|||||||
|
|
||||||
|
|
||||||
def opening_batches(date_: date, user_id: uuid.UUID, db: Session) -> Voucher:
|
def opening_batches(date_: date, user_id: uuid.UUID, db: Session) -> Voucher:
|
||||||
total = 0
|
total = Decimal(0)
|
||||||
sum_func = func.sum(Journal.debit * Inventory.quantity)
|
sum_func = func.sum(Journal.debit * Inventory.quantity)
|
||||||
query = db.execute(
|
query = db.execute(
|
||||||
select(Batch, sum_func)
|
select(Batch, sum_func)
|
||||||
@@ -173,8 +173,9 @@ def opening_batches(date_: date, user_id: uuid.UUID, db: Session) -> Voucher:
|
|||||||
voucher_type=VoucherType.OPENING_BATCHES,
|
voucher_type=VoucherType.OPENING_BATCHES,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
quantity: Decimal
|
||||||
for batch, quantity in query:
|
for batch, quantity in query:
|
||||||
quantity = round(Decimal(quantity), 2)
|
quantity = round(quantity, 2)
|
||||||
if quantity != 0:
|
if quantity != 0:
|
||||||
total += quantity * batch.rate * (1 + batch.tax) * (1 - batch.discount)
|
total += quantity * batch.rate * (1 + batch.tax) * (1 - batch.discount)
|
||||||
inventory = Inventory(
|
inventory = Inventory(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional, Set
|
from typing import List, Optional
|
||||||
|
|
||||||
import brewman.schemas.recipe as schemas
|
import brewman.schemas.recipe as schemas
|
||||||
import brewman.schemas.recipe_item
|
import brewman.schemas.recipe_item
|
||||||
@@ -76,6 +76,7 @@ def save(
|
|||||||
sale_price=round(data.sale_price, 2),
|
sale_price=round(data.sale_price, 2),
|
||||||
valid_from=data.valid_from,
|
valid_from=data.valid_from,
|
||||||
valid_till=data.valid_till,
|
valid_till=data.valid_till,
|
||||||
|
cost_price=Decimal(0),
|
||||||
)
|
)
|
||||||
recipe_cost = Decimal(0)
|
recipe_cost = Decimal(0)
|
||||||
for item in data.items:
|
for item in data.items:
|
||||||
@@ -87,7 +88,7 @@ def save(
|
|||||||
ingredient_cost = get_sub_product_cost(product, data.valid_from, data.valid_till, db)
|
ingredient_cost = get_sub_product_cost(product, data.valid_from, data.valid_till, db)
|
||||||
# ingredient_cost = get_purchased_product_cost(product.id, data.valid_from, data.valid_till, db)
|
# ingredient_cost = get_purchased_product_cost(product.id, data.valid_from, data.valid_till, db)
|
||||||
recipe_cost += round(ingredient_cost * quantity, 2)
|
recipe_cost += round(ingredient_cost * quantity, 2)
|
||||||
recipe.items.append(RecipeItem(None, product.id, quantity, ingredient_cost))
|
recipe.items.append(RecipeItem(product.id, quantity, ingredient_cost))
|
||||||
|
|
||||||
recipe.cost_price = round(recipe_cost / recipe.recipe_yield, 2)
|
recipe.cost_price = round(recipe_cost / recipe.recipe_yield, 2)
|
||||||
recipe_sku.cost_price = round(recipe.cost_price / recipe.recipe_yield, 2)
|
recipe_sku.cost_price = round(recipe.cost_price / recipe.recipe_yield, 2)
|
||||||
@@ -185,7 +186,7 @@ async def update_route(
|
|||||||
# ingredient_cost = get_purchased_product_cost(product.id, data.valid_from, data.valid_till, db)
|
# ingredient_cost = get_purchased_product_cost(product.id, data.valid_from, data.valid_till, db)
|
||||||
|
|
||||||
recipe_cost += round(ingredient_cost * quantity, 2)
|
recipe_cost += round(ingredient_cost * quantity, 2)
|
||||||
recipe.items.append(RecipeItem(None, product.id, quantity, ingredient_cost))
|
recipe.items.append(RecipeItem(product.id, quantity, ingredient_cost))
|
||||||
|
|
||||||
recipe.cost_price = round(recipe_cost / recipe.recipe_yield, 2)
|
recipe.cost_price = round(recipe_cost / recipe.recipe_yield, 2)
|
||||||
sku.cost_price = round(recipe.cost_price / recipe.recipe_yield, 2)
|
sku.cost_price = round(recipe.cost_price / recipe.recipe_yield, 2)
|
||||||
@@ -301,7 +302,7 @@ def update_old_rows(sku_id: uuid.UUID, valid_from: date, valid_till: date, db: S
|
|||||||
valid_till=valid_from - timedelta(days=1),
|
valid_till=valid_from - timedelta(days=1),
|
||||||
)
|
)
|
||||||
for ri in item.items:
|
for ri in item.items:
|
||||||
recipe.items.append(RecipeItem(None, ri.product_id, ri.quantity, ri.price))
|
recipe.items.append(RecipeItem(ri.product_id, ri.quantity, ri.price))
|
||||||
new_recipes.append(recipe)
|
new_recipes.append(recipe)
|
||||||
if item.valid_till > valid_till:
|
if item.valid_till > valid_till:
|
||||||
recipe = Recipe(
|
recipe = Recipe(
|
||||||
@@ -313,7 +314,7 @@ def update_old_rows(sku_id: uuid.UUID, valid_from: date, valid_till: date, db: S
|
|||||||
valid_till=item.valid_till,
|
valid_till=item.valid_till,
|
||||||
)
|
)
|
||||||
for ri in item.items:
|
for ri in item.items:
|
||||||
recipe.items.append(RecipeItem(None, ri.product_id, ri.quantity, ri.price))
|
recipe.items.append(RecipeItem(ri.product_id, ri.quantity, ri.price))
|
||||||
new_recipes.append(recipe)
|
new_recipes.append(recipe)
|
||||||
|
|
||||||
for recipe in new_recipes:
|
for recipe in new_recipes:
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ def delete_voucher(
|
|||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
db.execute(
|
db.execute(
|
||||||
delete(ClosingStock)
|
delete(ClosingStock)
|
||||||
.where(ClosingStock.date == date_, ClosingStock.cost_centre_id == cost_centre_id)
|
.where(ClosingStock.date_ == date_, ClosingStock.cost_centre_id == cost_centre_id)
|
||||||
.execution_options(synchronize_session=False)
|
.execution_options(synchronize_session=False)
|
||||||
)
|
)
|
||||||
delete_old_vouchers(datetime.strptime(date_, "%d-%b-%Y").date(), cost_centre_id, db)
|
delete_old_vouchers(datetime.strptime(date_, "%d-%b-%Y").date(), cost_centre_id, db)
|
||||||
@@ -159,7 +159,7 @@ def build_report(date_: date, cost_centre_id: uuid.UUID, db: Session) -> List[sc
|
|||||||
|
|
||||||
physical_list = (
|
physical_list = (
|
||||||
db.execute(
|
db.execute(
|
||||||
select(ClosingStock).where(ClosingStock.date == date_, ClosingStock.cost_centre_id == cost_centre_id)
|
select(ClosingStock).where(ClosingStock.date_ == date_, ClosingStock.cost_centre_id == cost_centre_id)
|
||||||
)
|
)
|
||||||
.scalars()
|
.scalars()
|
||||||
.all()
|
.all()
|
||||||
@@ -255,7 +255,7 @@ def save_route(
|
|||||||
detail="Products with change in quantity need a department",
|
detail="Products with change in quantity need a department",
|
||||||
)
|
)
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
count_ = db.execute(select(func.count()).where(ClosingStock.date == data.date_)).scalar_one()
|
count_ = db.execute(select(func.count()).where(ClosingStock.date_ == data.date_)).scalar_one()
|
||||||
if count_ == 0:
|
if count_ == 0:
|
||||||
save_cs(data, db)
|
save_cs(data, db)
|
||||||
else:
|
else:
|
||||||
@@ -265,7 +265,7 @@ def save_route(
|
|||||||
items = [d for d in data.items if d.cost_centre is not None and d.cost_centre.id_ == dep]
|
items = [d for d in data.items if d.cost_centre is not None and d.cost_centre.id_ == dep]
|
||||||
item = save(data.date_, items, user, db)
|
item = save(data.date_, items, user, db)
|
||||||
save_inventories(item, items, db)
|
save_inventories(item, items, db)
|
||||||
amount: Decimal = sum(i.amount for i in item.inventories) # type: ignore[assignment]
|
amount: Decimal = sum(i.amount for i in item.inventories) # type: ignore[assignment, misc]
|
||||||
save_journals(item, data.cost_centre.id_, dep, amount, db)
|
save_journals(item, data.cost_centre.id_, dep, amount, db)
|
||||||
check_journals_are_valid(item)
|
check_journals_are_valid(item)
|
||||||
db.commit()
|
db.commit()
|
||||||
@@ -356,7 +356,7 @@ def save_journals(
|
|||||||
def update_cs(date_: date, cost_centre_id: uuid.UUID, items: List[schemas.ClosingStockItem], db: Session) -> None:
|
def update_cs(date_: date, cost_centre_id: uuid.UUID, items: List[schemas.ClosingStockItem], db: Session) -> None:
|
||||||
old = (
|
old = (
|
||||||
db.execute(
|
db.execute(
|
||||||
select(ClosingStock).where(ClosingStock.date == date_, ClosingStock.cost_centre_id == cost_centre_id)
|
select(ClosingStock).where(ClosingStock.date_ == date_, ClosingStock.cost_centre_id == cost_centre_id)
|
||||||
)
|
)
|
||||||
.scalars()
|
.scalars()
|
||||||
.all()
|
.all()
|
||||||
|
|||||||
@@ -146,11 +146,11 @@ def delete_voucher(
|
|||||||
i_item.batch.quantity_remaining -= i_item.quantity
|
i_item.batch.quantity_remaining -= i_item.quantity
|
||||||
elif voucher.voucher_type == VoucherType.PURCHASE:
|
elif voucher.voucher_type == VoucherType.PURCHASE:
|
||||||
for i_item in voucher.inventories:
|
for i_item in voucher.inventories:
|
||||||
uses = db.execute(
|
uses: int = db.execute(
|
||||||
select(func.count(Inventory.id)).where(
|
select(func.count(Inventory.id)).where(
|
||||||
Inventory.batch_id == i_item.batch.id, Inventory.id != i_item.id
|
Inventory.batch_id == i_item.batch.id, Inventory.id != i_item.id
|
||||||
)
|
)
|
||||||
).scalar()
|
).scalar_one()
|
||||||
if uses > 0:
|
if uses > 0:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_423_LOCKED,
|
status_code=status.HTTP_423_LOCKED,
|
||||||
@@ -321,7 +321,7 @@ def blank_voucher(info: BlankVoucherInfo, db: Session) -> output.Voucher:
|
|||||||
if account is not None:
|
if account is not None:
|
||||||
j_account = output.AccountLink(id=account.id, name=account.name)
|
j_account = output.AccountLink(id=account.id, name=account.name)
|
||||||
else:
|
else:
|
||||||
j_account = output.AccountLink(id=AccountBase.cash_in_hand()["id"], name=AccountBase.cash_in_hand()["name"])
|
j_account = AccountBase.cash_in_hand()
|
||||||
json_voucher.journals.append(output.Journal(account=j_account, amount=0, debit=-1))
|
json_voucher.journals.append(output.Journal(account=j_account, amount=0, debit=-1))
|
||||||
elif info.type_ == VoucherType.RECEIPT:
|
elif info.type_ == VoucherType.RECEIPT:
|
||||||
account = None
|
account = None
|
||||||
@@ -330,16 +330,12 @@ def blank_voucher(info: BlankVoucherInfo, db: Session) -> output.Voucher:
|
|||||||
if account is not None:
|
if account is not None:
|
||||||
j_account = output.AccountLink(id=account.id, name=account.name)
|
j_account = output.AccountLink(id=account.id, name=account.name)
|
||||||
else:
|
else:
|
||||||
j_account = output.AccountLink(id=AccountBase.cash_in_hand()["id"], name=AccountBase.cash_in_hand()["name"])
|
j_account = AccountBase.cash_in_hand()
|
||||||
json_voucher.journals.append(output.Journal(account=j_account, amount=0, debit=1))
|
json_voucher.journals.append(output.Journal(account=j_account, amount=0, debit=1))
|
||||||
elif info.type_ == VoucherType.PURCHASE:
|
elif info.type_ == VoucherType.PURCHASE:
|
||||||
json_voucher.vendor = output.AccountLink(
|
json_voucher.vendor = AccountBase.local_purchase()
|
||||||
id=AccountBase.local_purchase()["id"], name=AccountBase.local_purchase()["name"]
|
|
||||||
)
|
|
||||||
elif info.type_ == VoucherType.PURCHASE_RETURN:
|
elif info.type_ == VoucherType.PURCHASE_RETURN:
|
||||||
json_voucher.vendor = output.AccountLink(
|
json_voucher.vendor = AccountBase.local_purchase()
|
||||||
id=AccountBase.local_purchase()["id"], name=AccountBase.local_purchase()["name"]
|
|
||||||
)
|
|
||||||
elif info.type_ == VoucherType.ISSUE:
|
elif info.type_ == VoucherType.ISSUE:
|
||||||
if info.source is not None:
|
if info.source is not None:
|
||||||
json_voucher.source = output.CostCentreLink(id=info.source.id_)
|
json_voucher.source = output.CostCentreLink(id=info.source.id_)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from brewman.schemas.attendance_type import AttendanceType
|
from brewman.schemas.attendance_type import AttendanceType
|
||||||
@@ -28,7 +28,7 @@ class Attendance(BaseModel):
|
|||||||
body: List[AttendanceItem]
|
body: List[AttendanceItem]
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -31,7 +31,7 @@ class BalanceSheet(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List
|
from typing import List, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -23,7 +23,7 @@ class BatchIntegrityItem(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -44,7 +44,7 @@ class BatchIntegrity(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from typing import Optional
|
from typing import Optional, Union
|
||||||
|
|
||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ class BlankVoucherInfo(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value) -> date:
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import Field, validator
|
from pydantic import Field, validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -41,13 +41,13 @@ class CashFlow(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -29,7 +29,7 @@ class ClosingStockItem(BaseModel):
|
|||||||
|
|
||||||
class ClosingStock(BaseModel):
|
class ClosingStock(BaseModel):
|
||||||
date_: date
|
date_: date
|
||||||
cost_centre: Optional[CostCentreLink]
|
cost_centre: CostCentreLink
|
||||||
items: List[ClosingStockItem]
|
items: List[ClosingStockItem]
|
||||||
creation_date: Optional[datetime]
|
creation_date: Optional[datetime]
|
||||||
last_edit_date: Optional[datetime]
|
last_edit_date: Optional[datetime]
|
||||||
@@ -43,13 +43,13 @@ class ClosingStock(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y"), datetime: lambda v: v.strftime("%d-%b-%Y %H:%M")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y"), datetime: lambda v: v.strftime("%d-%b-%Y %H:%M")}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value) -> date:
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("creation_date", pre=True)
|
@validator("creation_date", pre=True)
|
||||||
def parse_creation_date(cls, value) -> Optional[datetime]:
|
def parse_creation_date(cls, value: Union[None, datetime, str]) -> Optional[datetime]:
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
@@ -57,7 +57,7 @@ class ClosingStock(BaseModel):
|
|||||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||||
|
|
||||||
@validator("last_edit_date", pre=True)
|
@validator("last_edit_date", pre=True)
|
||||||
def parse_last_edit_date(cls, value) -> Optional[datetime]:
|
def parse_last_edit_date(cls, value: Union[None, datetime, str]) -> Optional[datetime]:
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -23,7 +23,7 @@ class DaybookItem(BaseModel):
|
|||||||
posted: bool
|
posted: bool
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -45,13 +45,13 @@ class Daybook(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import Optional
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, validator
|
from pydantic import BaseModel, Field, validator
|
||||||
|
|
||||||
@@ -19,13 +19,13 @@ class EmployeeIn(AccountBase):
|
|||||||
leaving_date: Optional[date]
|
leaving_date: Optional[date]
|
||||||
|
|
||||||
@validator("joining_date", pre=True)
|
@validator("joining_date", pre=True)
|
||||||
def parse_joining_date(cls, value):
|
def parse_joining_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("leaving_date", pre=True)
|
@validator("leaving_date", pre=True)
|
||||||
def parse_leaving_date(cls, value):
|
def parse_leaving_date(cls, value: Union[None, date, str]) -> Optional[date]:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
if value is None:
|
if value is None:
|
||||||
@@ -33,7 +33,7 @@ class EmployeeIn(AccountBase):
|
|||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("leaving_date")
|
@validator("leaving_date")
|
||||||
def leaving_date_more_than_joining_date(cls, v, values, **kwargs):
|
def leaving_date_more_than_joining_date(cls, v: Optional[date], values: dict, **kwargs: Any) -> Optional[date]:
|
||||||
if values["is_active"]:
|
if values["is_active"]:
|
||||||
return None
|
return None
|
||||||
if v < values["joining_date"]:
|
if v < values["joining_date"]:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from brewman.schemas.account import AccountLink
|
from brewman.schemas.account import AccountLink
|
||||||
@@ -15,7 +15,7 @@ class EmployeeAttendanceItem(BaseModel):
|
|||||||
full_day: Optional[bool]
|
full_day: Optional[bool]
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -33,13 +33,13 @@ class EmployeeAttendance(BaseModel):
|
|||||||
body: List[EmployeeAttendanceItem]
|
body: List[EmployeeAttendanceItem]
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from pydantic import BaseModel, Field
|
|||||||
|
|
||||||
class EmployeeBenefit(BaseModel):
|
class EmployeeBenefit(BaseModel):
|
||||||
id_: Optional[uuid.UUID]
|
id_: Optional[uuid.UUID]
|
||||||
employee: Optional[EmployeeLink]
|
employee: EmployeeLink
|
||||||
gross_salary: int = Field(ge=0)
|
gross_salary: int = Field(ge=0)
|
||||||
days_worked: int = Field(ge=0)
|
days_worked: int = Field(ge=0)
|
||||||
esi_employee: Optional[int] = Field(ge=0)
|
esi_employee: Optional[int] = Field(ge=0)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List
|
from typing import List, Union
|
||||||
|
|
||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
|
|
||||||
@@ -33,19 +33,19 @@ class Entries(BaseModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("creation_date", pre=True)
|
@validator("creation_date", pre=True)
|
||||||
def parse_creation_date(cls, value):
|
def parse_creation_date(cls, value: Union[datetime, str]) -> datetime:
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||||
|
|
||||||
@validator("last_edit_date", pre=True)
|
@validator("last_edit_date", pre=True)
|
||||||
def parse_last_edit_date(cls, value):
|
def parse_last_edit_date(cls, value: Union[datetime, str]) -> datetime:
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date
|
from datetime import datetime
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
@@ -8,4 +8,4 @@ from pydantic import BaseModel
|
|||||||
class Fingerprint(BaseModel):
|
class Fingerprint(BaseModel):
|
||||||
id: uuid.UUID
|
id: uuid.UUID
|
||||||
employee_id: uuid.UUID
|
employee_id: uuid.UUID
|
||||||
date: date
|
date: datetime
|
||||||
@@ -3,7 +3,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from fastapi import Form
|
from fastapi import Form
|
||||||
from pydantic import BaseModel, Field, validator
|
from pydantic import BaseModel, Field, validator
|
||||||
@@ -26,11 +26,11 @@ class JournalIn(VoucherIn):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {
|
||||||
date: lambda v: v.strftime("%d-%b-%Y"),
|
date: lambda v: v.strftime("%d-%b-%Y"),
|
||||||
datetime: lambda v: v.strftime("%d-%b-%Y %H:%I"),
|
datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value) -> date:
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -50,11 +50,11 @@ class PurchaseIn(VoucherIn):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {
|
||||||
date: lambda v: v.strftime("%d-%b-%Y"),
|
date: lambda v: v.strftime("%d-%b-%Y"),
|
||||||
datetime: lambda v: v.strftime("%d-%b-%Y %H:%I"),
|
datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value) -> date:
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -75,17 +75,17 @@ class IssueIn(VoucherIn):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {
|
||||||
date: lambda v: v.strftime("%d-%b-%Y"),
|
date: lambda v: v.strftime("%d-%b-%Y"),
|
||||||
datetime: lambda v: v.strftime("%d-%b-%Y %H:%I"),
|
datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value) -> date:
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("destination") # For Purchase, Issue and Return Vouchers
|
@validator("destination") # For Purchase, Issue and Return Vouchers
|
||||||
def source_destination_unique(cls, value: CostCentreLink, values) -> CostCentreLink:
|
def source_destination_unique(cls, value: CostCentreLink, values: dict) -> CostCentreLink:
|
||||||
if value.id_ == values["source"].id_:
|
if value.id_ == values["source"].id_:
|
||||||
raise ValueError("Source and destination cannot be the same")
|
raise ValueError("Source and destination cannot be the same")
|
||||||
return value
|
return value
|
||||||
@@ -104,11 +104,11 @@ class EmployeeBenefitIn(VoucherIn):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {
|
||||||
date: lambda v: v.strftime("%d-%b-%Y"),
|
date: lambda v: v.strftime("%d-%b-%Y"),
|
||||||
datetime: lambda v: v.strftime("%d-%b-%Y %H:%I"),
|
datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value) -> date:
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -127,11 +127,11 @@ class IncentiveIn(VoucherIn):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {
|
||||||
date: lambda v: v.strftime("%d-%b-%Y"),
|
date: lambda v: v.strftime("%d-%b-%Y"),
|
||||||
datetime: lambda v: v.strftime("%d-%b-%Y %H:%I"),
|
datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value) -> date:
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -23,7 +23,7 @@ class LedgerItem(BaseModel):
|
|||||||
posted: bool
|
posted: bool
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -46,13 +46,13 @@ class Ledger(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -31,13 +31,13 @@ class NetTransactions(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List
|
from typing import List, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -22,7 +22,7 @@ class NonContractPurchase(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -29,7 +29,7 @@ class ProductLedgerItem(BaseModel):
|
|||||||
posted: bool
|
posted: bool
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -52,13 +52,13 @@ class ProductLedger(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -33,13 +33,13 @@ class ProfitLoss(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List
|
from typing import List, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -20,7 +20,7 @@ class PurchaseEntriesItem(BaseModel):
|
|||||||
amount: Decimal
|
amount: Decimal
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -41,13 +41,13 @@ class PurchaseEntries(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -32,13 +32,13 @@ class Purchases(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from typing import List, Optional
|
from typing import List, Union
|
||||||
|
|
||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
|
|
||||||
@@ -11,9 +11,8 @@ from .rate_contract_item import RateContractItem
|
|||||||
from .user_link import UserLink
|
from .user_link import UserLink
|
||||||
|
|
||||||
|
|
||||||
class RateContractIn(BaseModel):
|
class RateContractBlank(BaseModel):
|
||||||
date_: date
|
date_: date
|
||||||
vendor: Optional[AccountLink]
|
|
||||||
valid_from: date
|
valid_from: date
|
||||||
valid_till: date
|
valid_till: date
|
||||||
narration: str
|
narration: str
|
||||||
@@ -24,11 +23,29 @@ class RateContractIn(BaseModel):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {
|
||||||
date: lambda v: v.strftime("%d-%b-%Y"),
|
date: lambda v: v.strftime("%d-%b-%Y"),
|
||||||
datetime: lambda v: v.strftime("%d-%b-%Y %H:%I"),
|
datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value) -> date:
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
|
class RateContractIn(RateContractBlank):
|
||||||
|
vendor: AccountLink
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
json_encoders = {
|
||||||
|
date: lambda v: v.strftime("%d-%b-%Y"),
|
||||||
|
datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"),
|
||||||
|
}
|
||||||
|
|
||||||
|
@validator("date_", pre=True)
|
||||||
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -45,17 +62,17 @@ class RateContract(RateContractIn):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {
|
||||||
date: lambda v: v.strftime("%d-%b-%Y"),
|
date: lambda v: v.strftime("%d-%b-%Y"),
|
||||||
datetime: lambda v: v.strftime("%d-%b-%Y %H:%I"),
|
datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@validator("creation_date", pre=True)
|
@validator("creation_date", pre=True)
|
||||||
def parse_creation_date(cls, value) -> datetime:
|
def parse_creation_date(cls, value: Union[datetime, str]) -> datetime:
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||||
|
|
||||||
@validator("last_edit_date", pre=True)
|
@validator("last_edit_date", pre=True)
|
||||||
def parse_last_edit_date(cls, value) -> datetime:
|
def parse_last_edit_date(cls, value: Union[datetime, str]) -> datetime:
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -43,13 +43,13 @@ class RawMaterialCost(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
|
|
||||||
@@ -30,13 +30,13 @@ class RecipeIn(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y") if v is not None else None}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y") if v is not None else None}
|
||||||
|
|
||||||
@validator("valid_from", pre=True)
|
@validator("valid_from", pre=True)
|
||||||
def parse_valid_from(cls, value) -> date:
|
def parse_valid_from(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("valid_till", pre=True)
|
@validator("valid_till", pre=True)
|
||||||
def parse_valid_till(cls, value) -> date:
|
def parse_valid_till(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -25,13 +25,13 @@ class ReconcileItem(BaseModel):
|
|||||||
reconcile_date: Optional[date]
|
reconcile_date: Optional[date]
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("reconcile_date", pre=True)
|
@validator("reconcile_date", pre=True)
|
||||||
def parse_reconcile_date(cls, value):
|
def parse_reconcile_date(cls, value: Union[None, date, str]) -> Optional[date]:
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
@@ -56,13 +56,13 @@ class Reconcile(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ class LockDate(BaseModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[None, date, str]) -> Optional[date]:
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
@@ -64,7 +64,7 @@ class LockInformation(BaseModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@validator("valid_from", pre=True)
|
@validator("valid_from", pre=True)
|
||||||
def parse_valid_from(cls, value):
|
def parse_valid_from(cls, value: Union[None, date, str]) -> Optional[date]:
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
@@ -72,7 +72,7 @@ class LockInformation(BaseModel):
|
|||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("valid_till", pre=True)
|
@validator("valid_till", pre=True)
|
||||||
def parse_valid_till(cls, value):
|
def parse_valid_till(cls, value: Union[None, date, str]) -> Optional[date]:
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List
|
from typing import List, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -36,13 +36,13 @@ class StockMovement(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
@@ -29,7 +29,7 @@ class TrialBalance(BaseModel):
|
|||||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -3,7 +3,7 @@ import uuid
|
|||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from fastapi import Form
|
from fastapi import Form
|
||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
@@ -59,17 +59,17 @@ class Voucher(VoucherIn):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
json_encoders = {
|
json_encoders = {
|
||||||
date: lambda v: v.strftime("%d-%b-%Y"),
|
date: lambda v: v.strftime("%d-%b-%Y"),
|
||||||
datetime: lambda v: v.strftime("%d-%b-%Y %H:%I"),
|
datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value) -> date:
|
def parse_date(cls, value: Union[date, str]) -> date:
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("creation_date", pre=True)
|
@validator("creation_date", pre=True)
|
||||||
def parse_creation_date(cls, value) -> Optional[date]:
|
def parse_creation_date(cls, value: Union[None, datetime, str]) -> Optional[datetime]:
|
||||||
if value is None or value == "":
|
if value is None or value == "":
|
||||||
return None
|
return None
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
@@ -77,7 +77,7 @@ class Voucher(VoucherIn):
|
|||||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||||
|
|
||||||
@validator("last_edit_date", pre=True)
|
@validator("last_edit_date", pre=True)
|
||||||
def parse_last_edit_date(cls, value) -> Optional[date]:
|
def parse_last_edit_date(cls, value: Union[None, datetime, str]) -> Optional[datetime]:
|
||||||
if value is None or value == "":
|
if value is None or value == "":
|
||||||
return None
|
return None
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
@@ -85,9 +85,9 @@ class Voucher(VoucherIn):
|
|||||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||||
|
|
||||||
@validator("reconcile_date", pre=True)
|
@validator("reconcile_date", pre=True)
|
||||||
def parse_reconcile_date(cls, value) -> Optional[date]:
|
def parse_reconcile_date(cls, value: Union[None, date, str]) -> Optional[date]:
|
||||||
if value is None or value == "":
|
if value is None or value == "":
|
||||||
return None
|
return None
|
||||||
elif isinstance(value, date):
|
if isinstance(value, date):
|
||||||
return value
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
@@ -41,19 +41,19 @@ export class AccountService {
|
|||||||
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Account[]>;
|
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Account[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
save(account: Account): Observable<Account> {
|
save(account: Account): Observable<null> {
|
||||||
return this.http
|
return this.http
|
||||||
.post<Account>(`${url}`, account)
|
.post<null>(`${url}`, account)
|
||||||
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<Account>;
|
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(account: Account): Observable<Account> {
|
update(account: Account): Observable<null> {
|
||||||
return this.http
|
return this.http
|
||||||
.put<Account>(`${url}/${account.id}`, account)
|
.put<null>(`${url}/${account.id}`, account)
|
||||||
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<Account>;
|
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveOrUpdate(account: Account): Observable<Account> {
|
saveOrUpdate(account: Account): Observable<null> {
|
||||||
if (!account.id) {
|
if (!account.id) {
|
||||||
return this.save(account);
|
return this.save(account);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user