Fix: Save account error was because in constructor type did not end in underscore
Fix: Employee save as checking for in None instead of is None Feature: Checking the existing token for validity in constructor of auth service, this should prevent last login showing Feature: Moved the middleware secret key into the env file Chore: Replaced my own GUID() with postgres UUID() type
This commit is contained in:
parent
6ccb3634be
commit
ad8a2d2cc3
.env
brewman
overlord
setup.py
3
.env
3
.env
@ -10,7 +10,10 @@ POSTGRES_USER=
|
|||||||
POSTGRES_PASSWORD=
|
POSTGRES_PASSWORD=
|
||||||
POSTGRES_DB=
|
POSTGRES_DB=
|
||||||
|
|
||||||
|
# openssl rand -hex 32
|
||||||
SECRET_KEY=
|
SECRET_KEY=
|
||||||
|
# openssl rand -hex 5
|
||||||
|
MIDDLEWARE_SECRET_KEY=
|
||||||
ALGORITHM=HS256
|
ALGORITHM=HS256
|
||||||
JWT_TOKEN_EXPIRE_MINUTES=30
|
JWT_TOKEN_EXPIRE_MINUTES=30
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ from pydantic import BaseSettings, PostgresDsn, validator
|
|||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
# openssl rand -hex 32
|
# openssl rand -hex 32
|
||||||
SECRET_KEY: str = secrets.token_urlsafe(32)
|
SECRET_KEY: str = secrets.token_urlsafe(32)
|
||||||
|
MIDDLEWARE_SECRET_KEY: str = secrets.token_urlsafe(5)
|
||||||
ALGORITHM: str = "HS256"
|
ALGORITHM: str = "HS256"
|
||||||
JWT_TOKEN_EXPIRE_MINUTES: int = 30
|
JWT_TOKEN_EXPIRE_MINUTES: int = 30
|
||||||
HOST: str = "0.0.0.0"
|
HOST: str = "0.0.0.0"
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
from brewman.db.base_class import Base # noqa
|
from brewman.db.base_class import Base # noqa
|
||||||
from brewman.models import (
|
from brewman.models import (
|
||||||
Client,
|
Client,
|
||||||
user_group,
|
user_role,
|
||||||
role_group,
|
role_permission,
|
||||||
User,
|
User,
|
||||||
LoginHistory,
|
LoginHistory,
|
||||||
Role,
|
Role,
|
||||||
|
@ -61,7 +61,7 @@ Base.metadata.create_all(bind=engine)
|
|||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
app.add_middleware(SessionMiddleware, secret_key="c982367648")
|
app.add_middleware(SessionMiddleware, secret_key=settings.MIDDLEWARE_SECRET_KEY)
|
||||||
app.include_router(db_image.router, prefix="/db-image", tags=["db-image"])
|
app.include_router(db_image.router, prefix="/db-image", tags=["db-image"])
|
||||||
app.include_router(login.router, tags=["login"])
|
app.include_router(login.router, tags=["login"])
|
||||||
app.include_router(account.router, prefix="/api/accounts", tags=["accounts"])
|
app.include_router(account.router, prefix="/api/accounts", tags=["accounts"])
|
||||||
|
@ -8,7 +8,7 @@ from sqlalchemy.schema import ForeignKey, Table
|
|||||||
from sqlalchemy import Column, Boolean, Unicode, Integer, DateTime, UniqueConstraint
|
from sqlalchemy import Column, Boolean, Unicode, Integer, DateTime, UniqueConstraint
|
||||||
from sqlalchemy.orm import synonym, relationship, Session
|
from sqlalchemy.orm import synonym, relationship, Session
|
||||||
|
|
||||||
from brewman.models.guidtype import GUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from .meta import Base
|
from .meta import Base
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ def encrypt(val):
|
|||||||
class Client(Base):
|
class Client(Base):
|
||||||
__tablename__ = "auth_clients"
|
__tablename__ = "auth_clients"
|
||||||
|
|
||||||
id = Column("client_id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("client_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
code = Column("code", Integer, unique=True, nullable=False)
|
code = Column("code", Integer, unique=True, nullable=False)
|
||||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||||
enabled = Column("enabled", Boolean, nullable=False)
|
enabled = Column("enabled", Boolean, nullable=False)
|
||||||
@ -51,24 +51,24 @@ class Client(Base):
|
|||||||
user_role = Table(
|
user_role = Table(
|
||||||
"user_roles",
|
"user_roles",
|
||||||
Base.metadata,
|
Base.metadata,
|
||||||
Column("id", GUID(), primary_key=True, default=uuid.uuid4),
|
Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4),
|
||||||
Column("user_id", GUID(), ForeignKey("auth_users.id")),
|
Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.id")),
|
||||||
Column("role_id", GUID(), ForeignKey("auth_roles.id")),
|
Column("role_id", UUID(as_uuid=True), ForeignKey("auth_roles.id")),
|
||||||
)
|
)
|
||||||
|
|
||||||
role_permission = Table(
|
role_permission = Table(
|
||||||
"role_permissions",
|
"role_permissions",
|
||||||
Base.metadata,
|
Base.metadata,
|
||||||
Column("id", GUID(), primary_key=True, default=uuid.uuid4),
|
Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4),
|
||||||
Column("permission_id", GUID(), ForeignKey("auth_permissions.id")),
|
Column("permission_id", UUID(as_uuid=True), ForeignKey("auth_permissions.id")),
|
||||||
Column("role_id", GUID(), ForeignKey("auth_roles.id")),
|
Column("role_id", UUID(as_uuid=True), ForeignKey("auth_roles.id")),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class User(Base):
|
class User(Base):
|
||||||
__tablename__ = "auth_users"
|
__tablename__ = "auth_users"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column("username", Unicode(255), unique=True)
|
name = Column("username", Unicode(255), unique=True)
|
||||||
_password = Column("password", Unicode(60))
|
_password = Column("password", Unicode(60))
|
||||||
locked_out = Column("disabled", Boolean)
|
locked_out = Column("disabled", Boolean)
|
||||||
@ -111,9 +111,9 @@ class User(Base):
|
|||||||
class LoginHistory(Base):
|
class LoginHistory(Base):
|
||||||
__tablename__ = "auth_login_history"
|
__tablename__ = "auth_login_history"
|
||||||
__table_args__ = (UniqueConstraint("user_id", "client_id", "date"),)
|
__table_args__ = (UniqueConstraint("user_id", "client_id", "date"),)
|
||||||
id = Column("login_history_id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("login_history_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
user_id = Column("user_id", GUID(), ForeignKey("auth_users.id"), nullable=False)
|
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.id"), nullable=False)
|
||||||
client_id = Column("client_id", GUID(), ForeignKey("auth_clients.client_id"), nullable=False)
|
client_id = Column("client_id", UUID(as_uuid=True), ForeignKey("auth_clients.client_id"), nullable=False)
|
||||||
date = Column("date", DateTime(timezone=True), nullable=False)
|
date = Column("date", DateTime(timezone=True), nullable=False)
|
||||||
|
|
||||||
def __init__(self, user_id=None, client_id=None, date=None, id_=None):
|
def __init__(self, user_id=None, client_id=None, date=None, id_=None):
|
||||||
@ -126,7 +126,7 @@ class LoginHistory(Base):
|
|||||||
class Role(Base):
|
class Role(Base):
|
||||||
__tablename__ = "auth_roles"
|
__tablename__ = "auth_roles"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column("name", Unicode(255), unique=True)
|
name = Column("name", Unicode(255), unique=True)
|
||||||
|
|
||||||
def __init__(self, name=None, id_=None):
|
def __init__(self, name=None, id_=None):
|
||||||
@ -137,7 +137,7 @@ class Role(Base):
|
|||||||
class Permission(Base):
|
class Permission(Base):
|
||||||
__tablename__ = "auth_permissions"
|
__tablename__ = "auth_permissions"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column("name", Unicode(255), unique=True)
|
name = Column("name", Unicode(255), unique=True)
|
||||||
|
|
||||||
roles = relationship("Role", secondary=role_permission, backref="permissions")
|
roles = relationship("Role", secondary=role_permission, backref="permissions")
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
import uuid
|
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
|
||||||
from sqlalchemy.dialects.sqlite import BLOB
|
|
||||||
from sqlalchemy.types import TypeDecorator, CHAR, Binary
|
|
||||||
|
|
||||||
|
|
||||||
class GUID(TypeDecorator):
|
|
||||||
"""Platform-independent GUID type.
|
|
||||||
|
|
||||||
Uses Postgresql's UUID type, otherwise uses
|
|
||||||
CHAR(32), storing as stringified hex values.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
impl = Binary
|
|
||||||
|
|
||||||
# if dialect.value == 'postgresql':
|
|
||||||
# impl = CHAR
|
|
||||||
# elif dialect.value == 'mysql':
|
|
||||||
# impl = MSBinary
|
|
||||||
# elif dialect.valie == 'sqlite':
|
|
||||||
# impl = Binary
|
|
||||||
# else:
|
|
||||||
# impl = Binary
|
|
||||||
|
|
||||||
def load_dialect_impl(self, dialect):
|
|
||||||
if dialect.name == "postgresql":
|
|
||||||
return dialect.type_descriptor(UUID())
|
|
||||||
elif dialect.name == "sqlite":
|
|
||||||
return dialect.type_descriptor(BLOB())
|
|
||||||
else:
|
|
||||||
return dialect.type_descriptor(CHAR(32))
|
|
||||||
|
|
||||||
def process_bind_param(self, value, dialect):
|
|
||||||
if value is None:
|
|
||||||
return None
|
|
||||||
elif dialect.name == "postgresql":
|
|
||||||
return str(value)
|
|
||||||
elif not isinstance(value, uuid.UUID):
|
|
||||||
raise ValueError("value %s is not a valid uuid.UUID" % value)
|
|
||||||
else:
|
|
||||||
return value.bytes
|
|
||||||
# if not isinstance(value, uuid.UUID):
|
|
||||||
# return "%.32x" % uuid.UUID(value)
|
|
||||||
# else:
|
|
||||||
# # hexstring
|
|
||||||
# return "%.32x" % value
|
|
||||||
|
|
||||||
def process_result_value(self, value, dialect=None):
|
|
||||||
if value is None:
|
|
||||||
return None
|
|
||||||
elif isinstance(value, bytes):
|
|
||||||
return uuid.UUID(bytes=value)
|
|
||||||
else:
|
|
||||||
return uuid.UUID(value)
|
|
||||||
|
|
||||||
def is_mutable(self):
|
|
||||||
return False
|
|
@ -15,7 +15,7 @@ from sqlalchemy import (
|
|||||||
)
|
)
|
||||||
from sqlalchemy.orm import relationship, Session
|
from sqlalchemy.orm import relationship, Session
|
||||||
|
|
||||||
from brewman.models.guidtype import GUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from .meta import Base
|
from .meta import Base
|
||||||
|
|
||||||
|
|
||||||
@ -23,15 +23,15 @@ class Product(Base):
|
|||||||
__tablename__ = "products"
|
__tablename__ = "products"
|
||||||
__table_args__ = (UniqueConstraint("name", "units"),)
|
__table_args__ = (UniqueConstraint("name", "units"),)
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
code = Column("code", Integer, unique=True)
|
code = Column("code", Integer, unique=True)
|
||||||
name = Column("name", Unicode(255), nullable=False)
|
name = Column("name", Unicode(255), nullable=False)
|
||||||
units = Column("units", Unicode(255), nullable=False)
|
units = Column("units", Unicode(255), nullable=False)
|
||||||
fraction = Column("fraction", Numeric, nullable=False)
|
fraction = Column("fraction", Numeric, nullable=False)
|
||||||
fraction_units = Column("fraction_units", Unicode(255), nullable=False)
|
fraction_units = Column("fraction_units", Unicode(255), nullable=False)
|
||||||
product_yield = Column("product_yield", Numeric, nullable=False)
|
product_yield = Column("product_yield", Numeric, nullable=False)
|
||||||
product_group_id = Column("product_group_id", GUID(), ForeignKey("product_groups.id"), nullable=False,)
|
product_group_id = Column("product_group_id", UUID(as_uuid=True), ForeignKey("product_groups.id"), nullable=False,)
|
||||||
account_id = Column("account_id", GUID(), ForeignKey("accounts.id"), nullable=False)
|
account_id = Column("account_id", UUID(as_uuid=True), ForeignKey("accounts.id"), nullable=False)
|
||||||
price = Column("cost_price", Numeric, nullable=False)
|
price = Column("cost_price", Numeric, nullable=False)
|
||||||
sale_price = Column("sale_price", Numeric, nullable=False)
|
sale_price = Column("sale_price", Numeric, nullable=False)
|
||||||
is_active = Column("is_active", Boolean, nullable=False)
|
is_active = Column("is_active", Boolean, nullable=False)
|
||||||
@ -118,8 +118,8 @@ class Product(Base):
|
|||||||
class Recipe(Base):
|
class Recipe(Base):
|
||||||
__tablename__ = "recipes"
|
__tablename__ = "recipes"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
product_id = Column("product_id", GUID(), ForeignKey("products.id"), nullable=False)
|
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||||
|
|
||||||
quantity = Column("quantity", Numeric, nullable=False)
|
quantity = Column("quantity", Numeric, nullable=False)
|
||||||
cost_price = Column("cost_price", Numeric, nullable=False)
|
cost_price = Column("cost_price", Numeric, nullable=False)
|
||||||
@ -162,9 +162,9 @@ class RecipeItem(Base):
|
|||||||
__tablename__ = "recipe_items"
|
__tablename__ = "recipe_items"
|
||||||
__table_args__ = (UniqueConstraint("recipe_id", "product_id"),)
|
__table_args__ = (UniqueConstraint("recipe_id", "product_id"),)
|
||||||
|
|
||||||
id = Column("recipe_item_id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("recipe_item_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
recipe_id = Column("recipe_id", GUID(), ForeignKey("recipes.id"), nullable=False)
|
recipe_id = Column("recipe_id", UUID(as_uuid=True), ForeignKey("recipes.id"), nullable=False)
|
||||||
product_id = Column("product_id", GUID(), ForeignKey("products.id"), nullable=False)
|
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||||
quantity = Column("quantity", Integer, nullable=False)
|
quantity = Column("quantity", Integer, nullable=False)
|
||||||
price = Column("price", Integer, nullable=False)
|
price = Column("price", Integer, nullable=False)
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ class RecipeItem(Base):
|
|||||||
class ProductGroup(Base):
|
class ProductGroup(Base):
|
||||||
__tablename__ = "product_groups"
|
__tablename__ = "product_groups"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column("name", Unicode(255), unique=True)
|
name = Column("name", Unicode(255), unique=True)
|
||||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ class ProductGroup(Base):
|
|||||||
class CostCentre(Base):
|
class CostCentre(Base):
|
||||||
__tablename__ = "cost_centres"
|
__tablename__ = "cost_centres"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column("name", Unicode(255), unique=True)
|
name = Column("name", Unicode(255), unique=True)
|
||||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ class CostCentre(Base):
|
|||||||
class AccountBase(Base):
|
class AccountBase(Base):
|
||||||
__tablename__ = "accounts"
|
__tablename__ = "accounts"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
code = Column("code", Integer, nullable=False)
|
code = Column("code", Integer, nullable=False)
|
||||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||||
type = Column("type", Integer, nullable=False)
|
type = Column("type", Integer, nullable=False)
|
||||||
@ -251,7 +251,7 @@ class AccountBase(Base):
|
|||||||
is_starred = Column("is_starred", Boolean, nullable=False)
|
is_starred = Column("is_starred", Boolean, nullable=False)
|
||||||
is_active = Column("is_active", Boolean, nullable=False)
|
is_active = Column("is_active", Boolean, nullable=False)
|
||||||
is_reconcilable = Column("is_reconcilable", Boolean, nullable=False)
|
is_reconcilable = Column("is_reconcilable", Boolean, nullable=False)
|
||||||
cost_centre_id = Column("cost_centre_id", GUID(), ForeignKey("cost_centres.id"), nullable=False)
|
cost_centre_id = Column("cost_centre_id", UUID(as_uuid=True), ForeignKey("cost_centres.id"), nullable=False)
|
||||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||||
|
|
||||||
__mapper_args__ = {"polymorphic_on": account_type}
|
__mapper_args__ = {"polymorphic_on": account_type}
|
||||||
@ -369,7 +369,7 @@ class Employee(AccountBase):
|
|||||||
__tablename__ = "employees"
|
__tablename__ = "employees"
|
||||||
__mapper_args__ = {"polymorphic_identity": "employees"}
|
__mapper_args__ = {"polymorphic_identity": "employees"}
|
||||||
|
|
||||||
id = Column("id", GUID(), ForeignKey(AccountBase.id), primary_key=True)
|
id = Column("id", UUID(as_uuid=True), ForeignKey(AccountBase.id), primary_key=True)
|
||||||
designation = Column("designation", Unicode(255), nullable=False)
|
designation = Column("designation", Unicode(255), nullable=False)
|
||||||
salary = Column("salary", Integer, nullable=False)
|
salary = Column("salary", Integer, nullable=False)
|
||||||
points = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
points = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
||||||
@ -409,7 +409,7 @@ class Employee(AccountBase):
|
|||||||
|
|
||||||
def create(self, db: Session):
|
def create(self, db: Session):
|
||||||
code = db.query(func.max(AccountBase.code)).filter(AccountBase.type == self.type).one()[0]
|
code = db.query(func.max(AccountBase.code)).filter(AccountBase.type == self.type).one()[0]
|
||||||
self.code = 1 if code in None else code + 1
|
self.code = 1 if code is None else code + 1
|
||||||
self.name += f" ({str(self.code)})"
|
self.name += f" ({str(self.code)})"
|
||||||
db.add(self)
|
db.add(self)
|
||||||
return self
|
return self
|
||||||
@ -508,7 +508,7 @@ class AccountType:
|
|||||||
class DbSetting(Base):
|
class DbSetting(Base):
|
||||||
__tablename__ = "settings"
|
__tablename__ = "settings"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||||
data = Column("data", PickleType)
|
data = Column("data", PickleType)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ from sqlalchemy.dialects.postgresql import BYTEA
|
|||||||
from sqlalchemy.ext.hybrid import hybrid_property
|
from sqlalchemy.ext.hybrid import hybrid_property
|
||||||
from sqlalchemy.orm import relationship, synonym, backref, Session
|
from sqlalchemy.orm import relationship, synonym, backref, Session
|
||||||
|
|
||||||
from brewman.models.guidtype import GUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from brewman.models.master import Product
|
from brewman.models.master import Product
|
||||||
from .meta import Base
|
from .meta import Base
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ class VoucherType:
|
|||||||
class Voucher(Base):
|
class Voucher(Base):
|
||||||
__tablename__ = "vouchers"
|
__tablename__ = "vouchers"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
date = Column("date", Date, nullable=False, index=True)
|
date = Column("date", Date, nullable=False, index=True)
|
||||||
narration = Column("narration", Unicode(1000), nullable=False)
|
narration = Column("narration", Unicode(1000), nullable=False)
|
||||||
is_reconciled = Column("is_reconciled", Boolean, nullable=False)
|
is_reconciled = Column("is_reconciled", Boolean, nullable=False)
|
||||||
@ -72,9 +72,9 @@ class Voucher(Base):
|
|||||||
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
||||||
last_edit_date = Column("last_edit_date", DateTime(timezone=True), nullable=False)
|
last_edit_date = Column("last_edit_date", DateTime(timezone=True), nullable=False)
|
||||||
_type = Column("voucher_type", Integer, nullable=False)
|
_type = Column("voucher_type", Integer, nullable=False)
|
||||||
user_id = Column("user_id", GUID(), ForeignKey("auth_users.id"), nullable=False)
|
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.id"), nullable=False)
|
||||||
posted = Column("is_posted", Boolean, nullable=False)
|
posted = Column("is_posted", Boolean, nullable=False)
|
||||||
poster_id = Column("poster_id", GUID(), ForeignKey("auth_users.id"))
|
poster_id = Column("poster_id", UUID(as_uuid=True), ForeignKey("auth_users.id"))
|
||||||
|
|
||||||
user = relationship("User", primaryjoin="User.id==Voucher.user_id", cascade=None)
|
user = relationship("User", primaryjoin="User.id==Voucher.user_id", cascade=None)
|
||||||
poster = relationship("User", primaryjoin="User.id==Voucher.poster_id", cascade=None)
|
poster = relationship("User", primaryjoin="User.id==Voucher.poster_id", cascade=None)
|
||||||
@ -136,12 +136,12 @@ class Voucher(Base):
|
|||||||
class Journal(Base):
|
class Journal(Base):
|
||||||
__tablename__ = "journals"
|
__tablename__ = "journals"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
debit = Column("debit", Integer)
|
debit = Column("debit", Integer)
|
||||||
amount = Column("amount", Numeric)
|
amount = Column("amount", Numeric)
|
||||||
voucher_id = Column("voucher_id", GUID(), ForeignKey("vouchers.id"), nullable=False, index=True)
|
voucher_id = Column("voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False, index=True)
|
||||||
account_id = Column("account_id", GUID(), ForeignKey("accounts.id"), nullable=False)
|
account_id = Column("account_id", UUID(as_uuid=True), ForeignKey("accounts.id"), nullable=False)
|
||||||
cost_centre_id = Column("cost_centre_id", GUID(), ForeignKey("cost_centres.id"), nullable=False)
|
cost_centre_id = Column("cost_centre_id", UUID(as_uuid=True), ForeignKey("cost_centres.id"), nullable=False)
|
||||||
|
|
||||||
voucher = relationship("Voucher", back_populates="journals")
|
voucher = relationship("Voucher", back_populates="journals")
|
||||||
account = relationship("AccountBase", back_populates="journals")
|
account = relationship("AccountBase", back_populates="journals")
|
||||||
@ -167,9 +167,9 @@ class Journal(Base):
|
|||||||
|
|
||||||
class EmployeeBenefit(Base):
|
class EmployeeBenefit(Base):
|
||||||
__tablename__ = "employee_benefit"
|
__tablename__ = "employee_benefit"
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
voucher_id = Column("voucher_id", GUID(), ForeignKey("vouchers.id"), nullable=False)
|
voucher_id = Column("voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False)
|
||||||
journal_id = Column("journal_id", GUID(), ForeignKey("journals.id"), nullable=False)
|
journal_id = Column("journal_id", UUID(as_uuid=True), ForeignKey("journals.id"), nullable=False)
|
||||||
gross_salary = Column("gross_salary", Integer)
|
gross_salary = Column("gross_salary", Integer)
|
||||||
days_worked = Column("days_worked", Integer)
|
days_worked = Column("days_worked", Integer)
|
||||||
esi_ee = Column("esi_employee", Integer)
|
esi_ee = Column("esi_employee", Integer)
|
||||||
@ -210,9 +210,9 @@ class EmployeeBenefit(Base):
|
|||||||
|
|
||||||
class Incentive(Base):
|
class Incentive(Base):
|
||||||
__tablename__ = "incentives"
|
__tablename__ = "incentives"
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
voucher_id = Column("voucher_id", GUID(), ForeignKey("vouchers.id"), nullable=False)
|
voucher_id = Column("voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False)
|
||||||
journal_id = Column("journal_id", GUID(), ForeignKey("journals.id"), nullable=False)
|
journal_id = Column("journal_id", UUID(as_uuid=True), ForeignKey("journals.id"), nullable=False)
|
||||||
days_worked = Column("days_worked", Numeric(precision=5, scale=1), nullable=False)
|
days_worked = Column("days_worked", Numeric(precision=5, scale=1), nullable=False)
|
||||||
points = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
points = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
||||||
|
|
||||||
@ -234,10 +234,10 @@ class Incentive(Base):
|
|||||||
class Inventory(Base):
|
class Inventory(Base):
|
||||||
__tablename__ = "inventories"
|
__tablename__ = "inventories"
|
||||||
__table_args__ = (UniqueConstraint("voucher_id", "batch_id"),)
|
__table_args__ = (UniqueConstraint("voucher_id", "batch_id"),)
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
voucher_id = Column("voucher_id", GUID(), ForeignKey("vouchers.id"), nullable=False, index=True)
|
voucher_id = Column("voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False, index=True)
|
||||||
product_id = Column("product_id", GUID(), ForeignKey("products.id"), nullable=False)
|
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||||
batch_id = Column("batch_id", GUID(), ForeignKey("batches.id"), nullable=False)
|
batch_id = Column("batch_id", UUID(as_uuid=True), ForeignKey("batches.id"), nullable=False)
|
||||||
quantity = Column("quantity", Numeric)
|
quantity = Column("quantity", Numeric)
|
||||||
rate = Column("rate", Numeric)
|
rate = Column("rate", Numeric)
|
||||||
tax = Column("tax", Numeric)
|
tax = Column("tax", Numeric)
|
||||||
@ -281,9 +281,9 @@ class Inventory(Base):
|
|||||||
class Batch(Base):
|
class Batch(Base):
|
||||||
__tablename__ = "batches"
|
__tablename__ = "batches"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column("name", Date, nullable=False)
|
name = Column("name", Date, nullable=False)
|
||||||
product_id = Column("product_id", GUID(), ForeignKey("products.id"), nullable=False)
|
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||||
quantity_remaining = Column("quantity_remaining", Numeric)
|
quantity_remaining = Column("quantity_remaining", Numeric)
|
||||||
rate = Column("rate", Numeric)
|
rate = Column("rate", Numeric)
|
||||||
tax = Column("tax", Numeric)
|
tax = Column("tax", Numeric)
|
||||||
@ -327,13 +327,13 @@ class Batch(Base):
|
|||||||
class Attendance(Base):
|
class Attendance(Base):
|
||||||
__tablename__ = "attendances"
|
__tablename__ = "attendances"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
employee_id = Column("employee_id", GUID(), ForeignKey("employees.id"))
|
employee_id = Column("employee_id", UUID(as_uuid=True), ForeignKey("employees.id"))
|
||||||
date = Column("date", Date, nullable=False)
|
date = Column("date", Date, nullable=False)
|
||||||
attendance_type = Column("attendance_type", Integer)
|
attendance_type = Column("attendance_type", Integer)
|
||||||
amount = Column("amount", Numeric)
|
amount = Column("amount", Numeric)
|
||||||
creation_date = Column("creation_date", DateTime(timezone=True))
|
creation_date = Column("creation_date", DateTime(timezone=True))
|
||||||
user_id = Column("user_id", GUID(), ForeignKey("auth_users.id"))
|
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.id"))
|
||||||
is_valid = Column("is_valid", Boolean)
|
is_valid = Column("is_valid", Boolean)
|
||||||
|
|
||||||
user = relationship("User", primaryjoin="User.id==Attendance.user_id")
|
user = relationship("User", primaryjoin="User.id==Attendance.user_id")
|
||||||
@ -375,8 +375,8 @@ class Attendance(Base):
|
|||||||
class Fingerprint(Base):
|
class Fingerprint(Base):
|
||||||
__tablename__ = "fingerprints"
|
__tablename__ = "fingerprints"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
employee_id = Column("employee_id", GUID(), ForeignKey("employees.id"))
|
employee_id = Column("employee_id", UUID(as_uuid=True), ForeignKey("employees.id"))
|
||||||
date = Column("date", DateTime)
|
date = Column("date", DateTime)
|
||||||
|
|
||||||
def __init__(self, id_=None, employee_id=None, date=None):
|
def __init__(self, id_=None, employee_id=None, date=None):
|
||||||
@ -389,8 +389,8 @@ class Fingerprint(Base):
|
|||||||
class DbImage(Base):
|
class DbImage(Base):
|
||||||
__tablename__ = "images"
|
__tablename__ = "images"
|
||||||
|
|
||||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
resource_id = Column("resource_id", GUID(), nullable=False)
|
resource_id = Column("resource_id", UUID(as_uuid=True), nullable=False)
|
||||||
resource_type = Column("resource_type", Unicode(255), nullable=False)
|
resource_type = Column("resource_type", Unicode(255), nullable=False)
|
||||||
image = Column("image", BYTEA, nullable=False)
|
image = Column("image", BYTEA, nullable=False)
|
||||||
thumbnail = Column("thumbnail", BYTEA, nullable=False)
|
thumbnail = Column("thumbnail", BYTEA, nullable=False)
|
||||||
|
@ -33,7 +33,7 @@ def save(
|
|||||||
try:
|
try:
|
||||||
item = Account(
|
item = Account(
|
||||||
name=data.name,
|
name=data.name,
|
||||||
type=data.type,
|
type_=data.type,
|
||||||
is_starred=data.is_starred,
|
is_starred=data.is_starred,
|
||||||
is_active=data.is_active,
|
is_active=data.is_active,
|
||||||
is_reconcilable=data.is_reconcilable,
|
is_reconcilable=data.is_reconcilable,
|
||||||
|
@ -70,13 +70,12 @@ def update(
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{id_}")
|
@router.delete("/{id_}")
|
||||||
def delete(
|
def delete(
|
||||||
id_: uuid.UUID, db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["cost-centres"]),
|
id_: uuid.UUID, db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["cost-centres"]),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
item = db.query(CostCentre).filter(CostCentre.id == id_).first()
|
item: CostCentre = db.query(CostCentre).filter(CostCentre.id == id_).first()
|
||||||
|
|
||||||
if item is None:
|
if item is None:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
@ -97,11 +97,11 @@ def update(
|
|||||||
def delete(
|
def delete(
|
||||||
id_: uuid.UUID, db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["products"]),
|
id_: uuid.UUID, db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["products"]),
|
||||||
):
|
):
|
||||||
product: Product = db.query(Product).filter(Product.id == id_).first()
|
item: Product = db.query(Product).filter(Product.id == id_).first()
|
||||||
can_delete, reason = product.can_delete("advanced-delete" in user.permissions)
|
can_delete, reason = item.can_delete("advanced-delete" in user.permissions)
|
||||||
|
|
||||||
if can_delete:
|
if can_delete:
|
||||||
delete_with_data(product, db)
|
delete_with_data(item, db)
|
||||||
db.commit()
|
db.commit()
|
||||||
return product_info(None, db)
|
return product_info(None, db)
|
||||||
else:
|
else:
|
||||||
@ -111,7 +111,7 @@ def delete(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/") # "Products"
|
@router.get("/")
|
||||||
def show_blank(
|
def show_blank(
|
||||||
db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["products"]),
|
db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["products"]),
|
||||||
):
|
):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "overlord",
|
"name": "overlord",
|
||||||
"version": "7.0.2",
|
"version": "7.0.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
|
@ -16,13 +16,29 @@ export class AuthService {
|
|||||||
public currentUser: Observable<User>;
|
public currentUser: Observable<User>;
|
||||||
|
|
||||||
constructor(private http: HttpClient) {
|
constructor(private http: HttpClient) {
|
||||||
this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem(JWT_USER)));
|
const existingToken: User = JSON.parse(localStorage.getItem(JWT_USER));
|
||||||
|
if (existingToken === null || Date.now() > existingToken.exp * 1000) {
|
||||||
|
localStorage.removeItem(JWT_USER);
|
||||||
|
this.currentUserSubject = new BehaviorSubject<User>(null);
|
||||||
|
} else {
|
||||||
|
this.currentUserSubject = new BehaviorSubject<User>(existingToken);
|
||||||
|
}
|
||||||
this.currentUser = this.currentUserSubject.asObservable();
|
this.currentUser = this.currentUserSubject.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public get user(): User {
|
public get user(): User {
|
||||||
|
const val = this.currentUserSubject.value;
|
||||||
|
if (val == null) {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
const expired = Date.now() > val.exp * 1000;
|
||||||
|
if (expired) {
|
||||||
|
this.logout();
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
return this.currentUserSubject.value;
|
return this.currentUserSubject.value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
login(username: string, password: string, otp: string) {
|
login(username: string, password: string, otp: string) {
|
||||||
const formData: FormData = new FormData();
|
const formData: FormData = new FormData();
|
||||||
|
@ -60,7 +60,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
|||||||
this.router.navigate([this.returnUrl]);
|
this.router.navigate([this.returnUrl]);
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
if (error.status === 401 && 'Client is not registered' == error.error.detail) {
|
if (error.status === 401 && 'Client is not registered' === error.error.detail) {
|
||||||
this.showOtp = true;
|
this.showOtp = true;
|
||||||
this.clientId = this.cs.getCookie('client_id');
|
this.clientId = this.cs.getCookie('client_id');
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import {ActivatedRoute} from '@angular/router';
|
|||||||
import { debounceTime, distinctUntilChanged, startWith } from 'rxjs/operators';
|
import { debounceTime, distinctUntilChanged, startWith } from 'rxjs/operators';
|
||||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import {ToCsvService} from "../../shared/to-csv.service";
|
import { ToCsvService } from '../../shared/to-csv.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-product-list',
|
selector: 'app-product-list',
|
||||||
@ -15,6 +15,25 @@ import {ToCsvService} from "../../shared/to-csv.service";
|
|||||||
styleUrls: ['./product-list.component.css']
|
styleUrls: ['./product-list.component.css']
|
||||||
})
|
})
|
||||||
export class ProductListComponent implements OnInit, AfterViewInit {
|
export class ProductListComponent implements OnInit, AfterViewInit {
|
||||||
|
|
||||||
|
constructor(private route: ActivatedRoute, private fb: FormBuilder, private toCsv: ToCsvService) {
|
||||||
|
this.showExtended = false;
|
||||||
|
this.createForm();
|
||||||
|
this.filter = this.listenToFilterChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
get showExtended(): boolean {
|
||||||
|
return this._showExtended;
|
||||||
|
}
|
||||||
|
|
||||||
|
set showExtended(value: boolean) {
|
||||||
|
this._showExtended = value;
|
||||||
|
if (value) {
|
||||||
|
this.displayedColumns = ['name', 'costPrice', 'productYield', 'productGroup', 'info'];
|
||||||
|
} else {
|
||||||
|
this.displayedColumns = ['name', 'costPrice', 'productGroup', 'info'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ViewChild('filterElement', { static: true }) filterElement: ElementRef;
|
@ViewChild('filterElement', { static: true }) filterElement: ElementRef;
|
||||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||||
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
||||||
@ -25,11 +44,7 @@ export class ProductListComponent implements OnInit, AfterViewInit {
|
|||||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||||
displayedColumns: string[];
|
displayedColumns: string[];
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private fb: FormBuilder, private toCsv: ToCsvService) {
|
private _showExtended: boolean;
|
||||||
this.showExtended = false;
|
|
||||||
this.createForm();
|
|
||||||
this.filter = this.listenToFilterChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
createForm() {
|
createForm() {
|
||||||
this.form = this.fb.group({
|
this.form = this.fb.group({
|
||||||
@ -60,21 +75,6 @@ export class ProductListComponent implements OnInit, AfterViewInit {
|
|||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _showExtended: boolean;
|
|
||||||
|
|
||||||
get showExtended(): boolean {
|
|
||||||
return this._showExtended;
|
|
||||||
}
|
|
||||||
|
|
||||||
set showExtended(value: boolean) {
|
|
||||||
this._showExtended = value;
|
|
||||||
if (value) {
|
|
||||||
this.displayedColumns = ['name', 'costPrice', 'productYield', 'productGroup', 'info'];
|
|
||||||
} else {
|
|
||||||
this.displayedColumns = ['name', 'costPrice', 'productGroup', 'info'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exportCsv() {
|
exportCsv() {
|
||||||
const headers = {
|
const headers = {
|
||||||
Code: 'code',
|
Code: 'code',
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||||
import { catchError } from 'rxjs/operators';
|
import { catchError } from 'rxjs/operators';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||||
import { catchError } from 'rxjs/operators';
|
import { catchError } from 'rxjs/operators';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
|
2
setup.py
2
setup.py
@ -11,7 +11,7 @@ with open(os.path.join(here, 'requirements.txt'), "r") as r:
|
|||||||
requires = r.read().splitlines()
|
requires = r.read().splitlines()
|
||||||
|
|
||||||
setup(name='brewman',
|
setup(name='brewman',
|
||||||
version='7.0.2',
|
version='7.0.3',
|
||||||
description='brewman',
|
description='brewman',
|
||||||
long_description=README + '\n\n' + CHANGES,
|
long_description=README + '\n\n' + CHANGES,
|
||||||
classifiers=[
|
classifiers=[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user