From d7f635b7b661d732b58c000977cf058483072c57 Mon Sep 17 00:00:00 2001 From: tanshu Date: Mon, 25 Jan 2021 12:44:17 +0530 Subject: [PATCH] Chore: Split models into their own files --- brewman/brewman/core/security.py | 4 +- brewman/brewman/db/base.py | 52 +- brewman/brewman/models/__init__.py | 31 - brewman/brewman/models/account.py | 10 + brewman/brewman/models/account_base.py | 137 +++++ brewman/brewman/models/account_type.py | 51 ++ brewman/brewman/models/attendance.py | 56 ++ brewman/brewman/models/attendance_type.py | 30 + brewman/brewman/models/auth.py | 170 ------ brewman/brewman/models/batch.py | 61 ++ brewman/brewman/models/client.py | 53 ++ brewman/brewman/models/cost_centre.py | 45 ++ brewman/brewman/models/db_image.py | 34 ++ brewman/brewman/models/db_setting.py | 19 + brewman/brewman/models/employee.py | 57 ++ brewman/brewman/models/emplyee_benefit.py | 53 ++ brewman/brewman/models/fingerprint.py | 19 + brewman/brewman/models/incentive.py | 41 ++ brewman/brewman/models/inventory.py | 61 ++ brewman/brewman/models/journal.py | 57 ++ brewman/brewman/models/login_history.py | 31 + brewman/brewman/models/master.py | 536 ------------------ brewman/brewman/models/permission.py | 26 + brewman/brewman/models/product.py | 116 ++++ brewman/brewman/models/product_group.py | 29 + brewman/brewman/models/recipe.py | 51 ++ brewman/brewman/models/recipe_item.py | 26 + brewman/brewman/models/role.py | 19 + brewman/brewman/models/role_permission.py | 18 + brewman/brewman/models/user.py | 62 ++ brewman/brewman/models/user_role.py | 18 + brewman/brewman/models/validations.py | 2 +- brewman/brewman/models/voucher.py | 383 +------------ brewman/brewman/models/voucher_type.py | 37 ++ brewman/brewman/routers/__init__.py | 2 +- brewman/brewman/routers/account.py | 9 +- brewman/brewman/routers/account_types.py | 2 +- brewman/brewman/routers/attendance.py | 4 +- brewman/brewman/routers/attendance_report.py | 5 +- brewman/brewman/routers/attendance_types.py | 2 +- brewman/brewman/routers/auth/client.py | 4 +- brewman/brewman/routers/auth/role.py | 3 +- brewman/brewman/routers/auth/user.py | 3 +- brewman/brewman/routers/batch.py | 2 +- brewman/brewman/routers/cost_centre.py | 2 +- brewman/brewman/routers/credit_salary.py | 9 +- brewman/brewman/routers/db_image.py | 2 +- brewman/brewman/routers/db_integrity.py | 2 +- brewman/brewman/routers/employee.py | 9 +- .../brewman/routers/employee_attendance.py | 4 +- brewman/brewman/routers/employee_benefit.py | 8 +- brewman/brewman/routers/fingerprint.py | 4 +- brewman/brewman/routers/incentive.py | 10 +- brewman/brewman/routers/issue.py | 9 +- brewman/brewman/routers/issue_grid.py | 4 +- brewman/brewman/routers/journal.py | 6 +- brewman/brewman/routers/lock_information.py | 2 +- brewman/brewman/routers/login.py | 3 +- brewman/brewman/routers/maintenance.py | 4 +- brewman/brewman/routers/product.py | 8 +- brewman/brewman/routers/product_group.py | 2 +- brewman/brewman/routers/purchase.py | 9 +- brewman/brewman/routers/purchase_return.py | 8 +- brewman/brewman/routers/rebase.py | 17 +- brewman/brewman/routers/recipe.py | 10 +- .../brewman/routers/reports/balance_sheet.py | 7 +- brewman/brewman/routers/reports/cash_flow.py | 7 +- .../brewman/routers/reports/closing_stock.py | 7 +- brewman/brewman/routers/reports/daybook.py | 4 +- brewman/brewman/routers/reports/ledger.py | 6 +- .../routers/reports/net_transactions.py | 6 +- .../brewman/routers/reports/product_ledger.py | 8 +- .../brewman/routers/reports/profit_loss.py | 7 +- .../routers/reports/purchase_entries.py | 3 +- brewman/brewman/routers/reports/purchases.py | 8 +- .../routers/reports/raw_material_cost.py | 9 +- brewman/brewman/routers/reports/reconcile.py | 6 +- .../brewman/routers/reports/stock_movement.py | 8 +- .../brewman/routers/reports/trial_balance.py | 6 +- brewman/brewman/routers/reports/unposted.py | 4 +- brewman/brewman/routers/reset_stock.py | 10 +- brewman/brewman/routers/voucher.py | 20 +- brewman/pyproject.toml | 11 +- overlord/.editorconfig | 3 + overlord/.eslintrc.json | 25 +- overlord/package.json | 68 ++- overlord/tsconfig.json | 1 + 87 files changed, 1509 insertions(+), 1288 deletions(-) create mode 100644 brewman/brewman/models/account.py create mode 100644 brewman/brewman/models/account_base.py create mode 100644 brewman/brewman/models/account_type.py create mode 100644 brewman/brewman/models/attendance.py create mode 100644 brewman/brewman/models/attendance_type.py delete mode 100644 brewman/brewman/models/auth.py create mode 100644 brewman/brewman/models/batch.py create mode 100644 brewman/brewman/models/client.py create mode 100644 brewman/brewman/models/cost_centre.py create mode 100644 brewman/brewman/models/db_image.py create mode 100644 brewman/brewman/models/db_setting.py create mode 100644 brewman/brewman/models/employee.py create mode 100644 brewman/brewman/models/emplyee_benefit.py create mode 100644 brewman/brewman/models/fingerprint.py create mode 100644 brewman/brewman/models/incentive.py create mode 100644 brewman/brewman/models/inventory.py create mode 100644 brewman/brewman/models/journal.py create mode 100644 brewman/brewman/models/login_history.py delete mode 100644 brewman/brewman/models/master.py create mode 100644 brewman/brewman/models/permission.py create mode 100644 brewman/brewman/models/product.py create mode 100644 brewman/brewman/models/product_group.py create mode 100644 brewman/brewman/models/recipe.py create mode 100644 brewman/brewman/models/recipe_item.py create mode 100644 brewman/brewman/models/role.py create mode 100644 brewman/brewman/models/role_permission.py create mode 100644 brewman/brewman/models/user.py create mode 100644 brewman/brewman/models/user_role.py create mode 100644 brewman/brewman/models/voucher_type.py diff --git a/brewman/brewman/core/security.py b/brewman/brewman/core/security.py index fc846dad..47947ae7 100644 --- a/brewman/brewman/core/security.py +++ b/brewman/brewman/core/security.py @@ -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 diff --git a/brewman/brewman/db/base.py b/brewman/brewman/db/base.py index 4df5f1f5..a701546a 100644 --- a/brewman/brewman/db/base.py +++ b/brewman/brewman/db/base.py @@ -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 diff --git a/brewman/brewman/models/__init__.py b/brewman/brewman/models/__init__.py index 746ad16f..e69de29b 100644 --- a/brewman/brewman/models/__init__.py +++ b/brewman/brewman/models/__init__.py @@ -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, -) diff --git a/brewman/brewman/models/account.py b/brewman/brewman/models/account.py new file mode 100644 index 00000000..2e64e46f --- /dev/null +++ b/brewman/brewman/models/account.py @@ -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) diff --git a/brewman/brewman/models/account_base.py b/brewman/brewman/models/account_base.py new file mode 100644 index 00000000..35967c98 --- /dev/null +++ b/brewman/brewman/models/account_base.py @@ -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") diff --git a/brewman/brewman/models/account_type.py b/brewman/brewman/models/account_type.py new file mode 100644 index 00000000..5ebd5dd2 --- /dev/null +++ b/brewman/brewman/models/account_type.py @@ -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_) diff --git a/brewman/brewman/models/attendance.py b/brewman/brewman/models/attendance.py new file mode 100644 index 00000000..2181c568 --- /dev/null +++ b/brewman/brewman/models/attendance.py @@ -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) diff --git a/brewman/brewman/models/attendance_type.py b/brewman/brewman/models/attendance_type.py new file mode 100644 index 00000000..aa4beec5 --- /dev/null +++ b/brewman/brewman/models/attendance_type.py @@ -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_) diff --git a/brewman/brewman/models/auth.py b/brewman/brewman/models/auth.py deleted file mode 100644 index cc21745e..00000000 --- a/brewman/brewman/models/auth.py +++ /dev/null @@ -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_ diff --git a/brewman/brewman/models/batch.py b/brewman/brewman/models/batch.py new file mode 100644 index 00000000..8d5bd8e1 --- /dev/null +++ b/brewman/brewman/models/batch.py @@ -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") diff --git a/brewman/brewman/models/client.py b/brewman/brewman/models/client.py new file mode 100644 index 00000000..5a80deb3 --- /dev/null +++ b/brewman/brewman/models/client.py @@ -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 diff --git a/brewman/brewman/models/cost_centre.py b/brewman/brewman/models/cost_centre.py new file mode 100644 index 00000000..7f3ebf1f --- /dev/null +++ b/brewman/brewman/models/cost_centre.py @@ -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", + } diff --git a/brewman/brewman/models/db_image.py b/brewman/brewman/models/db_image.py new file mode 100644 index 00000000..b43c6cb0 --- /dev/null +++ b/brewman/brewman/models/db_image.py @@ -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_ diff --git a/brewman/brewman/models/db_setting.py b/brewman/brewman/models/db_setting.py new file mode 100644 index 00000000..80aa7f3e --- /dev/null +++ b/brewman/brewman/models/db_setting.py @@ -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 diff --git a/brewman/brewman/models/employee.py b/brewman/brewman/models/employee.py new file mode 100644 index 00000000..5cdc821a --- /dev/null +++ b/brewman/brewman/models/employee.py @@ -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) diff --git a/brewman/brewman/models/emplyee_benefit.py b/brewman/brewman/models/emplyee_benefit.py new file mode 100644 index 00000000..d05dcc0d --- /dev/null +++ b/brewman/brewman/models/emplyee_benefit.py @@ -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 diff --git a/brewman/brewman/models/fingerprint.py b/brewman/brewman/models/fingerprint.py new file mode 100644 index 00000000..b9f0e020 --- /dev/null +++ b/brewman/brewman/models/fingerprint.py @@ -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 diff --git a/brewman/brewman/models/incentive.py b/brewman/brewman/models/incentive.py new file mode 100644 index 00000000..03869fd7 --- /dev/null +++ b/brewman/brewman/models/incentive.py @@ -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 diff --git a/brewman/brewman/models/inventory.py b/brewman/brewman/models/inventory.py new file mode 100644 index 00000000..97ed2d15 --- /dev/null +++ b/brewman/brewman/models/inventory.py @@ -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) diff --git a/brewman/brewman/models/journal.py b/brewman/brewman/models/journal.py new file mode 100644 index 00000000..7a90e9b8 --- /dev/null +++ b/brewman/brewman/models/journal.py @@ -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 diff --git a/brewman/brewman/models/login_history.py b/brewman/brewman/models/login_history.py new file mode 100644 index 00000000..5c391ef8 --- /dev/null +++ b/brewman/brewman/models/login_history.py @@ -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_ diff --git a/brewman/brewman/models/master.py b/brewman/brewman/models/master.py deleted file mode 100644 index b47b09d8..00000000 --- a/brewman/brewman/models/master.py +++ /dev/null @@ -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 diff --git a/brewman/brewman/models/permission.py b/brewman/brewman/models/permission.py new file mode 100644 index 00000000..5b8d78db --- /dev/null +++ b/brewman/brewman/models/permission.py @@ -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_ diff --git a/brewman/brewman/models/product.py b/brewman/brewman/models/product.py new file mode 100644 index 00000000..9eb918dd --- /dev/null +++ b/brewman/brewman/models/product.py @@ -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") diff --git a/brewman/brewman/models/product_group.py b/brewman/brewman/models/product_group.py new file mode 100644 index 00000000..5b4080d0 --- /dev/null +++ b/brewman/brewman/models/product_group.py @@ -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") diff --git a/brewman/brewman/models/recipe.py b/brewman/brewman/models/recipe.py new file mode 100644 index 00000000..f12fbd77 --- /dev/null +++ b/brewman/brewman/models/recipe.py @@ -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_ diff --git a/brewman/brewman/models/recipe_item.py b/brewman/brewman/models/recipe_item.py new file mode 100644 index 00000000..de270808 --- /dev/null +++ b/brewman/brewman/models/recipe_item.py @@ -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_ diff --git a/brewman/brewman/models/role.py b/brewman/brewman/models/role.py new file mode 100644 index 00000000..2f99e7b0 --- /dev/null +++ b/brewman/brewman/models/role.py @@ -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_ diff --git a/brewman/brewman/models/role_permission.py b/brewman/brewman/models/role_permission.py new file mode 100644 index 00000000..678fd6fb --- /dev/null +++ b/brewman/brewman/models/role_permission.py @@ -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")), +) diff --git a/brewman/brewman/models/user.py b/brewman/brewman/models/user.py new file mode 100644 index 00000000..1cb5ae02 --- /dev/null +++ b/brewman/brewman/models/user.py @@ -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 diff --git a/brewman/brewman/models/user_role.py b/brewman/brewman/models/user_role.py new file mode 100644 index 00000000..540a6413 --- /dev/null +++ b/brewman/brewman/models/user_role.py @@ -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")), +) diff --git a/brewman/brewman/models/validations.py b/brewman/brewman/models/validations.py index 13915fda..936699c6 100644 --- a/brewman/brewman/models/validations.py +++ b/brewman/brewman/models/validations.py @@ -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 diff --git a/brewman/brewman/models/voucher.py b/brewman/brewman/models/voucher.py index f0d90a86..ad7a4182 100644 --- a/brewman/brewman/models/voucher.py +++ b/brewman/brewman/models/voucher.py @@ -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_ diff --git a/brewman/brewman/models/voucher_type.py b/brewman/brewman/models/voucher_type.py new file mode 100644 index 00000000..a24141e4 --- /dev/null +++ b/brewman/brewman/models/voucher_type.py @@ -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 diff --git a/brewman/brewman/routers/__init__.py b/brewman/brewman/routers/__init__.py index 4ae5d60b..a793c724 100644 --- a/brewman/brewman/routers/__init__.py +++ b/brewman/brewman/routers/__init__.py @@ -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]): diff --git a/brewman/brewman/routers/account.py b/brewman/brewman/routers/account.py index 57af26ee..af98a92d 100644 --- a/brewman/brewman/routers/account.py +++ b/brewman/brewman/routers/account.py @@ -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 diff --git a/brewman/brewman/routers/account_types.py b/brewman/brewman/routers/account_types.py index 08d69f77..37bb5245 100644 --- a/brewman/brewman/routers/account_types.py +++ b/brewman/brewman/routers/account_types.py @@ -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 diff --git a/brewman/brewman/routers/attendance.py b/brewman/brewman/routers/attendance.py index 0ed19048..2f47ac75 100644 --- a/brewman/brewman/routers/attendance.py +++ b/brewman/brewman/routers/attendance.py @@ -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 diff --git a/brewman/brewman/routers/attendance_report.py b/brewman/brewman/routers/attendance_report.py index dd55f585..70f6cac4 100644 --- a/brewman/brewman/routers/attendance_report.py +++ b/brewman/brewman/routers/attendance_report.py @@ -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 diff --git a/brewman/brewman/routers/attendance_types.py b/brewman/brewman/routers/attendance_types.py index d76dfcc1..8596f784 100644 --- a/brewman/brewman/routers/attendance_types.py +++ b/brewman/brewman/routers/attendance_types.py @@ -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 diff --git a/brewman/brewman/routers/auth/client.py b/brewman/brewman/routers/auth/client.py index ce4012b1..00db0d50 100644 --- a/brewman/brewman/routers/auth/client.py +++ b/brewman/brewman/routers/auth/client.py @@ -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 diff --git a/brewman/brewman/routers/auth/role.py b/brewman/brewman/routers/auth/role.py index 20038ba8..3147ef38 100644 --- a/brewman/brewman/routers/auth/role.py +++ b/brewman/brewman/routers/auth/role.py @@ -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 diff --git a/brewman/brewman/routers/auth/user.py b/brewman/brewman/routers/auth/user.py index f9bcead5..d9185707 100644 --- a/brewman/brewman/routers/auth/user.py +++ b/brewman/brewman/routers/auth/user.py @@ -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 diff --git a/brewman/brewman/routers/batch.py b/brewman/brewman/routers/batch.py index 9e89b4c6..76b7b525 100644 --- a/brewman/brewman/routers/batch.py +++ b/brewman/brewman/routers/batch.py @@ -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 diff --git a/brewman/brewman/routers/cost_centre.py b/brewman/brewman/routers/cost_centre.py index 7ee712be..54a5b33a 100644 --- a/brewman/brewman/routers/cost_centre.py +++ b/brewman/brewman/routers/cost_centre.py @@ -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 diff --git a/brewman/brewman/routers/credit_salary.py b/brewman/brewman/routers/credit_salary.py index c48fcdd0..72cbf377 100644 --- a/brewman/brewman/routers/credit_salary.py +++ b/brewman/brewman/routers/credit_salary.py @@ -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 diff --git a/brewman/brewman/routers/db_image.py b/brewman/brewman/routers/db_image.py index 1f155f0b..8105db01 100644 --- a/brewman/brewman/routers/db_image.py +++ b/brewman/brewman/routers/db_image.py @@ -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() diff --git a/brewman/brewman/routers/db_integrity.py b/brewman/brewman/routers/db_integrity.py index 9b4420d2..e8005eb0 100644 --- a/brewman/brewman/routers/db_integrity.py +++ b/brewman/brewman/routers/db_integrity.py @@ -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 diff --git a/brewman/brewman/routers/employee.py b/brewman/brewman/routers/employee.py index 5b2cbe7d..6b726245 100644 --- a/brewman/brewman/routers/employee.py +++ b/brewman/brewman/routers/employee.py @@ -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 diff --git a/brewman/brewman/routers/employee_attendance.py b/brewman/brewman/routers/employee_attendance.py index 4e16d9f9..443ce7f4 100644 --- a/brewman/brewman/routers/employee_attendance.py +++ b/brewman/brewman/routers/employee_attendance.py @@ -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 diff --git a/brewman/brewman/routers/employee_benefit.py b/brewman/brewman/routers/employee_benefit.py index 1d808130..894ee133 100644 --- a/brewman/brewman/routers/employee_benefit.py +++ b/brewman/brewman/routers/employee_benefit.py @@ -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 ( diff --git a/brewman/brewman/routers/fingerprint.py b/brewman/brewman/routers/fingerprint.py index 9a429394..459f3dfa 100644 --- a/brewman/brewman/routers/fingerprint.py +++ b/brewman/brewman/routers/fingerprint.py @@ -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 diff --git a/brewman/brewman/routers/incentive.py b/brewman/brewman/routers/incentive.py index 4b0b2414..475a51b0 100644 --- a/brewman/brewman/routers/incentive.py +++ b/brewman/brewman/routers/incentive.py @@ -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, diff --git a/brewman/brewman/routers/issue.py b/brewman/brewman/routers/issue.py index 52a67b08..8f7800ca 100644 --- a/brewman/brewman/routers/issue.py +++ b/brewman/brewman/routers/issue.py @@ -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 ( diff --git a/brewman/brewman/routers/issue_grid.py b/brewman/brewman/routers/issue_grid.py index a56446dd..6fb56ac6 100644 --- a/brewman/brewman/routers/issue_grid.py +++ b/brewman/brewman/routers/issue_grid.py @@ -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 diff --git a/brewman/brewman/routers/journal.py b/brewman/brewman/routers/journal.py index 5c4c97b6..1a8db331 100644 --- a/brewman/brewman/routers/journal.py +++ b/brewman/brewman/routers/journal.py @@ -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 ( diff --git a/brewman/brewman/routers/lock_information.py b/brewman/brewman/routers/lock_information.py index 687e7be5..c29cd7cc 100644 --- a/brewman/brewman/routers/lock_information.py +++ b/brewman/brewman/routers/lock_information.py @@ -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 diff --git a/brewman/brewman/routers/login.py b/brewman/brewman/routers/login.py index a2803e3a..1b2f354b 100644 --- a/brewman/brewman/routers/login.py +++ b/brewman/brewman/routers/login.py @@ -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 diff --git a/brewman/brewman/routers/maintenance.py b/brewman/brewman/routers/maintenance.py index 7665b804..1647c1d0 100644 --- a/brewman/brewman/routers/maintenance.py +++ b/brewman/brewman/routers/maintenance.py @@ -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 diff --git a/brewman/brewman/routers/product.py b/brewman/brewman/routers/product.py index 1525fc8d..2c8e092d 100644 --- a/brewman/brewman/routers/product.py +++ b/brewman/brewman/routers/product.py @@ -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 diff --git a/brewman/brewman/routers/product_group.py b/brewman/brewman/routers/product_group.py index 3ed0c3df..077bda26 100644 --- a/brewman/brewman/routers/product_group.py +++ b/brewman/brewman/routers/product_group.py @@ -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 diff --git a/brewman/brewman/routers/purchase.py b/brewman/brewman/routers/purchase.py index 5a0bc659..5103410f 100644 --- a/brewman/brewman/routers/purchase.py +++ b/brewman/brewman/routers/purchase.py @@ -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 ( diff --git a/brewman/brewman/routers/purchase_return.py b/brewman/brewman/routers/purchase_return.py index 10af6345..766d3598 100644 --- a/brewman/brewman/routers/purchase_return.py +++ b/brewman/brewman/routers/purchase_return.py @@ -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 ( diff --git a/brewman/brewman/routers/rebase.py b/brewman/brewman/routers/rebase.py index a8f06e72..1bb202e8 100644 --- a/brewman/brewman/routers/rebase.py +++ b/brewman/brewman/routers/rebase.py @@ -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 diff --git a/brewman/brewman/routers/recipe.py b/brewman/brewman/routers/recipe.py index 4063da9a..16b54ed9 100644 --- a/brewman/brewman/routers/recipe.py +++ b/brewman/brewman/routers/recipe.py @@ -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() diff --git a/brewman/brewman/routers/reports/balance_sheet.py b/brewman/brewman/routers/reports/balance_sheet.py index 04b67859..d8f749cd 100644 --- a/brewman/brewman/routers/reports/balance_sheet.py +++ b/brewman/brewman/routers/reports/balance_sheet.py @@ -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 diff --git a/brewman/brewman/routers/reports/cash_flow.py b/brewman/brewman/routers/reports/cash_flow.py index b7e8db87..557514b1 100644 --- a/brewman/brewman/routers/reports/cash_flow.py +++ b/brewman/brewman/routers/reports/cash_flow.py @@ -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 diff --git a/brewman/brewman/routers/reports/closing_stock.py b/brewman/brewman/routers/reports/closing_stock.py index 56f72593..2e9246ee 100644 --- a/brewman/brewman/routers/reports/closing_stock.py +++ b/brewman/brewman/routers/reports/closing_stock.py @@ -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 diff --git a/brewman/brewman/routers/reports/daybook.py b/brewman/brewman/routers/reports/daybook.py index 2f57fb3d..feaf96ea 100644 --- a/brewman/brewman/routers/reports/daybook.py +++ b/brewman/brewman/routers/reports/daybook.py @@ -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 diff --git a/brewman/brewman/routers/reports/ledger.py b/brewman/brewman/routers/reports/ledger.py index fe9e7202..2a9eba01 100644 --- a/brewman/brewman/routers/reports/ledger.py +++ b/brewman/brewman/routers/reports/ledger.py @@ -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 diff --git a/brewman/brewman/routers/reports/net_transactions.py b/brewman/brewman/routers/reports/net_transactions.py index 6d1001f9..a0c4ae0a 100644 --- a/brewman/brewman/routers/reports/net_transactions.py +++ b/brewman/brewman/routers/reports/net_transactions.py @@ -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 diff --git a/brewman/brewman/routers/reports/product_ledger.py b/brewman/brewman/routers/reports/product_ledger.py index 939fcc6a..732db778 100644 --- a/brewman/brewman/routers/reports/product_ledger.py +++ b/brewman/brewman/routers/reports/product_ledger.py @@ -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 diff --git a/brewman/brewman/routers/reports/profit_loss.py b/brewman/brewman/routers/reports/profit_loss.py index 891fecdd..c1d355f8 100644 --- a/brewman/brewman/routers/reports/profit_loss.py +++ b/brewman/brewman/routers/reports/profit_loss.py @@ -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 diff --git a/brewman/brewman/routers/reports/purchase_entries.py b/brewman/brewman/routers/reports/purchase_entries.py index 66d0d6a4..150fe6cc 100644 --- a/brewman/brewman/routers/reports/purchase_entries.py +++ b/brewman/brewman/routers/reports/purchase_entries.py @@ -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 diff --git a/brewman/brewman/routers/reports/purchases.py b/brewman/brewman/routers/reports/purchases.py index 91e0c081..773f23cf 100644 --- a/brewman/brewman/routers/reports/purchases.py +++ b/brewman/brewman/routers/reports/purchases.py @@ -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 diff --git a/brewman/brewman/routers/reports/raw_material_cost.py b/brewman/brewman/routers/reports/raw_material_cost.py index e914e8e9..72f196ed 100644 --- a/brewman/brewman/routers/reports/raw_material_cost.py +++ b/brewman/brewman/routers/reports/raw_material_cost.py @@ -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 diff --git a/brewman/brewman/routers/reports/reconcile.py b/brewman/brewman/routers/reports/reconcile.py index aedc338d..705a1fa1 100644 --- a/brewman/brewman/routers/reports/reconcile.py +++ b/brewman/brewman/routers/reports/reconcile.py @@ -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 diff --git a/brewman/brewman/routers/reports/stock_movement.py b/brewman/brewman/routers/reports/stock_movement.py index 25991525..5cc50de9 100644 --- a/brewman/brewman/routers/reports/stock_movement.py +++ b/brewman/brewman/routers/reports/stock_movement.py @@ -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 diff --git a/brewman/brewman/routers/reports/trial_balance.py b/brewman/brewman/routers/reports/trial_balance.py index 6210f880..cd75f208 100644 --- a/brewman/brewman/routers/reports/trial_balance.py +++ b/brewman/brewman/routers/reports/trial_balance.py @@ -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 diff --git a/brewman/brewman/routers/reports/unposted.py b/brewman/brewman/routers/reports/unposted.py index 40c8ae59..9c85db80 100644 --- a/brewman/brewman/routers/reports/unposted.py +++ b/brewman/brewman/routers/reports/unposted.py @@ -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 diff --git a/brewman/brewman/routers/reset_stock.py b/brewman/brewman/routers/reset_stock.py index b4658bf6..016705bf 100644 --- a/brewman/brewman/routers/reset_stock.py +++ b/brewman/brewman/routers/reset_stock.py @@ -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 diff --git a/brewman/brewman/routers/voucher.py b/brewman/brewman/routers/voucher.py index 6ef4bfde..ffecf39c 100644 --- a/brewman/brewman/routers/voucher.py +++ b/brewman/brewman/routers/voucher.py @@ -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 diff --git a/brewman/pyproject.toml b/brewman/pyproject.toml index 9c21a6c2..f0f5a935 100644 --- a/brewman/pyproject.toml +++ b/brewman/pyproject.toml @@ -6,15 +6,15 @@ authors = ["tanshu "] [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"] diff --git a/overlord/.editorconfig b/overlord/.editorconfig index e89330a6..59d9a3a3 100644 --- a/overlord/.editorconfig +++ b/overlord/.editorconfig @@ -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 diff --git a/overlord/.eslintrc.json b/overlord/.eslintrc.json index 2251fbc2..354a261b 100644 --- a/overlord/.eslintrc.json +++ b/overlord/.eslintrc.json @@ -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" ] diff --git a/overlord/package.json b/overlord/package.json index 97c72d95..4a14bfab 100644 --- a/overlord/package.json +++ b/overlord/package.json @@ -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": { diff --git a/overlord/tsconfig.json b/overlord/tsconfig.json index 15618309..3240f7ae 100644 --- a/overlord/tsconfig.json +++ b/overlord/tsconfig.json @@ -22,6 +22,7 @@ ] }, "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, "strictInjectionParameters": true, "strictInputAccessModifiers": true, "strictTemplates": true