Fix: Rebase
Chore: Moved to ruff and sorted and cleaned using it. Chore: Ansible file moved to roles based. Chore: Upgraded some dependencies
This commit is contained in:
1 parent
5fa8580cb9
commit
7c71d95d71
97 files changed
+432
-382
No files matched your search
@@ -1,9 +1,10 @@
|
||||
import logging
|
||||
|
||||
from sqlalchemy import create_engine, pool
|
||||
|
||||
from alembic import context
|
||||
from brewman.core.config import settings
|
||||
from brewman.db.base import reg
|
||||
from sqlalchemy import create_engine, pool
|
||||
|
||||
|
||||
logging.basicConfig()
|
||||
|
||||
@@ -8,10 +8,11 @@ Create Date: 2020-05-10 19:02:57.301086
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import column, func, table, text
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0bf3d70ee7de"
|
||||
|
||||
@@ -9,10 +9,11 @@ from hashlib import md5
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import column, func, insert, select, table
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "185c674cc392"
|
||||
@@ -46,7 +47,7 @@ def users():
|
||||
users.insert().values(
|
||||
id="8de98592-76d9-c74d-bb3f-d6184d388b5a",
|
||||
username="Admin",
|
||||
password=md5("123456".encode("utf-8") + "Salt".encode("utf-8")).hexdigest(),
|
||||
password=md5(b"123456" + b"Salt").hexdigest(),
|
||||
disabled=False,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -5,9 +5,11 @@ Revises: ba0fff092981
|
||||
Create Date: 2023-10-16 16:26:45.922654
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "2438cd581f00"
|
||||
down_revision = "ba0fff092981"
|
||||
@@ -53,8 +55,12 @@ def upgrade():
|
||||
)
|
||||
op.add_column("products", sa.Column("water", sa.Numeric(precision=15, scale=5), server_default="0", nullable=False))
|
||||
|
||||
op.add_column("product_groups", sa.Column("nutritional", sa.Boolean(), server_default=sa.text("false"), nullable=False))
|
||||
op.add_column("product_groups", sa.Column("ice_cream", sa.Boolean(), server_default=sa.text("false"), nullable=False))
|
||||
op.add_column(
|
||||
"product_groups", sa.Column("nutritional", sa.Boolean(), server_default=sa.text("false"), nullable=False)
|
||||
)
|
||||
op.add_column(
|
||||
"product_groups", sa.Column("ice_cream", sa.Boolean(), server_default=sa.text("false"), nullable=False)
|
||||
)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
@@ -5,9 +5,11 @@ Revises: 2438cd581f00
|
||||
Create Date: 2023-12-28 12:45:01.275322
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "66abfc21db73"
|
||||
down_revision = "2438cd581f00"
|
||||
|
||||
@@ -7,10 +7,11 @@ Create Date: 2023-03-31 05:03:40.408240
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "a1372ed99c45"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any
|
||||
|
||||
from fastapi import Depends, HTTPException, Security, status
|
||||
from fastapi.security import OAuth2PasswordBearer, SecurityScopes
|
||||
@@ -32,18 +33,9 @@ class TokenData(BaseModel):
|
||||
scopes: list[str] = []
|
||||
|
||||
|
||||
def f7(seq):
|
||||
seen = set()
|
||||
seen_add = seen.add
|
||||
return [x for x in seq if not (x in seen or seen_add(x))]
|
||||
|
||||
|
||||
def create_access_token(*, data: dict, expires_delta: timedelta | None = None) -> str:
|
||||
def create_access_token(*, data: dict[str, Any], expires_delta: timedelta | None = None) -> str:
|
||||
to_encode = data.copy()
|
||||
if expires_delta:
|
||||
expire = datetime.utcnow() + expires_delta
|
||||
else:
|
||||
expire = datetime.utcnow() + timedelta(minutes=15)
|
||||
expire = datetime.utcnow() + expires_delta if expires_delta else datetime.utcnow() + timedelta(minutes=15)
|
||||
to_encode.update({"exp": expire})
|
||||
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM)
|
||||
return encoded_jwt
|
||||
@@ -81,10 +73,7 @@ async def get_current_user(
|
||||
security_scopes: SecurityScopes,
|
||||
token: str = Depends(oauth2_scheme),
|
||||
) -> UserToken:
|
||||
if security_scopes.scopes:
|
||||
authenticate_value = f'Bearer scope="{security_scopes.scope_str}"'
|
||||
else:
|
||||
authenticate_value = "Bearer"
|
||||
authenticate_value = f'Bearer scope="{security_scopes.scope_str}"' if security_scopes.scopes else "Bearer"
|
||||
credentials_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Could not validate credentials",
|
||||
|
||||
@@ -1,36 +1,37 @@
|
||||
from datetime import date, timedelta
|
||||
from typing import Any
|
||||
|
||||
|
||||
def get_date(session: dict) -> str:
|
||||
def get_date(session: dict[str, Any]) -> str:
|
||||
if "date" not in session:
|
||||
session["date"] = date.today().strftime("%d-%b-%Y")
|
||||
return session["date"] # type: ignore[no-any-return]
|
||||
|
||||
|
||||
def set_date(date_: str | date, session: dict) -> None:
|
||||
def set_date(date_: str | date, session: dict[str, Any]) -> None:
|
||||
session["date"] = date_ if isinstance(date_, str) else date_.strftime("%d-%b-%Y")
|
||||
|
||||
|
||||
def get_start_date(session: dict) -> str:
|
||||
def get_start_date(session: dict[str, Any]) -> str:
|
||||
if "start" not in session:
|
||||
session["start"] = get_first_day(date.today()).strftime("%d-%b-%Y")
|
||||
return session["start"] # type: ignore[no-any-return]
|
||||
|
||||
|
||||
def get_finish_date(session: dict) -> str:
|
||||
def get_finish_date(session: dict[str, Any]) -> str:
|
||||
if "finish" not in session:
|
||||
session["finish"] = get_last_day(date.today()).strftime("%d-%b-%Y")
|
||||
return session["finish"] # type: ignore[no-any-return]
|
||||
|
||||
|
||||
def set_period(start: str | date | None, finish: str | date | None, session: dict) -> None:
|
||||
def set_period(start: str | date | None, finish: str | date | None, session: dict[str, Any]) -> None:
|
||||
if start is not None:
|
||||
session["start"] = start if isinstance(start, str) else start.strftime("%d-%b-%Y")
|
||||
if finish is not None:
|
||||
session["finish"] = finish if isinstance(finish, str) else finish.strftime("%d-%b-%Y")
|
||||
|
||||
|
||||
def get_first_day(dt: date, d_years=0, d_months=0) -> date:
|
||||
def get_first_day(dt: date, d_years: int = 0, d_months: int = 0) -> date:
|
||||
# d_years, d_months are "deltas" to apply to dt
|
||||
y, m = dt.year + d_years, dt.month + d_months
|
||||
a, m = divmod(m - 1, 12)
|
||||
|
||||
@@ -47,4 +47,4 @@ class Account(AccountBase):
|
||||
def can_delete(self, advanced_delete: bool) -> tuple[bool, str]:
|
||||
if len(self.products) > 0:
|
||||
return False, "Account has products"
|
||||
return super(Account, self).can_delete(advanced_delete)
|
||||
return super().can_delete(advanced_delete)
|
||||
@@ -29,8 +29,8 @@ class Batch:
|
||||
tax: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=5), nullable=False)
|
||||
discount: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=5), nullable=False)
|
||||
|
||||
inventories: Mapped[list["Inventory"]] = relationship("Inventory", back_populates="batch")
|
||||
sku: Mapped["StockKeepingUnit"] = relationship("StockKeepingUnit", back_populates="batches")
|
||||
inventories: Mapped[list[Inventory]] = relationship("Inventory", back_populates="batch")
|
||||
sku: Mapped[StockKeepingUnit] = relationship("StockKeepingUnit", back_populates="batches")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -24,7 +24,7 @@ class Client:
|
||||
otp: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
creation_date: Mapped[datetime] = mapped_column(DateTime(), nullable=False)
|
||||
|
||||
login_history: Mapped[list["LoginHistory"]] = relationship(
|
||||
login_history: Mapped[list[LoginHistory]] = relationship(
|
||||
"LoginHistory", order_by=desc(LoginHistory.date), back_populates="client"
|
||||
)
|
||||
|
||||
@@ -46,7 +46,7 @@ class Client:
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def create(cls, db: Session) -> "Client":
|
||||
def create(cls, db: Session) -> Client:
|
||||
client_code = random.randint(1000, 9999)
|
||||
otp = random.randint(1000, 9999)
|
||||
name = "".join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
|
||||
|
||||
@@ -31,8 +31,8 @@ class ClosingStock:
|
||||
sku_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("stock_keeping_units.id"), nullable=False)
|
||||
quantity: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False)
|
||||
|
||||
cost_centre: Mapped["CostCentre"] = relationship("CostCentre")
|
||||
sku: Mapped["StockKeepingUnit"] = relationship("StockKeepingUnit")
|
||||
cost_centre: Mapped[CostCentre] = relationship("CostCentre")
|
||||
sku: Mapped[StockKeepingUnit] = relationship("StockKeepingUnit")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -40,7 +40,7 @@ class ClosingStock:
|
||||
cost_centre_id: uuid.UUID,
|
||||
quantity: Decimal,
|
||||
sku_id: uuid.UUID | None = None,
|
||||
sku: "StockKeepingUnit" | None = None,
|
||||
sku: StockKeepingUnit | None = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.date_ = date_
|
||||
|
||||
@@ -15,7 +15,7 @@ class DbSetting:
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, insert_default=uuid.uuid4)
|
||||
name: Mapped[str] = mapped_column(Unicode, unique=True, nullable=False)
|
||||
data: Mapped[dict] = mapped_column(PickleType)
|
||||
data: Mapped[dict] = mapped_column(PickleType) # type: ignore[type-arg]
|
||||
setting_type: Mapped[SettingType] = mapped_column(Enum(SettingType), nullable=False)
|
||||
|
||||
valid_from: Mapped[date | None] = mapped_column(Date(), nullable=True)
|
||||
@@ -25,7 +25,7 @@ class DbSetting:
|
||||
self,
|
||||
setting_type: SettingType,
|
||||
name: str,
|
||||
data: dict,
|
||||
data: dict, # type: ignore[type-arg]
|
||||
valid_from: date | None = None,
|
||||
valid_till: date | None = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
|
||||
@@ -68,4 +68,4 @@ class Employee(AccountBase):
|
||||
return self
|
||||
|
||||
def can_delete(self, advanced_delete: bool) -> tuple[bool, str]:
|
||||
return super(Employee, self).can_delete(advanced_delete)
|
||||
return super().can_delete(advanced_delete)
|
||||
@@ -26,16 +26,16 @@ class Price:
|
||||
product_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("products.id"), nullable=False)
|
||||
price: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False)
|
||||
|
||||
period: Mapped["Period"] = relationship("Period")
|
||||
product: Mapped["Product"] = relationship("Product")
|
||||
period: Mapped[Period] = relationship("Period")
|
||||
product: Mapped[Product] = relationship("Product")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
price: Decimal,
|
||||
period_id: uuid.UUID | None = None,
|
||||
product_id: uuid.UUID | None = None,
|
||||
period: "Period" | None = None,
|
||||
product: "Product" | None = None,
|
||||
period: Period | None = None,
|
||||
product: Product | None = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.price = price
|
||||
|
||||
@@ -66,19 +66,19 @@ class Product:
|
||||
is_purchased: bool,
|
||||
is_sold: bool,
|
||||
allergen: str = "",
|
||||
protein: Decimal = 0,
|
||||
carbohydrate: Decimal = 0,
|
||||
total_sugar: Decimal = 0,
|
||||
added_sugar: Decimal = 0,
|
||||
total_fat: Decimal = 0,
|
||||
saturated_fat: Decimal = 0,
|
||||
trans_fat: Decimal = 0,
|
||||
cholestrol: Decimal = 0,
|
||||
sodium: Decimal = 0,
|
||||
msnf: Decimal = 0,
|
||||
other_solids: Decimal = 0,
|
||||
total_solids: Decimal = 0,
|
||||
water: Decimal = 0,
|
||||
protein: Decimal = Decimal(0),
|
||||
carbohydrate: Decimal = Decimal(0),
|
||||
total_sugar: Decimal = Decimal(0),
|
||||
added_sugar: Decimal = Decimal(0),
|
||||
total_fat: Decimal = Decimal(0),
|
||||
saturated_fat: Decimal = Decimal(0),
|
||||
trans_fat: Decimal = Decimal(0),
|
||||
cholestrol: Decimal = Decimal(0),
|
||||
sodium: Decimal = Decimal(0),
|
||||
msnf: Decimal = Decimal(0),
|
||||
other_solids: Decimal = Decimal(0),
|
||||
total_solids: Decimal = Decimal(0),
|
||||
water: Decimal = Decimal(0),
|
||||
code: int | None = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
is_fixture: bool | None = False,
|
||||
|
||||
@@ -21,7 +21,6 @@ class ProductGroup:
|
||||
nutritional: Mapped[bool] = mapped_column(Boolean, nullable=False)
|
||||
ice_cream: Mapped[bool] = mapped_column(Boolean, nullable=False)
|
||||
is_fixture: Mapped[bool] = mapped_column(Boolean, nullable=False)
|
||||
is_fixture: Mapped[bool] = mapped_column(Boolean, nullable=False)
|
||||
|
||||
products: Mapped[list["Product"]] = relationship("Product", back_populates="product_group")
|
||||
|
||||
|
||||
@@ -35,10 +35,13 @@ class Recipe:
|
||||
|
||||
recipe_yield: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False)
|
||||
|
||||
items: Mapped[list["RecipeItem"]] = relationship("RecipeItem", back_populates="recipe")
|
||||
sku: Mapped["StockKeepingUnit"] = relationship("StockKeepingUnit", back_populates="recipes")
|
||||
tags: Mapped[list["Tag"]] = relationship(
|
||||
"Tag", secondary=RecipeTag.__table__, order_by="Tag.name", back_populates="recipes"
|
||||
items: Mapped[list[RecipeItem]] = relationship("RecipeItem", back_populates="recipe")
|
||||
sku: Mapped[StockKeepingUnit] = relationship("StockKeepingUnit", back_populates="recipes")
|
||||
tags: Mapped[list[Tag]] = relationship(
|
||||
"Tag",
|
||||
secondary=RecipeTag.__table__,
|
||||
order_by="Tag.name",
|
||||
back_populates="recipes", # type: ignore[attr-defined]
|
||||
)
|
||||
|
||||
def __init__(
|
||||
@@ -51,7 +54,7 @@ class Recipe:
|
||||
notes: str,
|
||||
recipe_yield: Decimal,
|
||||
sku_id: uuid.UUID | None = None,
|
||||
sku: "StockKeepingUnit" | None = None,
|
||||
sku: StockKeepingUnit | None = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.date_ = date_
|
||||
|
||||
@@ -27,8 +27,8 @@ class RecipeItem:
|
||||
quantity: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False)
|
||||
description: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
|
||||
recipe: Mapped["Recipe"] = relationship("Recipe", back_populates="items")
|
||||
product: Mapped["Product"] = relationship("Product")
|
||||
recipe: Mapped[Recipe] = relationship("Recipe", back_populates="items")
|
||||
product: Mapped[Product] = relationship("Product")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -36,8 +36,8 @@ class RecipeItem:
|
||||
description: str = "",
|
||||
recipe_id: uuid.UUID | None = None,
|
||||
product_id: uuid.UUID | None = None,
|
||||
recipe: "Recipe" | None = None,
|
||||
product: "Product" | None = None,
|
||||
recipe: Recipe | None = None,
|
||||
product: Product | None = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.quantity = quantity
|
||||
|
||||
@@ -28,3 +28,11 @@ class RecipeTemplate:
|
||||
postgresql_where=(selected == True), # noqa: E712
|
||||
),
|
||||
)
|
||||
|
||||
def __init__(self, name: str, date_: date, text: str, selected: bool, id_: uuid.UUID | None = None) -> None:
|
||||
self.name = name
|
||||
self.date_ = date_
|
||||
self.text = text
|
||||
self.selected = selected
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -22,6 +22,11 @@ class Role:
|
||||
|
||||
permissions: Mapped[list["Permission"]] = relationship(
|
||||
"Permission",
|
||||
secondary=RolePermission.__table__,
|
||||
back_populates="roles", # type: ignore[attr-defined]
|
||||
secondary=RolePermission.__table__, # type: ignore[attr-defined]
|
||||
back_populates="roles",
|
||||
)
|
||||
|
||||
def __init__(self, name: str, id_: uuid.UUID | None = None) -> None:
|
||||
self.name = name
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -30,9 +30,9 @@ class StockKeepingUnit:
|
||||
cost_price: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False)
|
||||
sale_price: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False)
|
||||
|
||||
product: Mapped["Product"] = relationship("Product", back_populates="skus")
|
||||
batches: Mapped[list["Batch"]] = relationship("Batch", back_populates="sku")
|
||||
recipes: Mapped[list["Recipe"]] = relationship("Recipe", back_populates="sku")
|
||||
product: Mapped[Product] = relationship("Product", back_populates="skus")
|
||||
batches: Mapped[list[Batch]] = relationship("Batch", back_populates="sku")
|
||||
recipes: Mapped[list[Recipe]] = relationship("Recipe", back_populates="sku")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -42,7 +42,7 @@ class StockKeepingUnit:
|
||||
cost_price: Decimal,
|
||||
sale_price: Decimal,
|
||||
product_id: uuid.UUID | None = None,
|
||||
product: "Product" | None = None,
|
||||
product: Product | None = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
) -> None:
|
||||
if product_id is not None:
|
||||
|
||||
@@ -21,5 +21,8 @@ class Tag:
|
||||
name: Mapped[str] = mapped_column(Unicode, unique=True, nullable=False)
|
||||
|
||||
recipes: Mapped[list["Recipe"]] = relationship(
|
||||
"Recipe", secondary=RecipeTag.__table__, order_by="Recipe.date_", back_populates="tags"
|
||||
"Recipe",
|
||||
secondary=RecipeTag.__table__,
|
||||
order_by="Recipe.date_",
|
||||
back_populates="tags", # type: ignore[attr-defined]
|
||||
)
|
||||
@@ -20,7 +20,7 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
def encrypt(val: str) -> str:
|
||||
return md5(val.encode("utf-8") + "Salt".encode("utf-8")).hexdigest()
|
||||
return md5(val.encode("utf-8") + b"Salt").hexdigest()
|
||||
|
||||
|
||||
@reg.mapped_as_dataclass(unsafe_hash=True)
|
||||
@@ -52,7 +52,7 @@ class User:
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def auth(cls, name: str, password: str, db: Session) -> "User" | None:
|
||||
def auth(cls, name: str, password: str, db: Session) -> User | None:
|
||||
if password is None:
|
||||
return None
|
||||
user: User | None = db.execute(select(cls).where(cls.name.ilike(name))).scalars().one_or_none()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from collections.abc import Sequence
|
||||
from datetime import date, timedelta
|
||||
from typing import Sequence
|
||||
|
||||
from sqlalchemy import or_, select
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -21,7 +21,7 @@ def get_lock_info(
|
||||
date_ = date.today()
|
||||
start: date | None
|
||||
finish: date | None
|
||||
data: list[dict] = list(
|
||||
data: list[dict] = list( # type: ignore[type-arg]
|
||||
db.execute(
|
||||
select(DbSetting.data).where(
|
||||
DbSetting.setting_type == SettingType.VOUCHER_LOCK,
|
||||
@@ -38,14 +38,14 @@ def get_lock_info(
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
data = sorted(data, key=lambda d: d["index"], reverse=True) # type: ignore[index]
|
||||
data = sorted(data, key=lambda d: d["index"], reverse=True)
|
||||
for it in data:
|
||||
li: LockInformation = LockInformation(
|
||||
voucher_types=[VoucherTypesSelected(id_=vt["id_"], name=vt["name"]) for vt in it["voucher_types"]], # type: ignore[index]
|
||||
account_types=[AccountTypesSelected(id_=at["id_"], name=at["name"]) for at in it["account_types"]], # type: ignore[index]
|
||||
start=LockDate(days=it["start"]["days"], date_=it["start"]["date_"]), # type: ignore[index]
|
||||
finish=LockDate(days=it["finish"]["days"], date_=it["finish"]["date_"]), # type: ignore[index]
|
||||
index=it["index"], # type: ignore[index]
|
||||
voucher_types=[VoucherTypesSelected(id_=vt["id_"], name=vt["name"]) for vt in it["voucher_types"]],
|
||||
account_types=[AccountTypesSelected(id_=at["id_"], name=at["name"]) for at in it["account_types"]],
|
||||
start=LockDate(days=it["start"]["days"], date_=it["start"]["date_"]),
|
||||
finish=LockDate(days=it["finish"]["days"], date_=it["finish"]["date_"]),
|
||||
index=it["index"],
|
||||
)
|
||||
# Data format
|
||||
if len(li.voucher_types) != 0 and voucher_type not in [vt.id_ for vt in li.voucher_types]:
|
||||
|
||||
@@ -3,13 +3,13 @@ import uuid
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.account as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
|
||||
import brewman.schemas.account as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.account import Account
|
||||
@@ -66,7 +66,7 @@ def update_route(
|
||||
status_code=status.HTTP_423_LOCKED,
|
||||
detail=f"{item.name} is a fixture and cannot be edited or deleted.",
|
||||
)
|
||||
if not item.type_id == data.type_:
|
||||
if item.type_id != data.type_:
|
||||
item.code = Account.get_code(data.type_, db)
|
||||
item.type_id = data.type_
|
||||
item.name = data.name
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import brewman.schemas.account_type as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy import select
|
||||
|
||||
import brewman.schemas.account_type as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.account_type import AccountType
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from collections.abc import Generator
|
||||
from datetime import date, datetime, timedelta
|
||||
from typing import Generator
|
||||
|
||||
import brewman.schemas.attendance as schemas
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request, Security, status
|
||||
from sqlalchemy import or_, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.attendance as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionFuture
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import brewman.schemas.attendance_type as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
import brewman.schemas.attendance_type as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..models.attendance_type import AttendanceType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import datetime
|
||||
|
||||
import brewman.schemas.batch as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import contains_eager
|
||||
|
||||
import brewman.schemas.batch as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.batch import Batch
|
||||
|
||||
@@ -2,12 +2,12 @@ import uuid
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.batch_integrity as schemas
|
||||
|
||||
from fastapi import APIRouter, Security
|
||||
from sqlalchemy import distinct, func, select, update
|
||||
from sqlalchemy.orm import Session, contains_eager
|
||||
|
||||
import brewman.schemas.batch_integrity as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.batch import Batch
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import uuid
|
||||
|
||||
from ..schemas.nutritional_information import NutritionalInformation
|
||||
from ..models.product_group import ProductGroup
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy import distinct, or_, select, update
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..models.product import Product
|
||||
from ..models.product_group import ProductGroup
|
||||
from ..models.recipe import Recipe
|
||||
from ..models.recipe_item import RecipeItem
|
||||
from ..models.stock_keeping_unit import StockKeepingUnit
|
||||
from ..schemas.nutritional_information import NutritionalInformation
|
||||
|
||||
|
||||
def calculate_nutrition(db: Session):
|
||||
def calculate_nutrition(db: Session) -> None:
|
||||
try:
|
||||
# Get all recipes that have nutritional values
|
||||
products = set(
|
||||
|
||||
@@ -2,6 +2,12 @@ import uuid
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy import distinct, func, select
|
||||
from sqlalchemy.dialects.postgresql import insert as pg_insert
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from brewman.models.batch import Batch
|
||||
from brewman.models.cost_centre import CostCentre
|
||||
from brewman.models.inventory import Inventory
|
||||
@@ -10,18 +16,13 @@ from brewman.models.period import Period
|
||||
from brewman.models.price import Price
|
||||
from brewman.models.voucher import Voucher
|
||||
from brewman.models.voucher_type import VoucherType
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy import distinct, func, select
|
||||
from sqlalchemy.dialects.postgresql import insert as pg_insert
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..models.recipe import Recipe
|
||||
from ..models.recipe_item import RecipeItem
|
||||
from ..models.stock_keeping_unit import StockKeepingUnit
|
||||
|
||||
|
||||
def calculate_prices(period_id: uuid.UUID, db: Session):
|
||||
def calculate_prices(period_id: uuid.UUID, db: Session) -> None:
|
||||
try:
|
||||
item: Period = db.execute(select(Period).where(Period.id == period_id)).scalar_one()
|
||||
recipes = set(
|
||||
@@ -57,7 +58,7 @@ def get_issue_prices(period: Period, products: set[uuid.UUID], db: Session) -> d
|
||||
sum_net = func.sum(Inventory.rate * Inventory.quantity * Journal.debit).label("net")
|
||||
|
||||
d: dict[uuid.UUID, Decimal] = {}
|
||||
query: list[tuple[uuid.UUID, Decimal]] = db.execute(
|
||||
query = db.execute(
|
||||
select(StockKeepingUnit.product_id, sum_net / sum_quantity)
|
||||
.join(Inventory.batch)
|
||||
.join(Batch.sku)
|
||||
@@ -84,7 +85,7 @@ def get_purchase_prices(period: Period, req: set[uuid.UUID], db: Session) -> dic
|
||||
sum_net = func.sum(Inventory.rate * Inventory.quantity * Journal.debit).label("net")
|
||||
|
||||
d: dict[uuid.UUID, Decimal] = {}
|
||||
query: list[tuple[uuid.UUID, Decimal]] = db.execute(
|
||||
query = db.execute(
|
||||
select(StockKeepingUnit.product_id, sum_net / sum_quantity)
|
||||
.join(Inventory.batch)
|
||||
.join(Batch.sku)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import uuid
|
||||
|
||||
import brewman.schemas.client as schemas
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Security, status
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
import brewman.schemas.client as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.client import Client
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import uuid
|
||||
|
||||
import brewman.schemas.cost_centre as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
import brewman.schemas.cost_centre as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.account_base import AccountBase
|
||||
|
||||
@@ -2,13 +2,13 @@ import uuid
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
import brewman.schemas.image_upload as output
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi.responses import StreamingResponse
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.image_upload as output
|
||||
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.db_image import DbImage
|
||||
|
||||
@@ -20,10 +20,7 @@ router = APIRouter()
|
||||
def db_image(id_: uuid.UUID, type_: str) -> StreamingResponse:
|
||||
with SessionFuture() as db:
|
||||
item = db.execute(select(DbImage).where(DbImage.id == id_)).scalar_one()
|
||||
if type_ == "thumbnail":
|
||||
img = BytesIO(item.thumbnail)
|
||||
else:
|
||||
img = BytesIO(item.image)
|
||||
img = BytesIO(item.thumbnail) if type_ == "thumbnail" else BytesIO(item.image)
|
||||
return StreamingResponse(img, media_type="image/jpeg")
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import uuid
|
||||
|
||||
from collections.abc import Sequence
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from typing import Sequence
|
||||
|
||||
import brewman.schemas.employee as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import desc, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
|
||||
import brewman.schemas.employee as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.account import Account
|
||||
|
||||
@@ -2,12 +2,12 @@ import uuid
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
import brewman.schemas.employee_attendance as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.employee_attendance as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_finish_date, get_start_date
|
||||
from ..db.session import SessionFuture
|
||||
|
||||
@@ -4,14 +4,14 @@ from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
from math import ceil
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, Request, Security, status
|
||||
from sqlalchemy import distinct, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, get_last_day, set_date
|
||||
from ..db.session import SessionFuture
|
||||
|
||||
@@ -5,14 +5,14 @@ import uuid
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from io import StringIO
|
||||
|
||||
import brewman.schemas.fingerprint as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, UploadFile, status
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.dialects.postgresql import insert as pg_insert
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.fingerprint as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.employee import Employee
|
||||
@@ -81,7 +81,7 @@ def fp(file_data: StringIO, employees: dict[int, uuid.UUID]) -> list[schemas.Fin
|
||||
try:
|
||||
employee_code = int(row[employee_column]) # EnNo
|
||||
date_ = datetime.strptime(row[date_column].replace("/", "-"), date_format)
|
||||
if employee_code in employees.keys():
|
||||
if employee_code in employees:
|
||||
fingerprints.append(
|
||||
schemas.Fingerprint(
|
||||
id_=uuid.uuid4(),
|
||||
|
||||
@@ -3,14 +3,14 @@ import uuid
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Security, status
|
||||
from sqlalchemy import and_, distinct, func, or_, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, get_first_day, set_date
|
||||
from ..db.session import SessionFuture
|
||||
|
||||
@@ -3,14 +3,14 @@ import uuid
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, Request, Security, status
|
||||
from sqlalchemy import distinct, func, or_, select, update
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionFuture
|
||||
|
||||
@@ -2,14 +2,14 @@ import uuid
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, Request, Security, status
|
||||
from sqlalchemy import distinct, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionFuture
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import uuid
|
||||
|
||||
import brewman.schemas.period as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Security, status
|
||||
from sqlalchemy import delete, desc, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
import brewman.schemas.period as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_finish_date, get_start_date
|
||||
from ..db.session import SessionFuture
|
||||
|
||||
@@ -3,13 +3,13 @@ import uuid
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.product as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import delete, desc, func, or_, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session, contains_eager
|
||||
|
||||
import brewman.schemas.product as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.account import Account
|
||||
@@ -245,7 +245,7 @@ async def show_term_sku(
|
||||
query_ = query_.order_by(Product.name)
|
||||
|
||||
for item in db.execute(query_).unique().scalars().all():
|
||||
for sku in item.skus: # type: StockKeepingUnit
|
||||
for sku in item.skus:
|
||||
rc_price = get_rc_price(item.id, d, v, db)
|
||||
list_.append(
|
||||
ProductSku(
|
||||
@@ -254,7 +254,7 @@ async def show_term_sku(
|
||||
fraction_units=item.fraction_units,
|
||||
cost_price=sku.cost_price if rc_price is None else rc_price,
|
||||
sale_price=sku.sale_price,
|
||||
is_rate_contracted=False if rc_price is None else True,
|
||||
is_rate_contracted=rc_price is not None,
|
||||
)
|
||||
)
|
||||
return list_
|
||||
@@ -355,19 +355,19 @@ def product_blank() -> schemas.ProductBlank:
|
||||
is_sold=False,
|
||||
is_fixture=False,
|
||||
allergen="",
|
||||
protein=0,
|
||||
carbohydrate=0,
|
||||
total_sugar=0,
|
||||
added_sugar=0,
|
||||
total_fat=0,
|
||||
saturated_fat=0,
|
||||
trans_fat=0,
|
||||
cholestrol=0,
|
||||
sodium=0,
|
||||
msnf=0,
|
||||
other_solids=0,
|
||||
total_solids=0,
|
||||
water=0,
|
||||
protein=Decimal(0),
|
||||
carbohydrate=Decimal(0),
|
||||
total_sugar=Decimal(0),
|
||||
added_sugar=Decimal(0),
|
||||
total_fat=Decimal(0),
|
||||
saturated_fat=Decimal(0),
|
||||
trans_fat=Decimal(0),
|
||||
cholestrol=Decimal(0),
|
||||
sodium=Decimal(0),
|
||||
msnf=Decimal(0),
|
||||
other_solids=Decimal(0),
|
||||
total_solids=Decimal(0),
|
||||
water=Decimal(0),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import uuid
|
||||
|
||||
import brewman.schemas.product_group as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
import brewman.schemas.product_group as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.product_group import ProductGroup
|
||||
@@ -124,4 +124,6 @@ def product_group_blank() -> schemas.ProductGroupBlank:
|
||||
return schemas.ProductGroupBlank(
|
||||
name="",
|
||||
is_fixture=False,
|
||||
ice_cream=False,
|
||||
nutritional=False,
|
||||
)
|
||||
@@ -3,14 +3,14 @@ import uuid
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, Request, Security, status
|
||||
from sqlalchemy import distinct, func, or_, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionFuture
|
||||
|
||||
@@ -3,14 +3,14 @@ import uuid
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, Request, Security, status
|
||||
from sqlalchemy import distinct, or_, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionFuture
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request, Security, status
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
@@ -17,9 +19,8 @@ from ..db.session import SessionFuture
|
||||
from ..models.rate_contract import RateContract
|
||||
from ..models.rate_contract_item import RateContractItem
|
||||
from ..schemas.product import ProductLink
|
||||
from ..schemas.rate_contract import AccountLink
|
||||
from ..schemas.rate_contract import AccountLink, RateContractBlank, RateContractIn
|
||||
from ..schemas.rate_contract import RateContract as RateContractSchema
|
||||
from ..schemas.rate_contract import RateContractBlank, RateContractIn
|
||||
from ..schemas.rate_contract import RateContractItem as RateContractItemSchema
|
||||
from ..schemas.user import UserToken
|
||||
from ..schemas.user_link import UserLink
|
||||
@@ -172,7 +173,7 @@ def rate_contract_info(item: RateContract) -> RateContractSchema:
|
||||
)
|
||||
|
||||
|
||||
def rate_contract_blank(session: dict) -> RateContractBlank:
|
||||
def rate_contract_blank(session: dict[str, Any]) -> RateContractBlank:
|
||||
return RateContractBlank(
|
||||
date_=get_date(session), # type: ignore[arg-type]
|
||||
valid_from=get_start_date(session), # type: ignore[arg-type]
|
||||
|
||||
@@ -6,7 +6,7 @@ from decimal import Decimal
|
||||
|
||||
from fastapi import APIRouter, Security
|
||||
from sqlalchemy import and_, delete, distinct, func, select
|
||||
from sqlalchemy.orm import Session, aliased
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
@@ -22,6 +22,8 @@ from ..models.fingerprint import Fingerprint
|
||||
from ..models.incentive import Incentive
|
||||
from ..models.inventory import Inventory
|
||||
from ..models.journal import Journal
|
||||
from ..models.rate_contract import RateContract
|
||||
from ..models.rate_contract_item import RateContractItem
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
@@ -207,8 +209,7 @@ def opening_batches(date_: date, user_id: uuid.UUID, db: Session) -> Voucher:
|
||||
|
||||
|
||||
def delete_data(date_: date, vouchers: list[uuid.UUID], db: Session) -> None:
|
||||
sub_voucher = aliased(Voucher)
|
||||
sub_query = select(sub_voucher.id).where(sub_voucher.date_ < date_).subquery()
|
||||
sub_query = select(Voucher.id).where(Voucher.date_ < date_)
|
||||
|
||||
db.execute(
|
||||
delete(Inventory).where(Inventory.voucher_id.in_(sub_query)).execution_options(synchronize_session=False)
|
||||
@@ -242,32 +243,36 @@ def delete_data(date_: date, vouchers: list[uuid.UUID], db: Session) -> None:
|
||||
.where(Voucher.date_ < date_, ~Voucher.id.in_(vouchers))
|
||||
.execution_options(synchronize_session=False)
|
||||
)
|
||||
db.execute(
|
||||
delete(RateContractItem)
|
||||
.where(RateContractItem.rate_contract_id.in_(select(RateContract.id).where(RateContract.date_ < date_)))
|
||||
.execution_options(synchronize_session=False)
|
||||
)
|
||||
db.execute(delete(RateContract).where(RateContract.date_ < date_).execution_options(synchronize_session=False))
|
||||
|
||||
|
||||
def cleanup_lint(date_: date, db: Session) -> None:
|
||||
# Insert executes on the end so keep list of batches and journals
|
||||
db.execute(
|
||||
delete(Batch)
|
||||
.where(~Batch.id.in_(select(distinct(Inventory.batch_id)).subquery()))
|
||||
.where(~Batch.id.in_(select(distinct(Inventory.batch_id))))
|
||||
.execution_options(synchronize_session=False)
|
||||
)
|
||||
db.execute(delete(Fingerprint).where(Fingerprint.date < date_).execution_options(synchronize_session=False))
|
||||
db.execute(delete(Fingerprint).where(Fingerprint.date_ < date_).execution_options(synchronize_session=False))
|
||||
db.execute(delete(Attendance).where(Attendance.date_ < date_).execution_options(synchronize_session=False))
|
||||
db.execute(
|
||||
delete(Employee)
|
||||
.where(
|
||||
and_(
|
||||
~Employee.id.in_(select(distinct(Journal.account_id)).subquery()),
|
||||
~Employee.id.in_(select(distinct(Fingerprint.employee_id)).subquery()),
|
||||
~Employee.id.in_(select(distinct(Attendance.employee_id)).subquery()),
|
||||
~Employee.id.in_(select(distinct(Journal.account_id))),
|
||||
~Employee.id.in_(select(distinct(Fingerprint.employee_id))),
|
||||
~Employee.id.in_(select(distinct(Attendance.employee_id))),
|
||||
Employee.id.in_(
|
||||
select(AccountBase.id)
|
||||
.where(
|
||||
select(AccountBase.id).where(
|
||||
AccountBase.is_fixture == False, # noqa: E712
|
||||
AccountBase.is_active == False, # noqa: E712
|
||||
AccountBase.is_starred == False, # noqa: E712
|
||||
)
|
||||
.subquery()
|
||||
),
|
||||
Employee.leaving_date < date_,
|
||||
)
|
||||
@@ -278,7 +283,7 @@ def cleanup_lint(date_: date, db: Session) -> None:
|
||||
delete(AccountBase)
|
||||
.where(
|
||||
and_(
|
||||
~AccountBase.id.in_(select(Employee.id).subquery()),
|
||||
~AccountBase.id.in_(select(Employee.id)),
|
||||
AccountBase.account_type == Employee.__mapper_args__["polymorphic_identity"],
|
||||
)
|
||||
)
|
||||
@@ -288,10 +293,9 @@ def cleanup_lint(date_: date, db: Session) -> None:
|
||||
delete(Account)
|
||||
.where(
|
||||
and_(
|
||||
~Account.id.in_(select(distinct(Journal.account_id)).subquery()),
|
||||
~Account.id.in_(select(distinct(Journal.account_id))),
|
||||
Account.is_fixture == False, # noqa: E712
|
||||
Account.is_starred == False, # noqa: E712
|
||||
Account.account_type == Account.__mapper_args__["polymorphic_identity"],
|
||||
)
|
||||
)
|
||||
.execution_options(synchronize_session=False)
|
||||
|
||||
@@ -3,19 +3,11 @@ import tempfile
|
||||
import uuid
|
||||
|
||||
from collections import defaultdict
|
||||
from collections.abc import Sequence
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
from io import BytesIO
|
||||
from typing import Sequence
|
||||
|
||||
from ..schemas.nutritional_information import NutritionalInformation
|
||||
from ..routers.calculate_nutrition import calculate_nutrition, report_nutrition
|
||||
|
||||
import brewman.schemas.recipe as schemas
|
||||
import brewman.schemas.recipe_item as rischemas
|
||||
|
||||
from ..models.price import Price
|
||||
from ..routers.calculate_prices import calculate_prices
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Security, status
|
||||
from fastapi.responses import FileResponse, StreamingResponse
|
||||
from openpyxl import Workbook
|
||||
@@ -24,12 +16,19 @@ from sqlalchemy import delete, func, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session, contains_eager, joinedload
|
||||
|
||||
import brewman.schemas.recipe as schemas
|
||||
import brewman.schemas.recipe_item as rischemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.price import Price
|
||||
from ..models.product import Product
|
||||
from ..models.recipe import Recipe
|
||||
from ..models.recipe_item import RecipeItem
|
||||
from ..models.stock_keeping_unit import StockKeepingUnit
|
||||
from ..routers.calculate_nutrition import calculate_nutrition, report_nutrition
|
||||
from ..routers.calculate_prices import calculate_prices
|
||||
from ..schemas.nutritional_information import NutritionalInformation
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
@@ -151,7 +150,7 @@ def check_recursion(product: uuid.UUID, visited: set[uuid.UUID], db: Session) ->
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail="Recipe recursion. Some ingredient recipe contains parent recipe.",
|
||||
)
|
||||
recipe: Recipe = (
|
||||
recipe = (
|
||||
db.execute(select(Recipe).join(Recipe.items).join(Recipe.sku).where(StockKeepingUnit.product_id == product))
|
||||
.unique()
|
||||
.scalar_one_or_none()
|
||||
@@ -306,7 +305,7 @@ def get_report(
|
||||
return StreamingResponse(e, media_type="text/xlsx", headers=headers)
|
||||
|
||||
|
||||
def excel(prices: list[tuple[str, str, Decimal, Decimal, Decimal]], recipes: list[Recipe]) -> BytesIO:
|
||||
def excel(prices: list[tuple[str, str, Decimal]], recipes: list[Recipe]) -> BytesIO:
|
||||
wb = Workbook()
|
||||
wb.active.title = "Rate List"
|
||||
wb.active.cell(row=1, column=1, value="Name")
|
||||
@@ -364,25 +363,6 @@ def get_nutrition(
|
||||
list_: list[NutritionalInformation] = []
|
||||
with SessionFuture() as db:
|
||||
list_ = report_nutrition(db)
|
||||
# q = (
|
||||
# select(Recipe)
|
||||
# .join(Recipe.sku)
|
||||
# .join(StockKeepingUnit.product)
|
||||
# .join(Product.product_group)
|
||||
# .where(or_(ProductGroup.nutritional == True, ProductGroup.ice_cream == True)) # noqa: E712
|
||||
# .options(
|
||||
# contains_eager(Recipe.sku, StockKeepingUnit.product, Product.product_group),
|
||||
# )
|
||||
# )
|
||||
# list_ = [
|
||||
# NutritionalInformation(
|
||||
# name=i.sku.product.name,
|
||||
# units=i.sku.units,
|
||||
# product_group=i.sku.product.product_group.name,
|
||||
# **i.sku.product,
|
||||
# )
|
||||
# for i in db.execute(q).unique().scalars().all()
|
||||
# ]
|
||||
e = nut(sorted(list_, key=lambda r: r.name))
|
||||
e.seek(0)
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
import brewman.schemas.recipe_template as schemas
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Security, status
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
import brewman.schemas.recipe_template as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.recipe_template import RecipeTemplate
|
||||
@@ -26,7 +26,7 @@ def save(
|
||||
date_ = data.date_ if data.date_ is not None else datetime.date.today()
|
||||
if data.selected:
|
||||
db.execute(update(RecipeTemplate).values(selected=False))
|
||||
item = RecipeTemplate(id=None, name=data.name, date_=date_, text=data.text, selected=data.selected)
|
||||
item = RecipeTemplate(name=data.name, date_=date_, text=data.text, selected=data.selected)
|
||||
db.add(item)
|
||||
db.commit()
|
||||
return None
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.balance_sheet as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql.expression import desc, func, select
|
||||
|
||||
import brewman.schemas.balance_sheet as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.cash_flow as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql.expression import desc, func, select
|
||||
|
||||
import brewman.schemas.cash_flow as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
|
||||
@@ -3,13 +3,13 @@ import uuid
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.closing_stock as schemas
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request, Security, status
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session, contains_eager
|
||||
from sqlalchemy.sql.expression import delete, distinct, func, or_, select, update
|
||||
|
||||
import brewman.schemas.closing_stock as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
@@ -244,6 +244,9 @@ def save_route(
|
||||
detail="Products cannot be issued to overall",
|
||||
)
|
||||
if len([i for i in data.items if i.physical > i.quantity]) > 0:
|
||||
x = [i for i in data.items if i.physical > i.quantity]
|
||||
for y in x:
|
||||
print(y)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail="Physical Quantity cannot be more than computed quality.",
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.daybook as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.daybook as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
@@ -74,10 +74,10 @@ def build_report(start_date: date, finish_date: date, db: Session) -> list[schem
|
||||
for journal in voucher.journals:
|
||||
if journal.debit == 1:
|
||||
debit += journal.amount
|
||||
name_debit += "{0} / ".format(journal.account.name)
|
||||
name_debit += f"{journal.account.name} / "
|
||||
else:
|
||||
credit += journal.amount
|
||||
name_credit += "{0} / ".format(journal.account.name)
|
||||
name_credit += f"{journal.account.name} / "
|
||||
name_debit = name_debit[:-3]
|
||||
name_credit = name_credit[:-3]
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
from collections.abc import Sequence
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from decimal import Decimal
|
||||
from typing import Sequence
|
||||
|
||||
import brewman.schemas.entries as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, Security
|
||||
from sqlalchemy import desc, not_, or_, select
|
||||
from sqlalchemy.orm import Session, contains_eager
|
||||
from sqlalchemy.sql.functions import count
|
||||
|
||||
import brewman.schemas.entries as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...db.session import SessionFuture
|
||||
from ...models.journal import Journal
|
||||
@@ -44,7 +44,7 @@ def build_report(
|
||||
)
|
||||
)
|
||||
sq = select(Voucher.id)
|
||||
counts = select(count(Voucher.id)) # type: ignore[no-untyped-call]
|
||||
counts = select(count(Voucher.id))
|
||||
if start_date is not None:
|
||||
sd = datetime.combine(start_date, time(5, 30))
|
||||
sq = sq.where(or_(Voucher.creation_date >= sd, Voucher.last_edit_date >= sd))
|
||||
|
||||
@@ -3,13 +3,13 @@ import uuid
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.ledger as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql.expression import func, select
|
||||
|
||||
import brewman.schemas.ledger as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
@@ -97,7 +97,7 @@ def build_report(account_id: uuid.UUID, start_date: str, finish_date: str, db: S
|
||||
debit = Decimal(0)
|
||||
for journal in voucher.journals:
|
||||
if journal.debit != journal_debit:
|
||||
name += "{0} / ".format(journal.account.name)
|
||||
name += f"{journal.account.name} / "
|
||||
name = name[:-3]
|
||||
body.append(
|
||||
schemas.LedgerItem(
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from datetime import date, datetime
|
||||
|
||||
import brewman.schemas.net_transactions as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql.expression import desc, func, select
|
||||
|
||||
import brewman.schemas.net_transactions as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
from fastapi import APIRouter, Security
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session, contains_eager, joinedload
|
||||
|
||||
import brewman.schemas.non_contract_purchase as schemas
|
||||
|
||||
from brewman.core.security import get_current_active_user as get_user
|
||||
@@ -11,9 +15,6 @@ from brewman.models.stock_keeping_unit import StockKeepingUnit
|
||||
from brewman.models.voucher import Voucher
|
||||
from brewman.models.voucher_type import VoucherType
|
||||
from brewman.schemas.user import UserToken
|
||||
from fastapi import APIRouter, Security
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session, contains_eager, joinedload
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -3,12 +3,12 @@ import uuid
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.product_ledger as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
from sqlalchemy.sql.expression import func, select
|
||||
|
||||
import brewman.schemas.product_ledger as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
@@ -72,7 +72,7 @@ def build_report(
|
||||
running_total_q, running_total_a, opening = opening_balance(product_id, start_date, db)
|
||||
body = opening
|
||||
|
||||
query: list[tuple[Voucher, Inventory, Journal, StockKeepingUnit]] = db.execute(
|
||||
query = db.execute(
|
||||
select(Voucher, Inventory, Journal, StockKeepingUnit)
|
||||
.join(Voucher.journals)
|
||||
.join(Voucher.inventories)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.profit_loss as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql.expression import desc, func, select
|
||||
|
||||
import brewman.schemas.profit_loss as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from datetime import date, datetime
|
||||
|
||||
import brewman.schemas.purchase_entries as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session, contains_eager
|
||||
|
||||
import brewman.schemas.purchase_entries as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.purchases as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql.expression import desc, func, select
|
||||
|
||||
import brewman.schemas.purchases as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
|
||||
@@ -3,12 +3,12 @@ import uuid
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.raw_material_cost as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql.expression import case, func, select
|
||||
|
||||
import brewman.schemas.raw_material_cost as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
|
||||
@@ -3,13 +3,13 @@ import uuid
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.reconcile as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
from sqlalchemy.sql.expression import and_, func, or_, select
|
||||
|
||||
import brewman.schemas.reconcile as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
@@ -97,7 +97,7 @@ def build_report(
|
||||
debit = Decimal(0)
|
||||
for journal in voucher.journals:
|
||||
if journal.debit != journal_debit:
|
||||
name += "{0} / ".format(journal.account.name)
|
||||
name += f"{journal.account.name} / "
|
||||
name = name[:-3]
|
||||
body.append(
|
||||
schemas.ReconcileItem(
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import brewman.schemas.stock_movement as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy.orm import Session, contains_eager
|
||||
from sqlalchemy.sql.expression import func, select
|
||||
|
||||
import brewman.schemas.stock_movement as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from datetime import date, datetime
|
||||
|
||||
import brewman.schemas.trial_balance as schemas
|
||||
|
||||
from fastapi import APIRouter, Request, Security
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy.orm import Session, contains_eager, joinedload
|
||||
from sqlalchemy.sql.expression import func, select
|
||||
|
||||
import brewman.schemas.trial_balance as schemas
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...core.session import get_finish_date, get_start_date, set_period
|
||||
from ...db.session import SessionFuture
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import uuid
|
||||
|
||||
from typing import Sequence
|
||||
|
||||
import brewman.schemas.role as schemas
|
||||
from collections.abc import Sequence
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Security, status
|
||||
from sqlalchemy import select
|
||||
@@ -10,6 +8,8 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql.functions import count
|
||||
|
||||
import brewman.schemas.role as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.permission import Permission
|
||||
@@ -135,7 +135,7 @@ def role_info(item: Role, db: Session) -> schemas.Role:
|
||||
schemas.PermissionItem(
|
||||
id_=p.id,
|
||||
name=p.name,
|
||||
enabled=True if p in item.permissions else False,
|
||||
enabled=p in item.permissions,
|
||||
)
|
||||
for p in db.execute(select(Permission).order_by(Permission.name)).scalars().all()
|
||||
],
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import uuid
|
||||
|
||||
from typing import Sequence
|
||||
|
||||
import brewman.schemas.user as schemas
|
||||
from collections.abc import Sequence
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.user as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.attendance import Attendance
|
||||
@@ -185,7 +185,7 @@ def user_info(item: User, db: Session, user: UserToken) -> schemas.User:
|
||||
schemas.RoleItem(
|
||||
id_=r.id,
|
||||
name=r.name,
|
||||
enabled=True if r in item.roles else False,
|
||||
enabled=r in item.roles,
|
||||
)
|
||||
for r in db.execute(select(Role).order_by(Role.name)).scalars().all()
|
||||
]
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import uuid
|
||||
|
||||
from collections.abc import Sequence
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
from typing import Sequence
|
||||
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Security, status
|
||||
from sqlalchemy import and_, distinct, func, or_, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import brewman.schemas.voucher as output
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_first_day
|
||||
from ..db.session import SessionFuture
|
||||
@@ -332,9 +332,7 @@ def blank_voucher(info: BlankVoucherInfo, db: Session) -> output.Voucher:
|
||||
else:
|
||||
j_account = AccountBase.cash_in_hand()
|
||||
json_voucher.journals.append(output.Journal(account=j_account, amount=Decimal(0), debit=1))
|
||||
elif info.type_ == VoucherType.PURCHASE:
|
||||
json_voucher.vendor = AccountBase.local_purchase()
|
||||
elif info.type_ == VoucherType.PURCHASE_RETURN:
|
||||
elif info.type_ == VoucherType.PURCHASE or info.type_ == VoucherType.PURCHASE_RETURN:
|
||||
json_voucher.vendor = AccountBase.local_purchase()
|
||||
elif info.type_ == VoucherType.ISSUE:
|
||||
if info.source is not None:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import brewman.schemas.account_type as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
import brewman.schemas.account_type as schemas
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
|
||||
class AccountType(BaseModel):
|
||||
id_: int
|
||||
|
||||
@@ -2,8 +2,6 @@ import uuid
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.attendance_type import AttendanceType
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
@@ -12,6 +10,9 @@ from pydantic import (
|
||||
field_validator,
|
||||
)
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.attendance_type import AttendanceType
|
||||
|
||||
|
||||
class AttendanceItem(BaseModel):
|
||||
id_: uuid.UUID
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
from . import Daf
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.product import ProductLink
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from . import Daf
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
from datetime import date, datetime
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.account import AccountLink
|
||||
from brewman.schemas.attendance_type import AttendanceType
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
@@ -11,6 +8,10 @@ from pydantic import (
|
||||
field_validator,
|
||||
)
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.account import AccountLink
|
||||
from brewman.schemas.attendance_type import AttendanceType
|
||||
|
||||
|
||||
class EmployeeAttendanceItem(BaseModel):
|
||||
date_: date
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.employee import EmployeeLink
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class EmployeeBenefit(BaseModel):
|
||||
|
||||
@@ -2,7 +2,6 @@ import uuid
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
@@ -11,6 +10,8 @@ from pydantic import (
|
||||
field_validator,
|
||||
)
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
|
||||
class Fingerprint(BaseModel):
|
||||
id_: uuid.UUID
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
|
||||
class ImageUpload(BaseModel):
|
||||
id_: uuid.UUID | None = None
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
from . import Daf
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.batch import Batch
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from . import Daf
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
from . import Daf
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.account import AccountLink
|
||||
from brewman.schemas.cost_centre import CostCentreLink
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from . import Daf
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
|
||||
class PermissionItem(BaseModel):
|
||||
id_: uuid.UUID
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
from . import Daf
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.product import ProductLink
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from . import Daf
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.product import ProductLink
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from . import Daf
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
from .permission import PermissionItem
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
|
||||
|
||||
class UserLink(BaseModel):
|
||||
id_: uuid.UUID
|
||||
|
||||
+30
-16
@@ -7,30 +7,30 @@ authors = ["tanshu <git@tanshu.com>"]
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11"
|
||||
uvicorn = {extras = ["standard"], version = "^0.23.2"}
|
||||
fastapi = {extras = ["all"], version = "^0.101.1"}
|
||||
fastapi = {extras = ["all"], version = "^0.110.1"}
|
||||
python-jose = {extras = ["cryptography"], version = "^3.3.0"}
|
||||
passlib = {extras = ["bcrypt"], version = "^1.7.4"}
|
||||
psycopg2-binary = "^2.9.7"
|
||||
SQLAlchemy = "^2.0.19"
|
||||
python-multipart = "^0.0.6"
|
||||
psycopg2-binary = "^2.9.9"
|
||||
SQLAlchemy = "^2.0.29"
|
||||
python-multipart = "^0.0.9"
|
||||
PyJWT = "^2.8.0"
|
||||
alembic = "^1.11.2"
|
||||
alembic = "^1.13.1"
|
||||
itsdangerous = "^2.1.2"
|
||||
python-dotenv = "^1.0.0"
|
||||
pydantic = {extras = ["dotenv"], version = "^2.1.1"}
|
||||
starlette = "^0.27.0"
|
||||
pandas = "^2.0.0"
|
||||
python-dotenv = "^1.0.1"
|
||||
pydantic = {extras = ["dotenv"], version = "^2.6.2"}
|
||||
starlette = "^0.36.3"
|
||||
pandas = "^2.2.2"
|
||||
arq = "^0.25.0"
|
||||
openpyxl = "^3.1.2"
|
||||
gunicorn = "^21.2.0"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
pre-commit = "^3.3.3"
|
||||
mypy = "^1.4.1"
|
||||
pre-commit = "^3.7.0"
|
||||
mypy = "^1.9.0"
|
||||
types-python-jose = "^3.3.4.8"
|
||||
ruff = "^0.1.9"
|
||||
bandit = "^1.7.5"
|
||||
safety = "^2.3.5"
|
||||
ruff = "^0.3.7"
|
||||
bandit = "^1.7.8"
|
||||
# safety = "^3.0.1"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
@@ -56,7 +56,21 @@ exclude = [
|
||||
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
||||
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
|
||||
# McCabe complexity (`C901`) by default.
|
||||
select = ["E4", "E7", "E9", "F"]
|
||||
# select = ["E4", "E7", "E9", "F"]
|
||||
select = [
|
||||
# pycodestyle
|
||||
"E",
|
||||
# Pyflakes
|
||||
"F",
|
||||
# pyupgrade
|
||||
"UP",
|
||||
# flake8-bugbear
|
||||
# "B",
|
||||
# flake8-simplify
|
||||
"SIM",
|
||||
# isort
|
||||
"I",
|
||||
]
|
||||
ignore = ["E203", "E501"]
|
||||
|
||||
# Allow fix for all enabled rules (when `--fix`) is provided.
|
||||
@@ -65,7 +79,7 @@ fixable = ["ALL"]
|
||||
# Avoid trying to fix flake8-bugbear (`B`) violations.
|
||||
unfixable = ["B", "F401"]
|
||||
|
||||
[tool.ruff.isort]
|
||||
[tool.ruff.lint.isort]
|
||||
# include-trailing-comma = true
|
||||
lines-after-imports = 2
|
||||
lines-between-types = 1
|
||||
|
||||
+4
-70
@@ -8,73 +8,7 @@
|
||||
- "{{ var_file }}"
|
||||
- vars/default.yml
|
||||
|
||||
tasks:
|
||||
- name: Copy dockerfile
|
||||
synchronize:
|
||||
src: app
|
||||
dest: "/tmp/{{ host_directory }}"
|
||||
|
||||
- name: Build brewman image
|
||||
docker_image:
|
||||
name: brewman:latest
|
||||
build:
|
||||
path: "/tmp/{{ host_directory }}/"
|
||||
dockerfile: "/tmp/{{ host_directory }}/Dockerfile"
|
||||
pull: yes
|
||||
state: present
|
||||
source: build
|
||||
|
||||
- name: Ensure Host Directory exists
|
||||
file:
|
||||
path: "/var/lib/{{ host_directory }}"
|
||||
state: directory
|
||||
|
||||
- name: Upload the .env file
|
||||
template:
|
||||
src: "files/.env"
|
||||
dest: "/var/lib/{{ host_directory }}/.env"
|
||||
|
||||
- name: Create brewman container
|
||||
docker_container:
|
||||
name: "{{ host_directory }}"
|
||||
image: brewman:latest
|
||||
state: started
|
||||
restart_policy: "unless-stopped"
|
||||
env_file: "/var/lib/{{ host_directory }}/.env"
|
||||
etc_hosts:
|
||||
db : "{{ db_host }}"
|
||||
# links:
|
||||
# - "postgres:db"
|
||||
published_ports:
|
||||
- "127.0.0.1:{{ host_port }}:80"
|
||||
volumes:
|
||||
- "/var/lib/{{ host_directory }}/frontend:/frontend"
|
||||
|
||||
|
||||
- name: Check if Nginx conf file exists
|
||||
stat: path="/etc/nginx/sites-available/{{ http_conf }}"
|
||||
register: status
|
||||
|
||||
- name: No need to reload Nginx
|
||||
debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }}
|
||||
|
||||
- name: Set Nginx conf file
|
||||
when: status.stat.exists == false
|
||||
template:
|
||||
src: "files/nginx.conf.j2"
|
||||
dest: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||
|
||||
- name: Enable new site
|
||||
when: status.stat.exists == false
|
||||
file:
|
||||
src: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
|
||||
state: link
|
||||
notify: Reload Nginx
|
||||
|
||||
handlers:
|
||||
- name: Reload Nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
|
||||
roles:
|
||||
- upload
|
||||
- brewman
|
||||
- nginx
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
# Tasks for docker role
|
||||
- name: Build brewman image
|
||||
docker_image:
|
||||
name: brewman:latest
|
||||
build:
|
||||
path: "/tmp/{{ host_directory }}/"
|
||||
dockerfile: "/tmp/{{ host_directory }}/Dockerfile"
|
||||
pull: yes
|
||||
state: present
|
||||
source: build
|
||||
|
||||
- name: Create brewman container
|
||||
docker_container:
|
||||
name: "{{ host_directory }}"
|
||||
image: brewman:latest
|
||||
state: started
|
||||
restart_policy: "unless-stopped"
|
||||
env_file: "/var/lib/{{ host_directory }}/.env"
|
||||
etc_hosts:
|
||||
db : "{{ db_host }}"
|
||||
# links:
|
||||
# - "postgres:db"
|
||||
published_ports:
|
||||
- "127.0.0.1:{{ host_port }}:80"
|
||||
volumes:
|
||||
- "/var/lib/{{ host_directory }}/frontend:/frontend"
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
# Handlers for Nginx role
|
||||
- name: Reload Nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
# Tasks for Nginx role
|
||||
- name: Check if Nginx conf file exists
|
||||
stat:
|
||||
path: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||
register: status
|
||||
|
||||
- name: No need to reload Nginx
|
||||
debug:
|
||||
msg: "No need to reload Nginx as sites-available entries have already been created"
|
||||
|
||||
- name: Set Nginx conf file
|
||||
when: status.stat.exists == false
|
||||
template:
|
||||
src: "files/nginx.conf.j2"
|
||||
dest: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||
|
||||
- name: Enable new site
|
||||
when: status.stat.exists == false
|
||||
file:
|
||||
src: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
|
||||
state: link
|
||||
notify: Reload Nginx
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
# Tasks for upload role
|
||||
- name: Ensure Temporary Directory exists
|
||||
file:
|
||||
path: "/tmp/{{ host_directory }}"
|
||||
state: directory
|
||||
|
||||
- name: Copy dockerfile
|
||||
synchronize:
|
||||
src: app
|
||||
dest: "/tmp/{{ host_directory }}"
|
||||
|
||||
- name: Ensure Host Directory exists
|
||||
file:
|
||||
path: "/var/lib/{{ host_directory }}"
|
||||
state: directory
|
||||
|
||||
- name: Upload the .env file
|
||||
template:
|
||||
src: "files/.env"
|
||||
dest: "/var/lib/{{ host_directory }}/.env"
|
||||
Reference in new issue
Block a user