Chore: Split models into their own files
This commit is contained in:
1 parent
9e1da1d59a
commit
d7f635b7b6
87 files changed
+1509
-1288
No files matched your search
@@ -13,8 +13,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.config import settings
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.auth import Client
|
||||
from ..models.auth import User as UserModel
|
||||
from ..models.client import Client
|
||||
from ..models.user import User as UserModel
|
||||
|
||||
# to get a string like this run:
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
+25
-27
@@ -1,30 +1,28 @@
|
||||
# Import all the models, so that Base has them before being
|
||||
# imported by Alembic
|
||||
from brewman.db.base_class import Base # noqa: F401
|
||||
from brewman.models import Account # noqa: F401
|
||||
from brewman.models import ( # noqa: F401
|
||||
AccountBase,
|
||||
AccountType,
|
||||
Attendance,
|
||||
AttendanceType,
|
||||
Batch,
|
||||
Client,
|
||||
CostCentre,
|
||||
Employee,
|
||||
EmployeeBenefit,
|
||||
Fingerprint,
|
||||
Inventory,
|
||||
Journal,
|
||||
LoginHistory,
|
||||
Permission,
|
||||
Product,
|
||||
ProductGroup,
|
||||
Recipe,
|
||||
RecipeItem,
|
||||
Role,
|
||||
User,
|
||||
Voucher,
|
||||
VoucherType,
|
||||
role_permission,
|
||||
user_role,
|
||||
)
|
||||
from brewman.models.account import Account # noqa: F401
|
||||
from brewman.models.account_base import AccountBase # noqa: F401
|
||||
from brewman.models.attendance import Attendance # noqa: F401
|
||||
from brewman.models.batch import Batch # noqa: F401
|
||||
from brewman.models.client import Client # noqa: F401
|
||||
from brewman.models.cost_centre import CostCentre # noqa: F401
|
||||
from brewman.models.db_image import DbImage # noqa: F401
|
||||
from brewman.models.db_setting import DbSetting # noqa: F401
|
||||
from brewman.models.employee import Employee # noqa: F401
|
||||
from brewman.models.emplyee_benefit import EmployeeBenefit # noqa: F401
|
||||
from brewman.models.fingerprint import Fingerprint # noqa: F401
|
||||
from brewman.models.incentive import Incentive # noqa: F401
|
||||
from brewman.models.inventory import Inventory # noqa: F401
|
||||
from brewman.models.journal import Journal # noqa: F401
|
||||
from brewman.models.login_history import LoginHistory # noqa: F401
|
||||
from brewman.models.permission import Permission # noqa: F401
|
||||
from brewman.models.product import Product # noqa: F401
|
||||
from brewman.models.product_group import ProductGroup # noqa: F401
|
||||
from brewman.models.recipe import Recipe # noqa: F401
|
||||
from brewman.models.recipe_item import RecipeItem # noqa: F401
|
||||
from brewman.models.role import Role # noqa: F401
|
||||
from brewman.models.role_permission import role_permission # noqa: F401
|
||||
from brewman.models.user import User # noqa: F401
|
||||
from brewman.models.user_role import user_role # noqa: F401
|
||||
from brewman.models.voucher import Voucher # noqa: F401
|
||||
@@ -1,31 +0,0 @@
|
||||
from .auth import ( # noqa: F401
|
||||
Client,
|
||||
LoginHistory,
|
||||
Permission,
|
||||
Role,
|
||||
User,
|
||||
role_permission,
|
||||
user_role,
|
||||
)
|
||||
from .master import ( # noqa: F401
|
||||
Account,
|
||||
AccountBase,
|
||||
AccountType,
|
||||
AttendanceType,
|
||||
CostCentre,
|
||||
Employee,
|
||||
Product,
|
||||
ProductGroup,
|
||||
Recipe,
|
||||
RecipeItem,
|
||||
)
|
||||
from .voucher import ( # noqa: F401
|
||||
Attendance,
|
||||
Batch,
|
||||
EmployeeBenefit,
|
||||
Fingerprint,
|
||||
Inventory,
|
||||
Journal,
|
||||
Voucher,
|
||||
VoucherType,
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
from brewman.models.account_base import AccountBase
|
||||
|
||||
|
||||
class Account(AccountBase):
|
||||
__mapper_args__ = {"polymorphic_identity": ""}
|
||||
|
||||
def can_delete(self, advanced_delete):
|
||||
if len(self.products) > 0:
|
||||
return False, "Account has products"
|
||||
return super(Account, self).can_delete(advanced_delete)
|
||||
@@ -0,0 +1,137 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.account_type import AccountType
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Boolean, Column, ForeignKey, Integer, Unicode, func
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Session, relationship
|
||||
|
||||
|
||||
class AccountBase(Base):
|
||||
__tablename__ = "accounts"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
code = Column("code", Integer, nullable=False)
|
||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||
type = Column("type", Integer, nullable=False)
|
||||
account_type = Column("account_type", Unicode(50), nullable=False)
|
||||
is_starred = Column("is_starred", Boolean, nullable=False)
|
||||
is_active = Column("is_active", Boolean, nullable=False)
|
||||
is_reconcilable = Column("is_reconcilable", Boolean, 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)
|
||||
|
||||
__mapper_args__ = {"polymorphic_on": account_type}
|
||||
|
||||
journals = relationship("Journal", back_populates="account")
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def type_object(self):
|
||||
return AccountType.by_id(self.type)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
code=None,
|
||||
name=None,
|
||||
type_=None,
|
||||
is_starred=None,
|
||||
is_active=None,
|
||||
is_reconcilable=False,
|
||||
cost_centre_id=None,
|
||||
id_=None,
|
||||
is_fixture=False,
|
||||
):
|
||||
self.code = code
|
||||
self.name = name
|
||||
self.type = type_
|
||||
self.is_starred = is_starred
|
||||
self.is_active = is_active
|
||||
self.is_reconcilable = is_reconcilable
|
||||
self.cost_centre_id = cost_centre_id
|
||||
self.id = id_
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@classmethod
|
||||
def query(cls, q, type_, reconcilable=None, active=None, db=None):
|
||||
query_ = db.query(cls)
|
||||
if type_ is not None:
|
||||
if not isinstance(type_, int):
|
||||
type_ = int(type_)
|
||||
query_ = query_.filter(cls.type == type_)
|
||||
if reconcilable is not None:
|
||||
query_ = query_.filter(cls.is_reconcilable == reconcilable)
|
||||
if active is not None:
|
||||
query_ = query_.filter(cls.is_active == active)
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
query_ = query_.filter(cls.name.ilike(f"%{item}%"))
|
||||
return query_.order_by(cls.name)
|
||||
|
||||
def create(self, db: Session):
|
||||
code = db.query(func.max(AccountBase.code)).filter(AccountBase.type == self.type).one()[0]
|
||||
self.code = 1 if code is None else code + 1
|
||||
db.add(self)
|
||||
return self
|
||||
|
||||
def can_delete(self, advanced_delete):
|
||||
if self.is_fixture:
|
||||
return False, f"{self.name} is a fixture and cannot be edited or deleted."
|
||||
if self.is_active:
|
||||
return False, "Account is active"
|
||||
if len(self.journals) > 0 and not advanced_delete:
|
||||
return False, "Account has journal entries"
|
||||
return True, ""
|
||||
|
||||
@classmethod
|
||||
def get_code(cls, type_, db: Session):
|
||||
code = db.query(func.max(AccountBase.code)).filter(AccountBase.type == type_).one()[0]
|
||||
return 1 if code is None else code + 1
|
||||
|
||||
@classmethod
|
||||
def all_purchases(cls):
|
||||
return uuid.UUID("240dd899-c413-854c-a7eb-67a29d154490")
|
||||
|
||||
@classmethod
|
||||
def cash_in_hand(cls):
|
||||
return {"id": "ed2341bb-80b8-9649-90db-f9aaca183bb3", "name": "Cash in Hand"}
|
||||
|
||||
@classmethod
|
||||
def local_purchase(cls):
|
||||
return {"id": "d2b75912-505f-2548-9093-466dfff6a0f9", "name": "Local Purchase"}
|
||||
|
||||
@classmethod
|
||||
def salary(cls):
|
||||
return {"id": "5c2b54d0-c174-004d-a0d5-92cdaadcefa7", "name": "Staff Salary"}
|
||||
|
||||
@classmethod
|
||||
def salary_id(cls):
|
||||
return uuid.UUID("5c2b54d0-c174-004d-a0d5-92cdaadcefa7")
|
||||
|
||||
@classmethod
|
||||
def incentive(cls):
|
||||
return {"id": "b7eff754-e8ba-e047-ab06-9132c15c7640", "name": "Incentives"}
|
||||
|
||||
@classmethod
|
||||
def incentive_id(cls):
|
||||
return uuid.UUID("b7eff754-e8ba-e047-ab06-9132c15c7640")
|
||||
|
||||
@classmethod
|
||||
def esi_pf_expense(cls):
|
||||
return uuid.UUID("d2a1a286-e900-764b-a1a5-9f4b00dbb940")
|
||||
|
||||
@classmethod
|
||||
def esi_pf_payable(cls):
|
||||
return uuid.UUID("42277912-cc18-854b-b134-9f4b00dba419")
|
||||
|
||||
@classmethod
|
||||
def suspense(cls):
|
||||
return uuid.UUID("3854e317-6f3b-5142-ab26-9c44d4cddd08")
|
||||
@@ -0,0 +1,51 @@
|
||||
class AccountType:
|
||||
def __init__(
|
||||
self,
|
||||
id_,
|
||||
name,
|
||||
balance_sheet=None,
|
||||
debit=None,
|
||||
cash_flow_classification=None,
|
||||
order=None,
|
||||
show_in_list=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.balance_sheet = balance_sheet
|
||||
self.debit = debit
|
||||
self.cash_flow_classification = cash_flow_classification
|
||||
# Cash flow Classifications are:
|
||||
# Cash
|
||||
# Operating
|
||||
# Investing
|
||||
# Financing
|
||||
self.order = order
|
||||
self.show_in_list = show_in_list
|
||||
|
||||
@classmethod
|
||||
def list(cls):
|
||||
return [
|
||||
AccountType(1, "Cash", True, True, "Cash", 10000, True),
|
||||
AccountType(2, "Purchase", False, True, "Operating", 20000, True),
|
||||
AccountType(3, "Sale", False, False, "Operating", 10000, True),
|
||||
AccountType(4, "Assets", True, True, "Investing", 20000, True),
|
||||
AccountType(5, "Capital", True, False, "Financing", 70000, True),
|
||||
AccountType(6, "Debtors", True, True, "Operating", 30000, True),
|
||||
AccountType(7, "Expenses", False, True, "Operating", 40000, True),
|
||||
AccountType(9, "Creditors", True, False, "Operating", 60000, True),
|
||||
AccountType(10, "Salary", True, True, "Operating", 40000, False),
|
||||
AccountType(11, "Liabilities", True, False, "Operating", 50000, True),
|
||||
AccountType(12, "Revenue", False, False, "Operating", 30000, True),
|
||||
AccountType(13, "Tax", True, False, "Operating", 80000, True),
|
||||
]
|
||||
# list.append(AccountType(8, 'Discount', False, False, True, 30, True))
|
||||
# list.append(AccountType(14, 'Total', False, False, False, 900, False))
|
||||
# list.append(AccountType(15, 'Net', False, False, False, 1000, False))
|
||||
|
||||
@classmethod
|
||||
def by_name(cls, name):
|
||||
return next(i for i in cls.list() if i.name == name)
|
||||
|
||||
@classmethod
|
||||
def by_id(cls, id_):
|
||||
return next(i for i in cls.list() if i.id == id_)
|
||||
@@ -0,0 +1,56 @@
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Boolean, Column, Date, DateTime, ForeignKey, Integer, Numeric
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Session, relationship
|
||||
|
||||
|
||||
class Attendance(Base):
|
||||
__tablename__ = "attendances"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
employee_id = Column("employee_id", UUID(as_uuid=True), ForeignKey("employees.id"))
|
||||
date = Column("date", Date, nullable=False)
|
||||
attendance_type = Column("attendance_type", Integer)
|
||||
amount = Column("amount", Numeric(precision=5, scale=2))
|
||||
creation_date = Column("creation_date", DateTime(timezone=True))
|
||||
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.id"))
|
||||
is_valid = Column("is_valid", Boolean)
|
||||
|
||||
user = relationship("User", primaryjoin="User.id==Attendance.user_id")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
employee_id=None,
|
||||
date=None,
|
||||
attendance_type=None,
|
||||
amount=None,
|
||||
creation_date=None,
|
||||
user_id=None,
|
||||
is_valid=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.employee_id = employee_id
|
||||
self.date = date
|
||||
self.attendance_type = attendance_type
|
||||
self.amount = amount if amount is not None else 0
|
||||
self.creation_date = creation_date or datetime.utcnow()
|
||||
self.user_id = user_id
|
||||
self.is_valid = is_valid if is_valid is not None else True
|
||||
|
||||
def create(self, db: Session):
|
||||
old = (
|
||||
db.query(Attendance)
|
||||
.filter(Attendance.date == self.date)
|
||||
.filter(Attendance.employee_id == self.employee_id)
|
||||
.filter(Attendance.is_valid == True) # noqa: E712
|
||||
.first()
|
||||
)
|
||||
if old is None or old.attendance_type != self.attendance_type:
|
||||
if old is not None:
|
||||
old.is_valid = False
|
||||
db.add(self)
|
||||
@@ -0,0 +1,30 @@
|
||||
class AttendanceType:
|
||||
def __init__(self, id_, name, value=None):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.value = value
|
||||
|
||||
@classmethod
|
||||
def list(cls):
|
||||
return [
|
||||
AttendanceType(0, "Not Set", 0),
|
||||
AttendanceType(1, "Present", 1),
|
||||
AttendanceType(2, "Off Day", 1),
|
||||
AttendanceType(3, "On Leave", 0),
|
||||
AttendanceType(4, "Absent", 0),
|
||||
AttendanceType(5, "Half Day", 0.5),
|
||||
AttendanceType(6, "Double Duty", 2),
|
||||
AttendanceType(7, "Paid Leave Availed", 1),
|
||||
AttendanceType(8, "Casual Leave Availed", 1),
|
||||
AttendanceType(9, "Compensatory Off", 1),
|
||||
AttendanceType(10, "Half Day + PL", 1),
|
||||
AttendanceType(11, "Half Day + CL", 1),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def by_name(cls, name):
|
||||
return next(i for i in cls.list() if i.name == name)
|
||||
|
||||
@classmethod
|
||||
def by_id(cls, id_):
|
||||
return next(i for i in cls.list() if i.id == id_)
|
||||
@@ -1,170 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import string
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
from hashlib import md5
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
Column,
|
||||
DateTime,
|
||||
Integer,
|
||||
Unicode,
|
||||
UniqueConstraint,
|
||||
desc,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Session, relationship, synonym
|
||||
from sqlalchemy.schema import ForeignKey, Table
|
||||
|
||||
from .meta import Base
|
||||
|
||||
|
||||
def encrypt(val):
|
||||
return md5(val.encode("utf-8") + "Salt".encode("utf-8")).hexdigest()
|
||||
|
||||
|
||||
class LoginHistory(Base):
|
||||
__tablename__ = "auth_login_history"
|
||||
__table_args__ = (UniqueConstraint("user_id", "client_id", "date"),)
|
||||
id = Column("login_history_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.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)
|
||||
|
||||
def __init__(self, user_id=None, client_id=None, date=None, id_=None):
|
||||
self.user_id = user_id
|
||||
self.client_id = client_id
|
||||
self.date = datetime.utcnow() if date is None else date
|
||||
self.id = id_
|
||||
|
||||
|
||||
class Client(Base):
|
||||
__tablename__ = "auth_clients"
|
||||
|
||||
id = Column("client_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
code = Column("code", Integer, unique=True, nullable=False)
|
||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||
enabled = Column("enabled", Boolean, nullable=False)
|
||||
otp = Column("otp", Integer)
|
||||
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
||||
|
||||
login_history: List[LoginHistory] = relationship("LoginHistory", order_by=desc(LoginHistory.date), backref="client")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
code=None,
|
||||
name=None,
|
||||
enabled=False,
|
||||
otp=None,
|
||||
creation_date=None,
|
||||
id_=None,
|
||||
):
|
||||
self.code = code
|
||||
self.name = name
|
||||
self.enabled = enabled
|
||||
self.otp = otp
|
||||
self.creation_date = datetime.utcnow() if creation_date is None else creation_date
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def create(cls, db: Session):
|
||||
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))
|
||||
client = Client(client_code, name, False, otp)
|
||||
db.add(client)
|
||||
return client
|
||||
|
||||
|
||||
user_role = Table(
|
||||
"user_roles",
|
||||
Base.metadata,
|
||||
Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4),
|
||||
Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.id")),
|
||||
Column("role_id", UUID(as_uuid=True), ForeignKey("auth_roles.id")),
|
||||
)
|
||||
|
||||
role_permission = Table(
|
||||
"role_permissions",
|
||||
Base.metadata,
|
||||
Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4),
|
||||
Column("permission_id", UUID(as_uuid=True), ForeignKey("auth_permissions.id")),
|
||||
Column("role_id", UUID(as_uuid=True), ForeignKey("auth_roles.id")),
|
||||
)
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "auth_users"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("username", Unicode(255), unique=True)
|
||||
_password = Column("password", Unicode(60))
|
||||
locked_out = Column("disabled", Boolean)
|
||||
|
||||
roles: List[Role] = relationship("Role", secondary=user_role)
|
||||
login_history: List[LoginHistory] = relationship("LoginHistory", order_by=desc(LoginHistory.date), backref="user")
|
||||
|
||||
def _get_password(self):
|
||||
return self._password
|
||||
|
||||
def _set_password(self, password):
|
||||
self._password = encrypt(password)
|
||||
|
||||
password = property(_get_password, _set_password)
|
||||
password = synonym("_password", descriptor=password)
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
def __init__(self, name=None, password=None, locked_out=None, id_=None):
|
||||
self.name = name
|
||||
self.password = password
|
||||
self.locked_out = locked_out
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def auth(cls, name: str, password: str, db: Session) -> Optional[User]:
|
||||
if password is None:
|
||||
return None
|
||||
user = db.query(User).filter(User.name.ilike(name)).first()
|
||||
if not user:
|
||||
return None
|
||||
if user.password != encrypt(password) or user.locked_out:
|
||||
return None
|
||||
else:
|
||||
return user
|
||||
|
||||
|
||||
class Role(Base):
|
||||
__tablename__ = "auth_roles"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True)
|
||||
|
||||
def __init__(self, name=None, id_=None):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
|
||||
|
||||
class Permission(Base):
|
||||
__tablename__ = "auth_permissions"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True)
|
||||
|
||||
roles: List[Role] = relationship("Role", secondary=role_permission, backref="permissions")
|
||||
|
||||
def __init__(self, name=None, id_=None):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
@@ -0,0 +1,61 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from brewman.models.product import Product
|
||||
from sqlalchemy import Column, Date, ForeignKey, Numeric
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Session, relationship
|
||||
|
||||
|
||||
class Batch(Base):
|
||||
__tablename__ = "batches"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Date, nullable=False)
|
||||
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||
quantity_remaining = Column("quantity_remaining", Numeric(precision=15, scale=2), nullable=False)
|
||||
rate = Column("rate", Numeric(precision=15, scale=2), nullable=False)
|
||||
tax = Column("tax", Numeric(precision=15, scale=5), nullable=False)
|
||||
discount = Column("discount", Numeric(precision=15, scale=5), nullable=False)
|
||||
|
||||
inventories = relationship("Inventory", backref="batch", cascade=None, cascade_backrefs=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name=None,
|
||||
product_id=None,
|
||||
quantity_remaining=None,
|
||||
rate=None,
|
||||
tax=None,
|
||||
discount=None,
|
||||
product=None,
|
||||
):
|
||||
self.name = name
|
||||
self.product_id = product_id
|
||||
self.quantity_remaining = quantity_remaining
|
||||
self.rate = rate
|
||||
self.tax = tax
|
||||
self.discount = discount
|
||||
if product is None:
|
||||
self.product_id = product_id
|
||||
else:
|
||||
self.product = product
|
||||
|
||||
def amount(self):
|
||||
return self.quantity_remaining * self.rate * (1 + self.tax) * (1 - self.discount)
|
||||
|
||||
@classmethod
|
||||
def list(cls, q, include_nil, date, db: Session):
|
||||
query = db.query(cls).join(cls.product)
|
||||
if not include_nil:
|
||||
query = query.filter(cls.quantity_remaining > 0)
|
||||
if date is not None:
|
||||
query = query.filter(cls.name <= date)
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
query = query.filter(Product.name.ilike(f"%{item}%"))
|
||||
return query.order_by(Product.name).order_by(cls.name).all()
|
||||
|
||||
@classmethod
|
||||
def suspense(cls):
|
||||
return uuid.UUID("a955790e-93cf-493c-a816-c7d92b127383")
|
||||
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import string
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, Integer, Unicode, desc
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Session, relationship
|
||||
|
||||
from .login_history import LoginHistory
|
||||
from .meta import Base
|
||||
|
||||
|
||||
class Client(Base):
|
||||
__tablename__ = "auth_clients"
|
||||
|
||||
id = Column("client_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
code = Column("code", Integer, unique=True, nullable=False)
|
||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||
enabled = Column("enabled", Boolean, nullable=False)
|
||||
otp = Column("otp", Integer)
|
||||
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
||||
|
||||
login_history: List[LoginHistory] = relationship("LoginHistory", order_by=desc(LoginHistory.date), backref="client")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
code=None,
|
||||
name=None,
|
||||
enabled=False,
|
||||
otp=None,
|
||||
creation_date=None,
|
||||
id_=None,
|
||||
):
|
||||
self.code = code
|
||||
self.name = name
|
||||
self.enabled = enabled
|
||||
self.otp = otp
|
||||
self.creation_date = datetime.utcnow() if creation_date is None else creation_date
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def create(cls, db: Session):
|
||||
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))
|
||||
client = Client(client_code, name, False, otp)
|
||||
db.add(client)
|
||||
return client
|
||||
@@ -0,0 +1,45 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Boolean, Column, Unicode
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
|
||||
class CostCentre(Base):
|
||||
__tablename__ = "cost_centres"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True)
|
||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||
|
||||
accounts = relationship("AccountBase", backref="cost_centre")
|
||||
journals = relationship("Journal", back_populates="cost_centre")
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
def __init__(self, name=None, id_=None, is_fixture=False):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@classmethod
|
||||
def cost_centre_purchase(cls):
|
||||
return uuid.UUID("7b845f95-dfef-fa4a-897c-f0baf15284a3")
|
||||
|
||||
@classmethod
|
||||
def cost_centre_kitchen(cls):
|
||||
return uuid.UUID("b2d398ce-e3cc-c542-9feb-5d7783e899df")
|
||||
|
||||
@classmethod
|
||||
def cost_centre_overall(cls):
|
||||
return uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d")
|
||||
|
||||
@classmethod
|
||||
def overall(cls):
|
||||
return {
|
||||
"id": uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d"),
|
||||
"name": "Overall",
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Column, DateTime, Unicode
|
||||
from sqlalchemy.dialects.postgresql import BYTEA, UUID
|
||||
|
||||
|
||||
class DbImage(Base):
|
||||
__tablename__ = "images"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
resource_id = Column("resource_id", UUID(as_uuid=True), nullable=False)
|
||||
resource_type = Column("resource_type", Unicode(255), nullable=False)
|
||||
image = Column("image", BYTEA, nullable=False)
|
||||
thumbnail = Column("thumbnail", BYTEA, nullable=False)
|
||||
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
resource_id=None,
|
||||
resource_type=None,
|
||||
image=None,
|
||||
thumbnail=None,
|
||||
creation_date=None,
|
||||
id_=None,
|
||||
):
|
||||
self.resource_id = resource_id
|
||||
self.resource_type = resource_type
|
||||
self.image = image
|
||||
self.thumbnail = thumbnail
|
||||
self.creation_date = creation_date or datetime.utcnow()
|
||||
self.id = id_
|
||||
@@ -0,0 +1,19 @@
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column, PickleType, Unicode
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
from .meta import Base
|
||||
|
||||
|
||||
class DbSetting(Base):
|
||||
__tablename__ = "settings"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||
data = Column("data", PickleType)
|
||||
|
||||
def __init__(self, id_=None, name=None, data=None):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.data = data
|
||||
@@ -0,0 +1,57 @@
|
||||
from brewman.models.account_base import AccountBase
|
||||
from sqlalchemy import Column, Date, ForeignKey, Integer, Numeric, Unicode, func
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Session, relationship
|
||||
|
||||
|
||||
class Employee(AccountBase):
|
||||
__tablename__ = "employees"
|
||||
__mapper_args__ = {"polymorphic_identity": "employees"}
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), ForeignKey(AccountBase.id), primary_key=True)
|
||||
designation = Column("designation", Unicode(255), nullable=False)
|
||||
salary = Column("salary", Integer, nullable=False)
|
||||
points = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
||||
joining_date = Column("joining_date", Date, nullable=False)
|
||||
leaving_date = Column("leaving_date", Date, nullable=True)
|
||||
|
||||
attendances = relationship("Attendance", backref="employee", cascade=None, cascade_backrefs=False)
|
||||
fingerprints = relationship("Fingerprint", backref="employee", cascade=None, cascade_backrefs=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
code=None,
|
||||
name=None,
|
||||
is_starred=None,
|
||||
is_active=None,
|
||||
cost_centre_id=None,
|
||||
designation=None,
|
||||
salary=None,
|
||||
points=None,
|
||||
joining_date=None,
|
||||
leaving_date=None,
|
||||
):
|
||||
self.designation = designation
|
||||
self.salary = salary
|
||||
self.points = points
|
||||
self.joining_date = joining_date
|
||||
self.leaving_date = leaving_date
|
||||
super().__init__(
|
||||
code=code,
|
||||
name=name,
|
||||
type_=10,
|
||||
is_starred=is_starred,
|
||||
is_active=is_active,
|
||||
is_reconcilable=False,
|
||||
cost_centre_id=cost_centre_id,
|
||||
)
|
||||
|
||||
def create(self, db: Session):
|
||||
code = db.query(func.max(AccountBase.code)).filter(AccountBase.type == self.type).one()[0]
|
||||
self.code = 1 if code is None else code + 1
|
||||
self.name += f" ({str(self.code)})"
|
||||
db.add(self)
|
||||
return self
|
||||
|
||||
def can_delete(self, advanced_delete):
|
||||
return super(Employee, self).can_delete(advanced_delete)
|
||||
@@ -0,0 +1,53 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.journal import Journal
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Column, ForeignKey, Integer
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import backref, relationship
|
||||
|
||||
|
||||
class EmployeeBenefit(Base):
|
||||
__tablename__ = "employee_benefit"
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column("voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False)
|
||||
journal_id = Column("journal_id", UUID(as_uuid=True), ForeignKey("journals.id"), nullable=False)
|
||||
gross_salary = Column("gross_salary", Integer)
|
||||
days_worked = Column("days_worked", Integer)
|
||||
esi_ee = Column("esi_employee", Integer)
|
||||
pf_ee = Column("pf_employee", Integer)
|
||||
esi_er = Column("esi_employer", Integer)
|
||||
pf_er = Column("pf_employer", Integer)
|
||||
|
||||
journal = relationship(
|
||||
Journal,
|
||||
backref=backref("employee_benefit", uselist=False),
|
||||
cascade=None,
|
||||
cascade_backrefs=False,
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
voucher_id=None,
|
||||
journal_id=None,
|
||||
journal=None,
|
||||
gross_salary=None,
|
||||
days_worked=None,
|
||||
esi_ee=None,
|
||||
pf_ee=None,
|
||||
esi_er=None,
|
||||
pf_er=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.voucher_id = voucher_id
|
||||
self.gross_salary = gross_salary
|
||||
self.days_worked = days_worked
|
||||
self.esi_ee = esi_ee
|
||||
self.pf_ee = pf_ee
|
||||
self.esi_er = esi_er
|
||||
self.pf_er = pf_er
|
||||
if journal is None:
|
||||
self.journal_id = journal_id
|
||||
else:
|
||||
self.journal = journal
|
||||
@@ -0,0 +1,19 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Column, DateTime, ForeignKey
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
|
||||
class Fingerprint(Base):
|
||||
__tablename__ = "fingerprints"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
employee_id = Column("employee_id", UUID(as_uuid=True), ForeignKey("employees.id"))
|
||||
date = Column("date", DateTime)
|
||||
|
||||
def __init__(self, id_=None, employee_id=None, date=None):
|
||||
self.id = id_
|
||||
self.employee_id = employee_id
|
||||
self.date = date
|
||||
self.fingerprint_type = 0
|
||||
@@ -0,0 +1,41 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.journal import Journal
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Column, ForeignKey, Numeric
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import backref, relationship
|
||||
|
||||
|
||||
class Incentive(Base):
|
||||
__tablename__ = "incentives"
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column("voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.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)
|
||||
points = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
||||
|
||||
journal = relationship(
|
||||
Journal,
|
||||
backref=backref("incentive", uselist=False),
|
||||
cascade=None,
|
||||
cascade_backrefs=False,
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
voucher_id=None,
|
||||
journal_id=None,
|
||||
journal=None,
|
||||
days_worked=None,
|
||||
points=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.voucher_id = voucher_id
|
||||
if journal is None:
|
||||
self.journal_id = journal_id
|
||||
else:
|
||||
self.journal = journal
|
||||
self.days_worked = days_worked
|
||||
self.points = points
|
||||
@@ -0,0 +1,61 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Column, ForeignKey, Numeric, UniqueConstraint
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
|
||||
class Inventory(Base):
|
||||
__tablename__ = "inventories"
|
||||
__table_args__ = (UniqueConstraint("voucher_id", "batch_id"),)
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column(
|
||||
"voucher_id",
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("vouchers.id"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||
batch_id = Column("batch_id", UUID(as_uuid=True), ForeignKey("batches.id"), nullable=False)
|
||||
quantity = Column("quantity", Numeric(precision=15, scale=2), nullable=False)
|
||||
rate = Column("rate", Numeric(precision=15, scale=2), nullable=False)
|
||||
tax = Column("tax", Numeric(precision=15, scale=5), nullable=False)
|
||||
discount = Column("discount", Numeric(precision=15, scale=5), nullable=False)
|
||||
|
||||
voucher = relationship("Voucher", back_populates="inventories")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
voucher_id=None,
|
||||
product_id=None,
|
||||
batch_id=None,
|
||||
quantity=None,
|
||||
rate=None,
|
||||
tax=None,
|
||||
discount=None,
|
||||
batch=None,
|
||||
product=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.voucher_id = voucher_id
|
||||
if product is None:
|
||||
self.product_id = product_id
|
||||
else:
|
||||
self.product = product
|
||||
self.product_id = product.id
|
||||
if batch is None:
|
||||
self.batch_id = batch_id
|
||||
else:
|
||||
self.batch = batch
|
||||
self.quantity = quantity
|
||||
self.rate = rate
|
||||
self.tax = tax
|
||||
self.discount = discount
|
||||
|
||||
@hybrid_property
|
||||
def amount(self):
|
||||
return self.quantity * self.rate * (1 + self.tax) * (1 - self.discount)
|
||||
@@ -0,0 +1,57 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Column, ForeignKey, Integer, Numeric
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
|
||||
class Journal(Base):
|
||||
__tablename__ = "journals"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
debit = Column("debit", Integer, nullable=False)
|
||||
amount = Column("amount", Numeric(precision=15, scale=2), nullable=False)
|
||||
voucher_id = Column(
|
||||
"voucher_id",
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("vouchers.id"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
account_id = Column("account_id", UUID(as_uuid=True), ForeignKey("accounts.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")
|
||||
account = relationship("AccountBase", back_populates="journals")
|
||||
cost_centre = relationship("CostCentre", back_populates="journals")
|
||||
|
||||
@hybrid_property
|
||||
def signed_amount(self):
|
||||
return self.debit * self.amount
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
debit=None,
|
||||
amount=None,
|
||||
voucher_id=None,
|
||||
account_id=None,
|
||||
cost_centre_id=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.debit = debit
|
||||
self.amount = amount
|
||||
self.voucher_id = voucher_id
|
||||
self.account_id = account_id
|
||||
self.cost_centre_id = cost_centre_id
|
||||
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, DateTime, UniqueConstraint
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.schema import ForeignKey
|
||||
|
||||
from .meta import Base
|
||||
|
||||
|
||||
class LoginHistory(Base):
|
||||
__tablename__ = "auth_login_history"
|
||||
__table_args__ = (UniqueConstraint("user_id", "client_id", "date"),)
|
||||
id = Column("login_history_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.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)
|
||||
|
||||
def __init__(self, user_id=None, client_id=None, date=None, id_=None):
|
||||
self.user_id = user_id
|
||||
self.client_id = client_id
|
||||
self.date = datetime.utcnow() if date is None else date
|
||||
self.id = id_
|
||||
@@ -1,536 +0,0 @@
|
||||
import uuid
|
||||
|
||||
from datetime import date
|
||||
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
Column,
|
||||
Date,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
Numeric,
|
||||
PickleType,
|
||||
Unicode,
|
||||
UniqueConstraint,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Session, relationship
|
||||
|
||||
from .meta import Base
|
||||
|
||||
|
||||
class Product(Base):
|
||||
__tablename__ = "products"
|
||||
__table_args__ = (UniqueConstraint("name", "units"),)
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
code = Column("code", Integer, unique=True)
|
||||
name = Column("name", Unicode(255), nullable=False)
|
||||
units = Column("units", Unicode(255), nullable=False)
|
||||
fraction = Column("fraction", Numeric(precision=15, scale=5), nullable=False)
|
||||
fraction_units = Column("fraction_units", Unicode(255), nullable=False)
|
||||
product_yield = Column("product_yield", Numeric(precision=15, scale=5), nullable=False)
|
||||
product_group_id = Column(
|
||||
"product_group_id",
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("product_groups.id"),
|
||||
nullable=False,
|
||||
)
|
||||
account_id = Column("account_id", UUID(as_uuid=True), ForeignKey("accounts.id"), nullable=False)
|
||||
price = Column("cost_price", Numeric(precision=15, scale=2), nullable=False)
|
||||
sale_price = Column("sale_price", Numeric(precision=15, scale=2), nullable=False)
|
||||
is_active = Column("is_active", Boolean, nullable=False)
|
||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||
is_purchased = Column("is_purchased", Boolean, nullable=False)
|
||||
is_sold = Column("is_sold", Boolean, nullable=False)
|
||||
|
||||
batches = relationship("Batch", backref="product")
|
||||
inventories = relationship("Inventory", backref="product")
|
||||
recipes = relationship("Recipe", backref="product")
|
||||
account = relationship("Account", primaryjoin="Account.id==Product.account_id", backref="products")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
code=None,
|
||||
name=None,
|
||||
units=None,
|
||||
fraction=None,
|
||||
fraction_units=None,
|
||||
product_yield=None,
|
||||
product_group_id=None,
|
||||
account_id=None,
|
||||
price=None,
|
||||
sale_price=None,
|
||||
is_active=None,
|
||||
is_purchased=None,
|
||||
is_sold=None,
|
||||
id_=None,
|
||||
is_fixture=False,
|
||||
):
|
||||
self.code = code
|
||||
self.name = name
|
||||
self.units = units
|
||||
self.fraction = fraction
|
||||
self.fraction_units = fraction_units
|
||||
self.product_yield = product_yield
|
||||
self.product_group_id = product_group_id
|
||||
self.account_id = account_id
|
||||
self.price = price
|
||||
self.sale_price = sale_price
|
||||
self.is_active = is_active
|
||||
self.is_purchased = is_purchased
|
||||
self.is_sold = is_sold
|
||||
self.id = id_
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
return "{0} ({1})".format(self.name, self.units)
|
||||
|
||||
def create(self, db: Session):
|
||||
code = db.query(func.max(Product.code)).one()[0]
|
||||
self.code = 1 if code is None else code + 1
|
||||
db.add(self)
|
||||
return self
|
||||
|
||||
def can_delete(self, advanced_delete):
|
||||
if self.is_fixture:
|
||||
return False, f"{self.name} is a fixture and cannot be edited or deleted."
|
||||
if self.is_active:
|
||||
return False, "Product is active"
|
||||
if len(self.inventories) > 0 and not advanced_delete:
|
||||
return False, "Product has entries"
|
||||
return True, ""
|
||||
|
||||
@classmethod
|
||||
def query(cls, q, is_purchased=None, active=None, db=None):
|
||||
query_ = db.query(cls)
|
||||
if active is not None:
|
||||
query_ = query_.filter(cls.is_active == active)
|
||||
if is_purchased is not None:
|
||||
query_ = query_.filter(cls.is_purchased == is_purchased)
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
if item.strip() != "":
|
||||
query_ = query_.filter(cls.name.ilike(f"%{item}%"))
|
||||
return query_
|
||||
|
||||
@classmethod
|
||||
def suspense(cls):
|
||||
return uuid.UUID("aa79a643-9ddc-4790-ac7f-a41f9efb4c15")
|
||||
|
||||
|
||||
class Recipe(Base):
|
||||
__tablename__ = "recipes"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||
|
||||
quantity = Column("quantity", Numeric(precision=15, scale=2), nullable=False)
|
||||
cost_price = Column("cost_price", Numeric(precision=15, scale=2), nullable=False)
|
||||
sale_price = Column("sale_price", Numeric(precision=15, scale=2), nullable=False)
|
||||
notes = Column("notes", Unicode(255))
|
||||
|
||||
valid_from = Column("valid_from", Date, nullable=False)
|
||||
valid_to = Column("valid_to", Date, nullable=False)
|
||||
|
||||
effective_from = Column("effective_from", Date, nullable=False)
|
||||
effective_to = Column("effective_to", Date)
|
||||
|
||||
recipe_items = relationship("RecipeItem", backref="recipe")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
product_id=None,
|
||||
quantity=None,
|
||||
cost_price=None,
|
||||
sale_price=None,
|
||||
valid_from=None,
|
||||
valid_to=None,
|
||||
notes=None,
|
||||
effective_from=None,
|
||||
id_=None,
|
||||
):
|
||||
self.product_id = product_id
|
||||
self.quantity = quantity
|
||||
self.cost_price = cost_price
|
||||
self.sale_price = sale_price
|
||||
self.valid_from = valid_from
|
||||
self.valid_to = valid_to
|
||||
self.notes = "" if notes is None else notes
|
||||
self.effective_from = date.today() if effective_from is None else effective_from
|
||||
self.effective_to = None
|
||||
self.id = id_
|
||||
|
||||
|
||||
class RecipeItem(Base):
|
||||
__tablename__ = "recipe_items"
|
||||
__table_args__ = (UniqueConstraint("recipe_id", "product_id"),)
|
||||
|
||||
id = Column("recipe_item_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
recipe_id = Column("recipe_id", UUID(as_uuid=True), ForeignKey("recipes.id"), nullable=False)
|
||||
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||
quantity = Column("quantity", Integer, nullable=False)
|
||||
price = Column("price", Integer, nullable=False)
|
||||
|
||||
product = relationship("Product")
|
||||
|
||||
def __init__(self, recipe_id=None, product_id=None, quantity=None, price=None, id_=None):
|
||||
self.recipe_id = recipe_id
|
||||
self.product_id = product_id
|
||||
self.quantity = quantity
|
||||
self.price = price
|
||||
self.id = id_
|
||||
|
||||
|
||||
class ProductGroup(Base):
|
||||
__tablename__ = "product_groups"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True)
|
||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||
|
||||
products = relationship("Product", backref="product_group")
|
||||
|
||||
def __init__(self, name=None, id_=None, is_fixture=False):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@classmethod
|
||||
def menu_item(cls):
|
||||
return uuid.UUID("dad46805-f577-4e5b-8073-9b788e0173fc")
|
||||
|
||||
@classmethod
|
||||
def semi(cls):
|
||||
return uuid.UUID("e6bf81b9-1e9b-499f-81d5-ab5662e9d9b1")
|
||||
|
||||
|
||||
class CostCentre(Base):
|
||||
__tablename__ = "cost_centres"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True)
|
||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||
|
||||
accounts = relationship("AccountBase", backref="cost_centre")
|
||||
journals = relationship("Journal", backref="cost_centre")
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
def __init__(self, name=None, id_=None, is_fixture=False):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@classmethod
|
||||
def cost_centre_purchase(cls):
|
||||
return uuid.UUID("7b845f95-dfef-fa4a-897c-f0baf15284a3")
|
||||
|
||||
@classmethod
|
||||
def cost_centre_kitchen(cls):
|
||||
return uuid.UUID("b2d398ce-e3cc-c542-9feb-5d7783e899df")
|
||||
|
||||
@classmethod
|
||||
def cost_centre_overall(cls):
|
||||
return uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d")
|
||||
|
||||
@classmethod
|
||||
def overall(cls):
|
||||
return {
|
||||
"id": uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d"),
|
||||
"name": "Overall",
|
||||
}
|
||||
|
||||
|
||||
class AccountBase(Base):
|
||||
__tablename__ = "accounts"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
code = Column("code", Integer, nullable=False)
|
||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||
type = Column("type", Integer, nullable=False)
|
||||
account_type = Column("account_type", Unicode(50), nullable=False)
|
||||
is_starred = Column("is_starred", Boolean, nullable=False)
|
||||
is_active = Column("is_active", Boolean, nullable=False)
|
||||
is_reconcilable = Column("is_reconcilable", Boolean, 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)
|
||||
|
||||
__mapper_args__ = {"polymorphic_on": account_type}
|
||||
|
||||
journals = relationship("Journal", back_populates="account")
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def type_object(self):
|
||||
return AccountType.by_id(self.type)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
code=None,
|
||||
name=None,
|
||||
type_=None,
|
||||
is_starred=None,
|
||||
is_active=None,
|
||||
is_reconcilable=False,
|
||||
cost_centre_id=None,
|
||||
id_=None,
|
||||
is_fixture=False,
|
||||
):
|
||||
self.code = code
|
||||
self.name = name
|
||||
self.type = type_
|
||||
self.is_starred = is_starred
|
||||
self.is_active = is_active
|
||||
self.is_reconcilable = is_reconcilable
|
||||
self.cost_centre_id = cost_centre_id
|
||||
self.id = id_
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@classmethod
|
||||
def query(cls, q, type_, reconcilable=None, active=None, db=None):
|
||||
query_ = db.query(cls)
|
||||
if type_ is not None:
|
||||
if not isinstance(type_, int):
|
||||
type_ = int(type_)
|
||||
query_ = query_.filter(cls.type == type_)
|
||||
if reconcilable is not None:
|
||||
query_ = query_.filter(cls.is_reconcilable == reconcilable)
|
||||
if active is not None:
|
||||
query_ = query_.filter(cls.is_active == active)
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
query_ = query_.filter(cls.name.ilike(f"%{item}%"))
|
||||
return query_.order_by(cls.name)
|
||||
|
||||
def create(self, db: Session):
|
||||
code = db.query(func.max(AccountBase.code)).filter(AccountBase.type == self.type).one()[0]
|
||||
self.code = 1 if code is None else code + 1
|
||||
db.add(self)
|
||||
return self
|
||||
|
||||
def can_delete(self, advanced_delete):
|
||||
if self.is_fixture:
|
||||
return False, f"{self.name} is a fixture and cannot be edited or deleted."
|
||||
if self.is_active:
|
||||
return False, "Account is active"
|
||||
if len(self.journals) > 0 and not advanced_delete:
|
||||
return False, "Account has journal entries"
|
||||
return True, ""
|
||||
|
||||
@classmethod
|
||||
def get_code(cls, type_, db: Session):
|
||||
code = db.query(func.max(AccountBase.code)).filter(AccountBase.type == type_).one()[0]
|
||||
return 1 if code is None else code + 1
|
||||
|
||||
@classmethod
|
||||
def all_purchases(cls):
|
||||
return uuid.UUID("240dd899-c413-854c-a7eb-67a29d154490")
|
||||
|
||||
@classmethod
|
||||
def cash_in_hand(cls):
|
||||
return {"id": "ed2341bb-80b8-9649-90db-f9aaca183bb3", "name": "Cash in Hand"}
|
||||
|
||||
@classmethod
|
||||
def local_purchase(cls):
|
||||
return {"id": "d2b75912-505f-2548-9093-466dfff6a0f9", "name": "Local Purchase"}
|
||||
|
||||
@classmethod
|
||||
def salary(cls):
|
||||
return {"id": "5c2b54d0-c174-004d-a0d5-92cdaadcefa7", "name": "Staff Salary"}
|
||||
|
||||
@classmethod
|
||||
def salary_id(cls):
|
||||
return uuid.UUID("5c2b54d0-c174-004d-a0d5-92cdaadcefa7")
|
||||
|
||||
@classmethod
|
||||
def incentive(cls):
|
||||
return {"id": "b7eff754-e8ba-e047-ab06-9132c15c7640", "name": "Incentives"}
|
||||
|
||||
@classmethod
|
||||
def incentive_id(cls):
|
||||
return uuid.UUID("b7eff754-e8ba-e047-ab06-9132c15c7640")
|
||||
|
||||
@classmethod
|
||||
def esi_pf_expense(cls):
|
||||
return uuid.UUID("d2a1a286-e900-764b-a1a5-9f4b00dbb940")
|
||||
|
||||
@classmethod
|
||||
def esi_pf_payable(cls):
|
||||
return uuid.UUID("42277912-cc18-854b-b134-9f4b00dba419")
|
||||
|
||||
@classmethod
|
||||
def suspense(cls):
|
||||
return uuid.UUID("3854e317-6f3b-5142-ab26-9c44d4cddd08")
|
||||
|
||||
|
||||
class Employee(AccountBase):
|
||||
__tablename__ = "employees"
|
||||
__mapper_args__ = {"polymorphic_identity": "employees"}
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), ForeignKey(AccountBase.id), primary_key=True)
|
||||
designation = Column("designation", Unicode(255), nullable=False)
|
||||
salary = Column("salary", Integer, nullable=False)
|
||||
points = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
||||
joining_date = Column("joining_date", Date, nullable=False)
|
||||
leaving_date = Column("leaving_date", Date, nullable=True)
|
||||
|
||||
attendances = relationship("Attendance", backref="employee", cascade=None, cascade_backrefs=False)
|
||||
fingerprints = relationship("Fingerprint", backref="employee", cascade=None, cascade_backrefs=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
code=None,
|
||||
name=None,
|
||||
is_starred=None,
|
||||
is_active=None,
|
||||
cost_centre_id=None,
|
||||
designation=None,
|
||||
salary=None,
|
||||
points=None,
|
||||
joining_date=None,
|
||||
leaving_date=None,
|
||||
):
|
||||
self.designation = designation
|
||||
self.salary = salary
|
||||
self.points = points
|
||||
self.joining_date = joining_date
|
||||
self.leaving_date = leaving_date
|
||||
super().__init__(
|
||||
code=code,
|
||||
name=name,
|
||||
type_=10,
|
||||
is_starred=is_starred,
|
||||
is_active=is_active,
|
||||
is_reconcilable=False,
|
||||
cost_centre_id=cost_centre_id,
|
||||
)
|
||||
|
||||
def create(self, db: Session):
|
||||
code = db.query(func.max(AccountBase.code)).filter(AccountBase.type == self.type).one()[0]
|
||||
self.code = 1 if code is None else code + 1
|
||||
self.name += f" ({str(self.code)})"
|
||||
db.add(self)
|
||||
return self
|
||||
|
||||
def can_delete(self, advanced_delete):
|
||||
return super(Employee, self).can_delete(advanced_delete)
|
||||
|
||||
|
||||
class Account(AccountBase):
|
||||
__mapper_args__ = {"polymorphic_identity": ""}
|
||||
|
||||
def can_delete(self, advanced_delete):
|
||||
if len(self.products) > 0:
|
||||
return False, "Account has products"
|
||||
return super(Account, self).can_delete(advanced_delete)
|
||||
|
||||
|
||||
class AttendanceType:
|
||||
def __init__(self, id_, name, value=None):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.value = value
|
||||
|
||||
@classmethod
|
||||
def list(cls):
|
||||
return [
|
||||
AttendanceType(0, "Not Set", 0),
|
||||
AttendanceType(1, "Present", 1),
|
||||
AttendanceType(2, "Off Day", 1),
|
||||
AttendanceType(3, "On Leave", 0),
|
||||
AttendanceType(4, "Absent", 0),
|
||||
AttendanceType(5, "Half Day", 0.5),
|
||||
AttendanceType(6, "Double Duty", 2),
|
||||
AttendanceType(7, "Paid Leave Availed", 1),
|
||||
AttendanceType(8, "Casual Leave Availed", 1),
|
||||
AttendanceType(9, "Compensatory Off", 1),
|
||||
AttendanceType(10, "Half Day + PL", 1),
|
||||
AttendanceType(11, "Half Day + CL", 1),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def by_name(cls, name):
|
||||
return next(i for i in cls.list() if i.name == name)
|
||||
|
||||
@classmethod
|
||||
def by_id(cls, id_):
|
||||
return next(i for i in cls.list() if i.id == id_)
|
||||
|
||||
|
||||
class AccountType:
|
||||
def __init__(
|
||||
self,
|
||||
id_,
|
||||
name,
|
||||
balance_sheet=None,
|
||||
debit=None,
|
||||
cash_flow_classification=None,
|
||||
order=None,
|
||||
show_in_list=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.balance_sheet = balance_sheet
|
||||
self.debit = debit
|
||||
self.cash_flow_classification = cash_flow_classification
|
||||
# Cash flow Classifications are:
|
||||
# Cash
|
||||
# Operating
|
||||
# Investing
|
||||
# Financing
|
||||
self.order = order
|
||||
self.show_in_list = show_in_list
|
||||
|
||||
@classmethod
|
||||
def list(cls):
|
||||
return [
|
||||
AccountType(1, "Cash", True, True, "Cash", 10000, True),
|
||||
AccountType(2, "Purchase", False, True, "Operating", 20000, True),
|
||||
AccountType(3, "Sale", False, False, "Operating", 10000, True),
|
||||
AccountType(4, "Assets", True, True, "Investing", 20000, True),
|
||||
AccountType(5, "Capital", True, False, "Financing", 70000, True),
|
||||
AccountType(6, "Debtors", True, True, "Operating", 30000, True),
|
||||
AccountType(7, "Expenses", False, True, "Operating", 40000, True),
|
||||
AccountType(9, "Creditors", True, False, "Operating", 60000, True),
|
||||
AccountType(10, "Salary", True, True, "Operating", 40000, False),
|
||||
AccountType(11, "Liabilities", True, False, "Operating", 50000, True),
|
||||
AccountType(12, "Revenue", False, False, "Operating", 30000, True),
|
||||
AccountType(13, "Tax", True, False, "Operating", 80000, True),
|
||||
]
|
||||
# list.append(AccountType(8, 'Discount', False, False, True, 30, True))
|
||||
# list.append(AccountType(14, 'Total', False, False, False, 900, False))
|
||||
# list.append(AccountType(15, 'Net', False, False, False, 1000, False))
|
||||
|
||||
@classmethod
|
||||
def by_name(cls, name):
|
||||
return next(i for i in cls.list() if i.name == name)
|
||||
|
||||
@classmethod
|
||||
def by_id(cls, id_):
|
||||
return next(i for i in cls.list() if i.id == id_)
|
||||
|
||||
|
||||
class DbSetting(Base):
|
||||
__tablename__ = "settings"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||
data = Column("data", PickleType)
|
||||
|
||||
def __init__(self, id_=None, name=None, data=None):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.data = data
|
||||
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from typing import List
|
||||
|
||||
from sqlalchemy import Column, Unicode
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from .meta import Base
|
||||
from .role import Role
|
||||
from .role_permission import role_permission
|
||||
|
||||
|
||||
class Permission(Base):
|
||||
__tablename__ = "auth_permissions"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True)
|
||||
|
||||
roles: List[Role] = relationship("Role", secondary=role_permission, backref="permissions")
|
||||
|
||||
def __init__(self, name=None, id_=None):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
@@ -0,0 +1,116 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
Column,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
Numeric,
|
||||
Unicode,
|
||||
UniqueConstraint,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Session, relationship
|
||||
|
||||
|
||||
class Product(Base):
|
||||
__tablename__ = "products"
|
||||
__table_args__ = (UniqueConstraint("name", "units"),)
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
code = Column("code", Integer, unique=True)
|
||||
name = Column("name", Unicode(255), nullable=False)
|
||||
units = Column("units", Unicode(255), nullable=False)
|
||||
fraction = Column("fraction", Numeric(precision=15, scale=5), nullable=False)
|
||||
fraction_units = Column("fraction_units", Unicode(255), nullable=False)
|
||||
product_yield = Column("product_yield", Numeric(precision=15, scale=5), nullable=False)
|
||||
product_group_id = Column(
|
||||
"product_group_id",
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("product_groups.id"),
|
||||
nullable=False,
|
||||
)
|
||||
account_id = Column("account_id", UUID(as_uuid=True), ForeignKey("accounts.id"), nullable=False)
|
||||
price = Column("cost_price", Numeric(precision=15, scale=2), nullable=False)
|
||||
sale_price = Column("sale_price", Numeric(precision=15, scale=2), nullable=False)
|
||||
is_active = Column("is_active", Boolean, nullable=False)
|
||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||
is_purchased = Column("is_purchased", Boolean, nullable=False)
|
||||
is_sold = Column("is_sold", Boolean, nullable=False)
|
||||
|
||||
batches = relationship("Batch", backref="product")
|
||||
inventories = relationship("Inventory", backref="product")
|
||||
recipes = relationship("Recipe", backref="product")
|
||||
account = relationship("Account", primaryjoin="Account.id==Product.account_id", backref="products")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
code=None,
|
||||
name=None,
|
||||
units=None,
|
||||
fraction=None,
|
||||
fraction_units=None,
|
||||
product_yield=None,
|
||||
product_group_id=None,
|
||||
account_id=None,
|
||||
price=None,
|
||||
sale_price=None,
|
||||
is_active=None,
|
||||
is_purchased=None,
|
||||
is_sold=None,
|
||||
id_=None,
|
||||
is_fixture=False,
|
||||
):
|
||||
self.code = code
|
||||
self.name = name
|
||||
self.units = units
|
||||
self.fraction = fraction
|
||||
self.fraction_units = fraction_units
|
||||
self.product_yield = product_yield
|
||||
self.product_group_id = product_group_id
|
||||
self.account_id = account_id
|
||||
self.price = price
|
||||
self.sale_price = sale_price
|
||||
self.is_active = is_active
|
||||
self.is_purchased = is_purchased
|
||||
self.is_sold = is_sold
|
||||
self.id = id_
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
return "{0} ({1})".format(self.name, self.units)
|
||||
|
||||
def create(self, db: Session):
|
||||
code = db.query(func.max(Product.code)).one()[0]
|
||||
self.code = 1 if code is None else code + 1
|
||||
db.add(self)
|
||||
return self
|
||||
|
||||
def can_delete(self, advanced_delete):
|
||||
if self.is_fixture:
|
||||
return False, f"{self.name} is a fixture and cannot be edited or deleted."
|
||||
if self.is_active:
|
||||
return False, "Product is active"
|
||||
if len(self.inventories) > 0 and not advanced_delete:
|
||||
return False, "Product has entries"
|
||||
return True, ""
|
||||
|
||||
@classmethod
|
||||
def query(cls, q, is_purchased=None, active=None, db=None):
|
||||
query_ = db.query(cls)
|
||||
if active is not None:
|
||||
query_ = query_.filter(cls.is_active == active)
|
||||
if is_purchased is not None:
|
||||
query_ = query_.filter(cls.is_purchased == is_purchased)
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
if item.strip() != "":
|
||||
query_ = query_.filter(cls.name.ilike(f"%{item}%"))
|
||||
return query_
|
||||
|
||||
@classmethod
|
||||
def suspense(cls):
|
||||
return uuid.UUID("aa79a643-9ddc-4790-ac7f-a41f9efb4c15")
|
||||
@@ -0,0 +1,29 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Boolean, Column, Unicode
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
|
||||
class ProductGroup(Base):
|
||||
__tablename__ = "product_groups"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True)
|
||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||
|
||||
products = relationship("Product", backref="product_group")
|
||||
|
||||
def __init__(self, name=None, id_=None, is_fixture=False):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@classmethod
|
||||
def menu_item(cls):
|
||||
return uuid.UUID("dad46805-f577-4e5b-8073-9b788e0173fc")
|
||||
|
||||
@classmethod
|
||||
def semi(cls):
|
||||
return uuid.UUID("e6bf81b9-1e9b-499f-81d5-ab5662e9d9b1")
|
||||
@@ -0,0 +1,51 @@
|
||||
import uuid
|
||||
|
||||
from datetime import date
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Column, Date, ForeignKey, Numeric, Unicode
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
|
||||
class Recipe(Base):
|
||||
__tablename__ = "recipes"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||
|
||||
quantity = Column("quantity", Numeric(precision=15, scale=2), nullable=False)
|
||||
cost_price = Column("cost_price", Numeric(precision=15, scale=2), nullable=False)
|
||||
sale_price = Column("sale_price", Numeric(precision=15, scale=2), nullable=False)
|
||||
notes = Column("notes", Unicode(255))
|
||||
|
||||
valid_from = Column("valid_from", Date, nullable=False)
|
||||
valid_to = Column("valid_to", Date, nullable=False)
|
||||
|
||||
effective_from = Column("effective_from", Date, nullable=False)
|
||||
effective_to = Column("effective_to", Date)
|
||||
|
||||
recipe_items = relationship("RecipeItem", backref="recipe")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
product_id=None,
|
||||
quantity=None,
|
||||
cost_price=None,
|
||||
sale_price=None,
|
||||
valid_from=None,
|
||||
valid_to=None,
|
||||
notes=None,
|
||||
effective_from=None,
|
||||
id_=None,
|
||||
):
|
||||
self.product_id = product_id
|
||||
self.quantity = quantity
|
||||
self.cost_price = cost_price
|
||||
self.sale_price = sale_price
|
||||
self.valid_from = valid_from
|
||||
self.valid_to = valid_to
|
||||
self.notes = "" if notes is None else notes
|
||||
self.effective_from = date.today() if effective_from is None else effective_from
|
||||
self.effective_to = None
|
||||
self.id = id_
|
||||
@@ -0,0 +1,26 @@
|
||||
import uuid
|
||||
|
||||
from brewman.models.meta import Base
|
||||
from sqlalchemy import Column, ForeignKey, Integer, UniqueConstraint
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
|
||||
class RecipeItem(Base):
|
||||
__tablename__ = "recipe_items"
|
||||
__table_args__ = (UniqueConstraint("recipe_id", "product_id"),)
|
||||
|
||||
id = Column("recipe_item_id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
recipe_id = Column("recipe_id", UUID(as_uuid=True), ForeignKey("recipes.id"), nullable=False)
|
||||
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||
quantity = Column("quantity", Integer, nullable=False)
|
||||
price = Column("price", Integer, nullable=False)
|
||||
|
||||
product = relationship("Product")
|
||||
|
||||
def __init__(self, recipe_id=None, product_id=None, quantity=None, price=None, id_=None):
|
||||
self.recipe_id = recipe_id
|
||||
self.product_id = product_id
|
||||
self.quantity = quantity
|
||||
self.price = price
|
||||
self.id = id_
|
||||
@@ -0,0 +1,19 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column, Unicode
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
from .meta import Base
|
||||
|
||||
|
||||
class Role(Base):
|
||||
__tablename__ = "auth_roles"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True)
|
||||
|
||||
def __init__(self, name=None, id_=None):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
@@ -0,0 +1,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.schema import ForeignKey, Table
|
||||
|
||||
from .meta import Base
|
||||
|
||||
|
||||
role_permission = Table(
|
||||
"role_permissions",
|
||||
Base.metadata,
|
||||
Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4),
|
||||
Column("permission_id", UUID(as_uuid=True), ForeignKey("auth_permissions.id")),
|
||||
Column("role_id", UUID(as_uuid=True), ForeignKey("auth_roles.id")),
|
||||
)
|
||||
@@ -0,0 +1,62 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from hashlib import md5
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import Boolean, Column, Unicode, desc
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Session, relationship, synonym
|
||||
|
||||
from .login_history import LoginHistory
|
||||
from .meta import Base
|
||||
from .role import Role
|
||||
from .user_role import user_role
|
||||
|
||||
|
||||
def encrypt(val):
|
||||
return md5(val.encode("utf-8") + "Salt".encode("utf-8")).hexdigest()
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "auth_users"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("username", Unicode(255), unique=True)
|
||||
_password = Column("password", Unicode(60))
|
||||
locked_out = Column("disabled", Boolean)
|
||||
|
||||
roles: List[Role] = relationship("Role", secondary=user_role)
|
||||
login_history: List[LoginHistory] = relationship("LoginHistory", order_by=desc(LoginHistory.date), backref="user")
|
||||
|
||||
def _get_password(self):
|
||||
return self._password
|
||||
|
||||
def _set_password(self, password):
|
||||
self._password = encrypt(password)
|
||||
|
||||
password = property(_get_password, _set_password)
|
||||
password = synonym("_password", descriptor=password)
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
def __init__(self, name=None, password=None, locked_out=None, id_=None):
|
||||
self.name = name
|
||||
self.password = password
|
||||
self.locked_out = locked_out
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def auth(cls, name: str, password: str, db: Session) -> Optional[User]:
|
||||
if password is None:
|
||||
return None
|
||||
user = db.query(User).filter(User.name.ilike(name)).first()
|
||||
if not user:
|
||||
return None
|
||||
if user.password != encrypt(password) or user.locked_out:
|
||||
return None
|
||||
else:
|
||||
return user
|
||||
@@ -0,0 +1,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.schema import ForeignKey, Table
|
||||
|
||||
from .meta import Base
|
||||
|
||||
|
||||
user_role = Table(
|
||||
"user_roles",
|
||||
Base.metadata,
|
||||
Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4),
|
||||
Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.id")),
|
||||
Column("role_id", UUID(as_uuid=True), ForeignKey("auth_roles.id")),
|
||||
)
|
||||
@@ -3,7 +3,7 @@ from typing import Union
|
||||
import brewman.schemas.input as schema_in
|
||||
import brewman.schemas.voucher as schema
|
||||
|
||||
from brewman.models import Voucher
|
||||
from brewman.models.voucher import Voucher
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
|
||||
@@ -2,64 +2,13 @@ import uuid
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from brewman.models.master import Product
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
Column,
|
||||
Date,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
Numeric,
|
||||
Unicode,
|
||||
UniqueConstraint,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import BYTEA, UUID
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.orm import Session, backref, relationship, synonym
|
||||
from sqlalchemy import Boolean, Column, Date, DateTime, ForeignKey, Integer, Unicode
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship, synonym
|
||||
|
||||
from .meta import Base
|
||||
|
||||
|
||||
class VoucherType:
|
||||
def __init__(self, id_, name):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
|
||||
@classmethod
|
||||
def list(cls):
|
||||
list_ = [
|
||||
VoucherType(1, "Journal"),
|
||||
VoucherType(2, "Purchase"),
|
||||
VoucherType(3, "Issue"),
|
||||
VoucherType(4, "Payment"),
|
||||
VoucherType(5, "Receipt"),
|
||||
VoucherType(6, "Purchase Return"),
|
||||
VoucherType(7, "Opening Accounts"),
|
||||
VoucherType(8, "Opening Batches"),
|
||||
VoucherType(9, "Verification"),
|
||||
VoucherType(10, "Opening Balance"),
|
||||
VoucherType(11, "Closing Balance"),
|
||||
VoucherType(12, "Employee Benefit"),
|
||||
VoucherType(13, "Incentive"),
|
||||
]
|
||||
return list_
|
||||
|
||||
@classmethod
|
||||
def by_name(cls, name):
|
||||
list_ = cls.list()
|
||||
for item in list_:
|
||||
if item.name == name:
|
||||
return item
|
||||
|
||||
@classmethod
|
||||
def by_id(cls, id_):
|
||||
list_ = cls.list()
|
||||
for item in list_:
|
||||
if item.id == id_:
|
||||
return item
|
||||
|
||||
|
||||
class Voucher(Base):
|
||||
__tablename__ = "vouchers"
|
||||
|
||||
@@ -145,329 +94,3 @@ class Voucher(Base):
|
||||
self.type = type_
|
||||
self.user_id = user_id
|
||||
self.poster_id = poster_id
|
||||
|
||||
|
||||
class Journal(Base):
|
||||
__tablename__ = "journals"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
debit = Column("debit", Integer, nullable=False)
|
||||
amount = Column("amount", Numeric(precision=15, scale=2), nullable=False)
|
||||
voucher_id = Column(
|
||||
"voucher_id",
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("vouchers.id"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
account_id = Column("account_id", UUID(as_uuid=True), ForeignKey("accounts.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")
|
||||
account = relationship("AccountBase", back_populates="journals")
|
||||
|
||||
@hybrid_property
|
||||
def signed_amount(self):
|
||||
return self.debit * self.amount
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
debit=None,
|
||||
amount=None,
|
||||
voucher_id=None,
|
||||
account_id=None,
|
||||
cost_centre_id=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.debit = debit
|
||||
self.amount = amount
|
||||
self.voucher_id = voucher_id
|
||||
self.account_id = account_id
|
||||
self.cost_centre_id = cost_centre_id
|
||||
|
||||
|
||||
class EmployeeBenefit(Base):
|
||||
__tablename__ = "employee_benefit"
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column("voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False)
|
||||
journal_id = Column("journal_id", UUID(as_uuid=True), ForeignKey("journals.id"), nullable=False)
|
||||
gross_salary = Column("gross_salary", Integer)
|
||||
days_worked = Column("days_worked", Integer)
|
||||
esi_ee = Column("esi_employee", Integer)
|
||||
pf_ee = Column("pf_employee", Integer)
|
||||
esi_er = Column("esi_employer", Integer)
|
||||
pf_er = Column("pf_employer", Integer)
|
||||
|
||||
journal = relationship(
|
||||
Journal,
|
||||
backref=backref("employee_benefit", uselist=False),
|
||||
cascade=None,
|
||||
cascade_backrefs=False,
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
voucher_id=None,
|
||||
journal_id=None,
|
||||
journal=None,
|
||||
gross_salary=None,
|
||||
days_worked=None,
|
||||
esi_ee=None,
|
||||
pf_ee=None,
|
||||
esi_er=None,
|
||||
pf_er=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.voucher_id = voucher_id
|
||||
self.gross_salary = gross_salary
|
||||
self.days_worked = days_worked
|
||||
self.esi_ee = esi_ee
|
||||
self.pf_ee = pf_ee
|
||||
self.esi_er = esi_er
|
||||
self.pf_er = pf_er
|
||||
if journal is None:
|
||||
self.journal_id = journal_id
|
||||
else:
|
||||
self.journal = journal
|
||||
|
||||
|
||||
class Incentive(Base):
|
||||
__tablename__ = "incentives"
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column("voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.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)
|
||||
points = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
||||
|
||||
journal = relationship(
|
||||
Journal,
|
||||
backref=backref("incentive", uselist=False),
|
||||
cascade=None,
|
||||
cascade_backrefs=False,
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
voucher_id=None,
|
||||
journal_id=None,
|
||||
journal=None,
|
||||
days_worked=None,
|
||||
points=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.voucher_id = voucher_id
|
||||
if journal is None:
|
||||
self.journal_id = journal_id
|
||||
else:
|
||||
self.journal = journal
|
||||
self.days_worked = days_worked
|
||||
self.points = points
|
||||
|
||||
|
||||
class Inventory(Base):
|
||||
__tablename__ = "inventories"
|
||||
__table_args__ = (UniqueConstraint("voucher_id", "batch_id"),)
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column(
|
||||
"voucher_id",
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("vouchers.id"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||
batch_id = Column("batch_id", UUID(as_uuid=True), ForeignKey("batches.id"), nullable=False)
|
||||
quantity = Column("quantity", Numeric(precision=15, scale=2), nullable=False)
|
||||
rate = Column("rate", Numeric(precision=15, scale=2), nullable=False)
|
||||
tax = Column("tax", Numeric(precision=15, scale=5), nullable=False)
|
||||
discount = Column("discount", Numeric(precision=15, scale=5), nullable=False)
|
||||
|
||||
voucher = relationship("Voucher", back_populates="inventories")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
voucher_id=None,
|
||||
product_id=None,
|
||||
batch_id=None,
|
||||
quantity=None,
|
||||
rate=None,
|
||||
tax=None,
|
||||
discount=None,
|
||||
batch=None,
|
||||
product=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.voucher_id = voucher_id
|
||||
if product is None:
|
||||
self.product_id = product_id
|
||||
else:
|
||||
self.product = product
|
||||
self.product_id = product.id
|
||||
if batch is None:
|
||||
self.batch_id = batch_id
|
||||
else:
|
||||
self.batch = batch
|
||||
self.quantity = quantity
|
||||
self.rate = rate
|
||||
self.tax = tax
|
||||
self.discount = discount
|
||||
|
||||
@hybrid_property
|
||||
def amount(self):
|
||||
return self.quantity * self.rate * (1 + self.tax) * (1 - self.discount)
|
||||
|
||||
|
||||
class Batch(Base):
|
||||
__tablename__ = "batches"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Date, nullable=False)
|
||||
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||
quantity_remaining = Column("quantity_remaining", Numeric(precision=15, scale=2), nullable=False)
|
||||
rate = Column("rate", Numeric(precision=15, scale=2), nullable=False)
|
||||
tax = Column("tax", Numeric(precision=15, scale=5), nullable=False)
|
||||
discount = Column("discount", Numeric(precision=15, scale=5), nullable=False)
|
||||
|
||||
inventories = relationship("Inventory", backref="batch", cascade=None, cascade_backrefs=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name=None,
|
||||
product_id=None,
|
||||
quantity_remaining=None,
|
||||
rate=None,
|
||||
tax=None,
|
||||
discount=None,
|
||||
product=None,
|
||||
):
|
||||
self.name = name
|
||||
self.product_id = product_id
|
||||
self.quantity_remaining = quantity_remaining
|
||||
self.rate = rate
|
||||
self.tax = tax
|
||||
self.discount = discount
|
||||
if product is None:
|
||||
self.product_id = product_id
|
||||
else:
|
||||
self.product = product
|
||||
|
||||
def amount(self):
|
||||
return self.quantity_remaining * self.rate * (1 + self.tax) * (1 - self.discount)
|
||||
|
||||
@classmethod
|
||||
def list(cls, q, include_nil, date, db: Session):
|
||||
query = db.query(cls).join(cls.product)
|
||||
if not include_nil:
|
||||
query = query.filter(cls.quantity_remaining > 0)
|
||||
if date is not None:
|
||||
query = query.filter(cls.name <= date)
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
query = query.filter(Product.name.ilike(f"%{item}%"))
|
||||
return query.order_by(Product.name).order_by(cls.name).all()
|
||||
|
||||
@classmethod
|
||||
def suspense(cls):
|
||||
return uuid.UUID("a955790e-93cf-493c-a816-c7d92b127383")
|
||||
|
||||
|
||||
class Attendance(Base):
|
||||
__tablename__ = "attendances"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
employee_id = Column("employee_id", UUID(as_uuid=True), ForeignKey("employees.id"))
|
||||
date = Column("date", Date, nullable=False)
|
||||
attendance_type = Column("attendance_type", Integer)
|
||||
amount = Column("amount", Numeric(precision=5, scale=2))
|
||||
creation_date = Column("creation_date", DateTime(timezone=True))
|
||||
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.id"))
|
||||
is_valid = Column("is_valid", Boolean)
|
||||
|
||||
user = relationship("User", primaryjoin="User.id==Attendance.user_id")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id_=None,
|
||||
employee_id=None,
|
||||
date=None,
|
||||
attendance_type=None,
|
||||
amount=None,
|
||||
creation_date=None,
|
||||
user_id=None,
|
||||
is_valid=None,
|
||||
):
|
||||
self.id = id_
|
||||
self.employee_id = employee_id
|
||||
self.date = date
|
||||
self.attendance_type = attendance_type
|
||||
self.amount = amount if amount is not None else 0
|
||||
self.creation_date = creation_date or datetime.utcnow()
|
||||
self.user_id = user_id
|
||||
self.is_valid = is_valid if is_valid is not None else True
|
||||
|
||||
def create(self, db: Session):
|
||||
old = (
|
||||
db.query(Attendance)
|
||||
.filter(Attendance.date == self.date)
|
||||
.filter(Attendance.employee_id == self.employee_id)
|
||||
.filter(Attendance.is_valid == True) # noqa: E712
|
||||
.first()
|
||||
)
|
||||
if old is None or old.attendance_type != self.attendance_type:
|
||||
if old is not None:
|
||||
old.is_valid = False
|
||||
db.add(self)
|
||||
|
||||
|
||||
class Fingerprint(Base):
|
||||
__tablename__ = "fingerprints"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
employee_id = Column("employee_id", UUID(as_uuid=True), ForeignKey("employees.id"))
|
||||
date = Column("date", DateTime)
|
||||
|
||||
def __init__(self, id_=None, employee_id=None, date=None):
|
||||
self.id = id_
|
||||
self.employee_id = employee_id
|
||||
self.date = date
|
||||
self.fingerprint_type = 0
|
||||
|
||||
|
||||
class DbImage(Base):
|
||||
__tablename__ = "images"
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
resource_id = Column("resource_id", UUID(as_uuid=True), nullable=False)
|
||||
resource_type = Column("resource_type", Unicode(255), nullable=False)
|
||||
image = Column("image", BYTEA, nullable=False)
|
||||
thumbnail = Column("thumbnail", BYTEA, nullable=False)
|
||||
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
resource_id=None,
|
||||
resource_type=None,
|
||||
image=None,
|
||||
thumbnail=None,
|
||||
creation_date=None,
|
||||
id_=None,
|
||||
):
|
||||
self.resource_id = resource_id
|
||||
self.resource_type = resource_type
|
||||
self.image = image
|
||||
self.thumbnail = thumbnail
|
||||
self.creation_date = creation_date or datetime.utcnow()
|
||||
self.id = id_
|
||||
@@ -0,0 +1,37 @@
|
||||
class VoucherType:
|
||||
def __init__(self, id_, name):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
|
||||
@classmethod
|
||||
def list(cls):
|
||||
list_ = [
|
||||
VoucherType(1, "Journal"),
|
||||
VoucherType(2, "Purchase"),
|
||||
VoucherType(3, "Issue"),
|
||||
VoucherType(4, "Payment"),
|
||||
VoucherType(5, "Receipt"),
|
||||
VoucherType(6, "Purchase Return"),
|
||||
VoucherType(7, "Opening Accounts"),
|
||||
VoucherType(8, "Opening Batches"),
|
||||
VoucherType(9, "Verification"),
|
||||
VoucherType(10, "Opening Balance"),
|
||||
VoucherType(11, "Closing Balance"),
|
||||
VoucherType(12, "Employee Benefit"),
|
||||
VoucherType(13, "Incentive"),
|
||||
]
|
||||
return list_
|
||||
|
||||
@classmethod
|
||||
def by_name(cls, name):
|
||||
list_ = cls.list()
|
||||
for item in list_:
|
||||
if item.name == name:
|
||||
return item
|
||||
|
||||
@classmethod
|
||||
def by_id(cls, id_):
|
||||
list_ = cls.list()
|
||||
for item in list_:
|
||||
if item.id == id_:
|
||||
return item
|
||||
@@ -7,7 +7,7 @@ from typing import Optional
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..models.master import DbSetting
|
||||
from ..models.db_setting import DbSetting
|
||||
|
||||
|
||||
def get_lock_info(db: Session) -> (Optional[date], Optional[date]):
|
||||
|
||||
@@ -13,8 +13,13 @@ from sqlalchemy.orm import Session, joinedload_all
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import Account, AccountBase, AccountType, CostCentre
|
||||
from ..models.voucher import Journal, Voucher, VoucherType
|
||||
from ..models.account import Account
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.account_type import AccountType
|
||||
from ..models.cost_centre import CostCentre
|
||||
from ..models.journal import Journal
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import brewman.schemas.account_type as schemas
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..models.master import AccountType
|
||||
from ..models.account_type import AccountType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ from sqlalchemy.orm import Session
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import Employee
|
||||
from ..models.voucher import Attendance
|
||||
from ..models.attendance import Attendance
|
||||
from ..models.employee import Employee
|
||||
from ..routers.fingerprint import get_prints
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@ from sqlalchemy import or_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import AttendanceType, Employee
|
||||
from ..models.voucher import Attendance
|
||||
from ..models.attendance import Attendance
|
||||
from ..models.attendance_type import AttendanceType
|
||||
from ..models.employee import Employee
|
||||
from .attendance import date_range
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..models.master import AttendanceType
|
||||
from ..models.attendance_type import AttendanceType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ from typing import List
|
||||
import brewman.schemas.client as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...db.session import SessionLocal
|
||||
from ...models.auth import Client, LoginHistory
|
||||
from ...models.client import Client
|
||||
from ...models.login_history import LoginHistory
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...db.session import SessionLocal
|
||||
from ...models.auth import Permission, Role
|
||||
from ...models.permission import Permission
|
||||
from ...models.role import Role
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...db.session import SessionLocal
|
||||
from ...models.auth import Role, User
|
||||
from ...models.role import Role
|
||||
from ...models.user import User
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.voucher import Batch
|
||||
from ..models.batch import Batch
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import CostCentre
|
||||
from ..models.cost_centre import CostCentre
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -8,8 +8,13 @@ from sqlalchemy.orm import Session
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_first_day, get_last_day
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import Account, AttendanceType, Employee
|
||||
from ..models.voucher import Attendance, Journal, Voucher, VoucherType
|
||||
from ..models.account import Account
|
||||
from ..models.attendance import Attendance
|
||||
from ..models.attendance_type import AttendanceType
|
||||
from ..models.employee import Employee
|
||||
from ..models.journal import Journal
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from fastapi.responses import StreamingResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.voucher import DbImage
|
||||
from ..models.db_image import DbImage
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -4,7 +4,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models import Attendance
|
||||
from ..models.attendance import Attendance
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -12,8 +12,13 @@ from sqlalchemy.orm import Session, joinedload_all
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import Account, AccountBase, CostCentre, Employee
|
||||
from ..models.voucher import Journal, Voucher, VoucherType
|
||||
from ..models.account import Account
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.cost_centre import CostCentre
|
||||
from ..models.employee import Employee
|
||||
from ..models.journal import Journal
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ from sqlalchemy.orm import Session
|
||||
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 SessionLocal
|
||||
from ..models.master import Employee
|
||||
from ..models.voucher import Attendance
|
||||
from ..models.attendance import Attendance
|
||||
from ..models.employee import Employee
|
||||
from ..routers.fingerprint import get_prints
|
||||
from ..schemas.user import UserToken
|
||||
from .attendance import date_range
|
||||
|
||||
@@ -14,9 +14,13 @@ from sqlalchemy.orm import Session
|
||||
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 SessionLocal
|
||||
from ..models import AccountBase, Employee
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.employee import Employee
|
||||
from ..models.emplyee_benefit import EmployeeBenefit
|
||||
from ..models.journal import Journal
|
||||
from ..models.validations import check_journals_are_valid
|
||||
from ..models.voucher import EmployeeBenefit, Journal, Voucher, VoucherType
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
from .db_image import save_files, update_files
|
||||
from .voucher import (
|
||||
|
||||
@@ -12,8 +12,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import Employee
|
||||
from ..models.voucher import Fingerprint
|
||||
from ..models.employee import Employee
|
||||
from ..models.fingerprint import Fingerprint
|
||||
from ..routers import get_lock_info
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
@@ -15,9 +15,15 @@ from sqlalchemy.orm import Session
|
||||
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 SessionLocal
|
||||
from ..models import Account, AttendanceType, Employee
|
||||
from ..models.account import Account
|
||||
from ..models.attendance import Attendance
|
||||
from ..models.attendance_type import AttendanceType
|
||||
from ..models.employee import Employee
|
||||
from ..models.incentive import Incentive
|
||||
from ..models.journal import Journal
|
||||
from ..models.validations import check_journals_are_valid
|
||||
from ..models.voucher import Attendance, Incentive, Journal, Voucher, VoucherType
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
from .voucher import (
|
||||
blank_voucher,
|
||||
|
||||
@@ -14,9 +14,14 @@ from sqlalchemy.orm import Session
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionLocal
|
||||
from ..models import AccountBase, CostCentre
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.batch import Batch
|
||||
from ..models.cost_centre import CostCentre
|
||||
from ..models.inventory import Inventory
|
||||
from ..models.journal import Journal
|
||||
from ..models.validations import check_inventories_are_valid, check_journals_are_valid
|
||||
from ..models.voucher import Batch, Inventory, Journal, Voucher, VoucherType
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
from .db_image import save_files, update_files
|
||||
from .voucher import (
|
||||
|
||||
@@ -6,7 +6,9 @@ from sqlalchemy.orm.util import aliased
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.voucher import Journal, Voucher, VoucherType
|
||||
from ..models.journal import Journal
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -13,9 +13,11 @@ from sqlalchemy.orm import Session
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionLocal
|
||||
from ..models import AccountBase
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.journal import Journal
|
||||
from ..models.validations import check_journals_are_valid
|
||||
from ..models.voucher import Journal, Voucher, VoucherType
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
from .db_image import save_files, update_files
|
||||
from .voucher import (
|
||||
|
||||
@@ -3,7 +3,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import DbSetting
|
||||
from ..models.db_setting import DbSetting
|
||||
from ..schemas.settings import LockInformation
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ from ..core.security import (
|
||||
get_current_active_user,
|
||||
)
|
||||
from ..db.session import SessionLocal
|
||||
from ..models import Client, LoginHistory
|
||||
from ..models.client import Client
|
||||
from ..models.login_history import LoginHistory
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models import User
|
||||
from ..models.master import DbSetting
|
||||
from ..models.db_setting import DbSetting
|
||||
from ..models.user import User
|
||||
from ..schemas.settings import Maintenance
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
@@ -11,8 +11,12 @@ from sqlalchemy.orm import Session, joinedload_all
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import Account, Product
|
||||
from ..models.voucher import Batch, Inventory, Voucher, VoucherType
|
||||
from ..models.account import Account
|
||||
from ..models.batch import Batch
|
||||
from ..models.inventory import Inventory
|
||||
from ..models.product import Product
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import ProductGroup
|
||||
from ..models.product_group import ProductGroup
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -15,9 +15,14 @@ from sqlalchemy.orm import Session
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionLocal
|
||||
from ..models import AccountBase, Product
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.batch import Batch
|
||||
from ..models.inventory import Inventory
|
||||
from ..models.journal import Journal
|
||||
from ..models.product import Product
|
||||
from ..models.validations import check_inventories_are_valid, check_journals_are_valid
|
||||
from ..models.voucher import Batch, Inventory, Journal, Voucher, VoucherType
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
from .db_image import save_files, update_files
|
||||
from .voucher import (
|
||||
|
||||
@@ -14,9 +14,13 @@ from sqlalchemy.orm import Session
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_date, set_date
|
||||
from ..db.session import SessionLocal
|
||||
from ..models import AccountBase
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.batch import Batch
|
||||
from ..models.inventory import Inventory
|
||||
from ..models.journal import Journal
|
||||
from ..models.validations import check_inventories_are_valid, check_journals_are_valid
|
||||
from ..models.voucher import Batch, Inventory, Journal, Voucher, VoucherType
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
from .db_image import save_files, update_files
|
||||
from .voucher import (
|
||||
|
||||
@@ -10,9 +10,20 @@ from sqlalchemy.orm import Session, aliased, joinedload_all
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models import Batch, EmployeeBenefit, Inventory, Journal, Voucher, VoucherType
|
||||
from ..models.master import Account, AccountBase, CostCentre, Employee
|
||||
from ..models.voucher import Attendance, DbImage, Fingerprint, Incentive
|
||||
from ..models.account import Account
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.attendance import Attendance
|
||||
from ..models.batch import Batch
|
||||
from ..models.cost_centre import CostCentre
|
||||
from ..models.db_image import DbImage
|
||||
from ..models.employee import Employee
|
||||
from ..models.emplyee_benefit import EmployeeBenefit
|
||||
from ..models.fingerprint import Fingerprint
|
||||
from ..models.incentive import Incentive
|
||||
from ..models.inventory import Inventory
|
||||
from ..models.journal import Journal
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -4,12 +4,18 @@ import uuid
|
||||
|
||||
from decimal import Decimal, InvalidOperation
|
||||
|
||||
from brewman.models.master import CostCentre, Product, Recipe, RecipeItem
|
||||
from brewman.models.voucher import Inventory, Journal, Voucher, VoucherType
|
||||
from brewman.models.voucher import Voucher
|
||||
from fastapi import APIRouter
|
||||
from sqlalchemy import desc, func, or_
|
||||
|
||||
from ..core.session import get_finish_date, get_start_date, set_period
|
||||
from ..models.cost_centre import CostCentre
|
||||
from ..models.inventory import Inventory
|
||||
from ..models.journal import Journal
|
||||
from ..models.product import Product
|
||||
from ..models.recipe import Recipe
|
||||
from ..models.recipe_item import RecipeItem
|
||||
from ..models.voucher_type import VoucherType
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -10,8 +10,11 @@ from sqlalchemy.sql.expression import desc, func
|
||||
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 SessionLocal
|
||||
from ...models.master import AccountBase, AccountType
|
||||
from ...models.voucher import Journal, Voucher, VoucherType
|
||||
from ...models.account_base import AccountBase
|
||||
from ...models.account_type import AccountType
|
||||
from ...models.journal import Journal
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...routers.reports.closing_stock import get_closing_stock
|
||||
from ...routers.reports.profit_loss import get_accumulated_profit
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
@@ -10,8 +10,11 @@ from sqlalchemy.sql.expression import desc, func
|
||||
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 SessionLocal
|
||||
from ...models.master import AccountBase, AccountType
|
||||
from ...models.voucher import Journal, Voucher, VoucherType
|
||||
from ...models.account_base import AccountBase
|
||||
from ...models.account_type import AccountType
|
||||
from ...models.journal import Journal
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,11 @@ from sqlalchemy.sql.expression import func
|
||||
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 SessionLocal
|
||||
from ...models.master import CostCentre, Product
|
||||
from ...models.voucher import Inventory, Journal, Voucher
|
||||
from ...models.cost_centre import CostCentre
|
||||
from ...models.inventory import Inventory
|
||||
from ...models.journal import Journal
|
||||
from ...models.product import Product
|
||||
from ...models.voucher import Voucher
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@ from sqlalchemy.orm import Session, joinedload_all
|
||||
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 SessionLocal
|
||||
from ...models.voucher import Journal, Voucher, VoucherType
|
||||
from ...models.journal import Journal
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@ from sqlalchemy.sql.expression import func
|
||||
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 SessionLocal
|
||||
from ...models.master import AccountBase
|
||||
from ...models.voucher import Journal, Voucher, VoucherType
|
||||
from ...models.account_base import AccountBase
|
||||
from ...models.journal import Journal
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -10,8 +10,10 @@ from sqlalchemy.sql.expression import desc, func
|
||||
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 SessionLocal
|
||||
from ...models.master import AccountBase
|
||||
from ...models.voucher import Journal, Voucher, VoucherType
|
||||
from ...models.account_base import AccountBase
|
||||
from ...models.journal import Journal
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -13,8 +13,12 @@ from sqlalchemy.sql.expression import func
|
||||
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 SessionLocal
|
||||
from ...models.master import CostCentre, Product
|
||||
from ...models.voucher import Inventory, Journal, Voucher, VoucherType
|
||||
from ...models.cost_centre import CostCentre
|
||||
from ...models.inventory import Inventory
|
||||
from ...models.journal import Journal
|
||||
from ...models.product import Product
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,11 @@ from sqlalchemy.sql.expression import desc, func
|
||||
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 SessionLocal
|
||||
from ...models.master import AccountBase, AccountType
|
||||
from ...models.voucher import Journal, Voucher, VoucherType
|
||||
from ...models.account_base import AccountBase
|
||||
from ...models.account_type import AccountType
|
||||
from ...models.journal import Journal
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...routers.reports.closing_stock import get_closing_stock, get_opening_stock
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ from sqlalchemy.orm import Session
|
||||
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 SessionLocal
|
||||
from ...models.voucher import Voucher, VoucherType
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,12 @@ from sqlalchemy.sql.expression import desc, func
|
||||
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 SessionLocal
|
||||
from ...models.master import CostCentre, Product
|
||||
from ...models.voucher import Inventory, Journal, Voucher, VoucherType
|
||||
from ...models.cost_centre import CostCentre
|
||||
from ...models.inventory import Inventory
|
||||
from ...models.journal import Journal
|
||||
from ...models.product import Product
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -12,8 +12,13 @@ from sqlalchemy.sql.expression import case, func
|
||||
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 SessionLocal
|
||||
from ...models.master import AccountBase, CostCentre, Product, ProductGroup
|
||||
from ...models.voucher import Inventory, Journal, Voucher
|
||||
from ...models.account_base import AccountBase
|
||||
from ...models.cost_centre import CostCentre
|
||||
from ...models.inventory import Inventory
|
||||
from ...models.journal import Journal
|
||||
from ...models.product import Product
|
||||
from ...models.product_group import ProductGroup
|
||||
from ...models.voucher import Voucher
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ from sqlalchemy.sql.expression import and_, func, or_
|
||||
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 SessionLocal
|
||||
from ...models.master import AccountBase
|
||||
from ...models.voucher import Journal, Voucher, VoucherType
|
||||
from ...models.account_base import AccountBase
|
||||
from ...models.journal import Journal
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,12 @@ from sqlalchemy.sql.expression import func
|
||||
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 SessionLocal
|
||||
from ...models.master import CostCentre, Product
|
||||
from ...models.voucher import Inventory, Journal, Voucher, VoucherType
|
||||
from ...models.cost_centre import CostCentre
|
||||
from ...models.inventory import Inventory
|
||||
from ...models.journal import Journal
|
||||
from ...models.product import Product
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -10,8 +10,10 @@ from sqlalchemy.sql.expression import func
|
||||
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 SessionLocal
|
||||
from ...models.master import AccountBase
|
||||
from ...models.voucher import Journal, Voucher, VoucherType
|
||||
from ...models.account_base import AccountBase
|
||||
from ...models.journal import Journal
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ from sqlalchemy.orm import Session, joinedload_all
|
||||
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...db.session import SessionLocal
|
||||
from ...models.voucher import Journal, Voucher, VoucherType
|
||||
from ...models.journal import Journal
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.user import UserToken
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,14 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models import Batch, Inventory, Journal, Voucher, VoucherType
|
||||
from ..models.master import AccountBase, CostCentre, Product
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.batch import Batch
|
||||
from ..models.cost_centre import CostCentre
|
||||
from ..models.inventory import Inventory
|
||||
from ..models.journal import Journal
|
||||
from ..models.product import Product
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..schemas.settings import ResetStock
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
@@ -14,15 +14,17 @@ from sqlalchemy.orm import Session
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..core.session import get_first_day
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import Account, AccountBase, AttendanceType, CostCentre, Employee
|
||||
from ..models.voucher import (
|
||||
Attendance,
|
||||
DbImage,
|
||||
Inventory,
|
||||
Journal,
|
||||
Voucher,
|
||||
VoucherType,
|
||||
)
|
||||
from ..models.account import Account
|
||||
from ..models.account_base import AccountBase
|
||||
from ..models.attendance import Attendance
|
||||
from ..models.attendance_type import AttendanceType
|
||||
from ..models.cost_centre import CostCentre
|
||||
from ..models.db_image import DbImage
|
||||
from ..models.employee import Employee
|
||||
from ..models.inventory import Inventory
|
||||
from ..models.journal import Journal
|
||||
from ..models.voucher import Voucher
|
||||
from ..models.voucher_type import VoucherType
|
||||
from ..routers import get_lock_info
|
||||
from ..schemas.user import UserToken
|
||||
|
||||
|
||||
@@ -6,15 +6,15 @@ authors = ["tanshu <git@tanshu.com>"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.8"
|
||||
uvicorn = "^0.12.3"
|
||||
fastapi = "^0.61.2"
|
||||
uvicorn = {extras = ["standard"], version = "^0.13.3"}
|
||||
fastapi = "^0.63.0"
|
||||
python-jose = {extras = ["cryptography"], version = "^3.2.0"}
|
||||
passlib = {extras = ["bcrypt"], version = "^1.7.3"}
|
||||
psycopg2-binary = "^2.8.6"
|
||||
SQLAlchemy = "^1.3.19"
|
||||
SQLAlchemy = "^1.3.22"
|
||||
python-multipart = "^0.0.5"
|
||||
PyJWT = "^1.7.1"
|
||||
alembic = "^1.4.3"
|
||||
alembic = "^1.5.2"
|
||||
itsdangerous = "^1.1.0"
|
||||
python-dotenv = "^0.14.0"
|
||||
pydantic = {extras = ["dotenv"], version = "^1.7.3"}
|
||||
@@ -23,7 +23,8 @@ starlette = "^0.13.6"
|
||||
[tool.poetry.dev-dependencies]
|
||||
flake8 = "^3.8.4"
|
||||
black = "^20.8b1"
|
||||
isort = {extras = ["toml"], version = "^5.5.4"}
|
||||
isort = {extras = ["toml"], version = "^5.7.0"}
|
||||
pre-commit = "^2.9.3"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
|
||||
@@ -8,6 +8,9 @@ indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.ts]
|
||||
quote_type = single
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
+12
-13
@@ -16,19 +16,13 @@
|
||||
"createDefaultProgram": true
|
||||
},
|
||||
"extends": [
|
||||
"plugin:@angular-eslint/ng-cli-compat",
|
||||
"plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
|
||||
"plugin:@angular-eslint/recommended",
|
||||
"plugin:@angular-eslint/template/process-inline-templates"
|
||||
],
|
||||
"plugins": [
|
||||
"import"
|
||||
],
|
||||
"rules": {
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "element",
|
||||
"prefix": "app",
|
||||
"style": "kebab-case"
|
||||
}
|
||||
],
|
||||
"@angular-eslint/directive-selector": [
|
||||
"error",
|
||||
{
|
||||
@@ -37,6 +31,14 @@
|
||||
"style": "camelCase"
|
||||
}
|
||||
],
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "element",
|
||||
"prefix": "app",
|
||||
"style": "kebab-case"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/lines-between-class-members": [
|
||||
"error",
|
||||
"always",
|
||||
@@ -51,9 +53,6 @@
|
||||
"newlines-between": "always"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/naming-convention": [
|
||||
"off"
|
||||
],
|
||||
"@typescript-eslint/no-explicit-any": [
|
||||
"error"
|
||||
]
|
||||
|
||||
+33
-35
@@ -14,55 +14,53 @@
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^11.0.5",
|
||||
"@angular/cdk": "^11.0.3",
|
||||
"@angular/common": "^11.0.5",
|
||||
"@angular/compiler": "^11.0.5",
|
||||
"@angular/core": "^11.0.5",
|
||||
"@angular/animations": "^11.1.0",
|
||||
"@angular/cdk": "^11.1.0",
|
||||
"@angular/common": "^11.1.0",
|
||||
"@angular/compiler": "^11.1.0",
|
||||
"@angular/core": "^11.1.0",
|
||||
"@angular/flex-layout": "^11.0.0-beta.33",
|
||||
"@angular/forms": "^11.0.5",
|
||||
"@angular/material": "^11.0.3",
|
||||
"@angular/material-moment-adapter": "^11.0.3",
|
||||
"@angular/platform-browser": "^11.0.5",
|
||||
"@angular/platform-browser-dynamic": "^11.0.5",
|
||||
"@angular/router": "^11.0.5",
|
||||
"@angular/forms": "^11.1.0",
|
||||
"@angular/material": "^11.1.0",
|
||||
"@angular/material-moment-adapter": "^11.1.0",
|
||||
"@angular/platform-browser": "^11.1.0",
|
||||
"@angular/platform-browser-dynamic": "^11.1.0",
|
||||
"@angular/router": "^11.1.0",
|
||||
"@ngx-loading-bar/core": "^5.1.1",
|
||||
"@ngx-loading-bar/http-client": "^5.1.1",
|
||||
"@ngx-loading-bar/router": "^5.1.1",
|
||||
"@types/mousetrap": "1.6.3",
|
||||
"angular2-hotkeys": "^2.2.0",
|
||||
"core-js": "^3.8.1",
|
||||
"mathjs": "^8.1.0",
|
||||
"mathjs": "^9.0.0",
|
||||
"moment": "^2.29.1",
|
||||
"rxjs": "^6.6.3",
|
||||
"tslib": "^2.0.0",
|
||||
"tslib": "^2.1.0",
|
||||
"zone.js": "^0.11.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "~0.1100.5",
|
||||
"@angular-eslint/builder": "^0.8.0-beta.6",
|
||||
"@angular-eslint/eslint-plugin": "^0.8.0-beta.6",
|
||||
"@angular-eslint/eslint-plugin-template": "^0.8.0-beta.6",
|
||||
"@angular-eslint/schematics": "^0.8.0-beta.6",
|
||||
"@angular-eslint/template-parser": "^0.8.0-beta.6",
|
||||
"@angular/cli": "^11.0.5",
|
||||
"@angular/compiler-cli": "^11.0.5",
|
||||
"@angular/language-service": "^11.0.5",
|
||||
"@types/jasmine": "~3.6.2",
|
||||
"@angular-devkit/build-angular": "~0.1101.1",
|
||||
"@angular-eslint/builder": "^1.1.0",
|
||||
"@angular-eslint/eslint-plugin": "^1.1.0",
|
||||
"@angular-eslint/eslint-plugin-template": "^1.1.0",
|
||||
"@angular-eslint/schematics": "^1.1.0",
|
||||
"@angular-eslint/template-parser": "^1.1.0",
|
||||
"@angular/cli": "^11.1.1",
|
||||
"@angular/compiler-cli": "^11.1.0",
|
||||
"@angular/language-service": "^11.1.0",
|
||||
"@types/jasmine": "~3.6.3",
|
||||
"@types/jasminewd2": "^2.0.3",
|
||||
"@types/mathjs": "^6.0.9",
|
||||
"@types/node": "^14.14.14",
|
||||
"@typescript-eslint/eslint-plugin": "^4.10.0",
|
||||
"@typescript-eslint/parser": "^4.10.0",
|
||||
"eslint": "^7.15.0",
|
||||
"eslint-config-prettier": "^7.0.0",
|
||||
"@types/mathjs": "^6.0.11",
|
||||
"@types/node": "^14.14.22",
|
||||
"@typescript-eslint/eslint-plugin": "^4.14.0",
|
||||
"@typescript-eslint/parser": "^4.14.0",
|
||||
"eslint": "^7.18.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-jsdoc": "^30.7.8",
|
||||
"eslint-plugin-jsdoc": "^31.2.2",
|
||||
"eslint-plugin-prefer-arrow": "1.2.2",
|
||||
"husky": "^4.3.6",
|
||||
"husky": "^4.3.8",
|
||||
"jasmine-core": "~3.6.0",
|
||||
"jasmine-spec-reporter": "6.0.0",
|
||||
"karma": "^5.2.3",
|
||||
"karma": "^6.0.1",
|
||||
"karma-chrome-launcher": "~3.1.0",
|
||||
"karma-coverage-istanbul-reporter": "~3.0.2",
|
||||
"karma-jasmine": "~4.0.0",
|
||||
@@ -70,9 +68,9 @@
|
||||
"lint-staged": "^10.5.3",
|
||||
"prettier": "^2.2.1",
|
||||
"protractor": "~7.0.0",
|
||||
"standard-version": "^9.0.0",
|
||||
"standard-version": "^9.1.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "~4.0.5"
|
||||
"typescript": "^4.1.3"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
]
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
|
||||
Reference in new issue
Block a user