From 789722c0a9f992d21e51fb157ee8bda5dfbdc61c Mon Sep 17 00:00:00 2001 From: tanshu Date: Tue, 12 Jan 2021 10:49:38 +0530 Subject: [PATCH] Chore: Update dependencies Chore: Lint Chore: Remove old useless files Feature: Add more fields to case detail --- luthor/luthor/__version__.py | 2 +- luthor/luthor/core/session.py | 40 --- luthor/luthor/db/base.py | 38 +-- luthor/luthor/db/init_db.py | 217 ------------ luthor/luthor/models/case_source.py | 2 +- luthor/luthor/models/court_status.py | 4 +- luthor/luthor/models/department.py | 22 +- luthor/luthor/routers/menu_category.py | 195 ----------- luthor/luthor/routers/modifier.py | 149 --------- luthor/luthor/routers/modifier_category.py | 311 ------------------ luthor/luthor/routers/sale_category.py | 140 -------- luthor/luthor/routers/section_printer.py | 156 --------- .../luthor/routers/update_product_prices.py | 182 ---------- luthor/luthor/routers/voucher/__init__.py | 155 --------- luthor/luthor/routers/voucher/change.py | 99 ------ luthor/luthor/routers/voucher/merge_move.py | 177 ---------- .../luthor/routers/voucher/receive_payment.py | 67 ---- luthor/luthor/routers/voucher/save.py | 179 ---------- luthor/luthor/routers/voucher/show.py | 207 ------------ luthor/luthor/routers/voucher/split.py | 204 ------------ luthor/luthor/routers/voucher/update.py | 190 ----------- luthor/luthor/routers/voucher/void.py | 55 ---- luthor/luthor/schemas/discount_report.py | 39 --- luthor/luthor/schemas/guest_book.py | 79 ----- luthor/luthor/schemas/header_footer.py | 14 - luthor/luthor/schemas/login_history.py | 17 - luthor/luthor/schemas/master.py | 78 ----- luthor/luthor/schemas/menu_category.py | 44 --- luthor/luthor/schemas/merge_move.py | 45 --- luthor/luthor/schemas/modifier.py | 44 --- luthor/luthor/schemas/modifier_category.py | 46 --- luthor/luthor/schemas/printer.py | 41 --- luthor/luthor/schemas/product.py | 45 --- luthor/luthor/schemas/product_link.py | 14 - luthor/luthor/schemas/receive_payment.py | 23 -- luthor/luthor/schemas/sale_category.py | 53 --- luthor/luthor/schemas/sale_report.py | 41 --- luthor/luthor/schemas/section.py | 35 -- luthor/luthor/schemas/section_printer.py | 16 - luthor/luthor/schemas/split.py | 16 - luthor/luthor/schemas/table.py | 44 --- luthor/luthor/schemas/tax.py | 43 --- luthor/luthor/schemas/tax_report.py | 41 --- .../luthor/schemas/update_product_prices.py | 35 -- luthor/luthor/schemas/voucher.py | 68 ---- otis/package.json | 51 ++- .../case-detail/case-detail.component.html | 129 +++++++- .../case-detail/case-detail.component.ts | 23 +- otis/src/app/cases/cases-routing.module.ts | 22 ++ .../contact-detail.component.html | 8 - otis/src/environments/environment.prod.ts | 2 +- otis/src/environments/environment.ts | 2 +- 52 files changed, 210 insertions(+), 3739 deletions(-) delete mode 100644 luthor/luthor/core/session.py delete mode 100644 luthor/luthor/db/init_db.py delete mode 100644 luthor/luthor/routers/menu_category.py delete mode 100644 luthor/luthor/routers/modifier.py delete mode 100644 luthor/luthor/routers/modifier_category.py delete mode 100644 luthor/luthor/routers/sale_category.py delete mode 100644 luthor/luthor/routers/section_printer.py delete mode 100644 luthor/luthor/routers/update_product_prices.py delete mode 100644 luthor/luthor/routers/voucher/__init__.py delete mode 100644 luthor/luthor/routers/voucher/change.py delete mode 100644 luthor/luthor/routers/voucher/merge_move.py delete mode 100644 luthor/luthor/routers/voucher/receive_payment.py delete mode 100644 luthor/luthor/routers/voucher/save.py delete mode 100644 luthor/luthor/routers/voucher/show.py delete mode 100644 luthor/luthor/routers/voucher/split.py delete mode 100644 luthor/luthor/routers/voucher/update.py delete mode 100644 luthor/luthor/routers/voucher/void.py delete mode 100644 luthor/luthor/schemas/discount_report.py delete mode 100644 luthor/luthor/schemas/guest_book.py delete mode 100644 luthor/luthor/schemas/header_footer.py delete mode 100644 luthor/luthor/schemas/login_history.py delete mode 100644 luthor/luthor/schemas/master.py delete mode 100644 luthor/luthor/schemas/menu_category.py delete mode 100644 luthor/luthor/schemas/merge_move.py delete mode 100644 luthor/luthor/schemas/modifier.py delete mode 100644 luthor/luthor/schemas/modifier_category.py delete mode 100644 luthor/luthor/schemas/printer.py delete mode 100644 luthor/luthor/schemas/product.py delete mode 100644 luthor/luthor/schemas/product_link.py delete mode 100644 luthor/luthor/schemas/receive_payment.py delete mode 100644 luthor/luthor/schemas/sale_category.py delete mode 100644 luthor/luthor/schemas/sale_report.py delete mode 100644 luthor/luthor/schemas/section.py delete mode 100644 luthor/luthor/schemas/section_printer.py delete mode 100644 luthor/luthor/schemas/split.py delete mode 100644 luthor/luthor/schemas/table.py delete mode 100644 luthor/luthor/schemas/tax.py delete mode 100644 luthor/luthor/schemas/tax_report.py delete mode 100644 luthor/luthor/schemas/update_product_prices.py delete mode 100644 luthor/luthor/schemas/voucher.py diff --git a/luthor/luthor/__version__.py b/luthor/luthor/__version__.py index 833eacf..5becc17 100644 --- a/luthor/luthor/__version__.py +++ b/luthor/luthor/__version__.py @@ -1 +1 @@ -__version__ = "6.3.0" +__version__ = "1.0.0" diff --git a/luthor/luthor/core/session.py b/luthor/luthor/core/session.py deleted file mode 100644 index 13abcd8..0000000 --- a/luthor/luthor/core/session.py +++ /dev/null @@ -1,40 +0,0 @@ -from datetime import date, timedelta - - -def get_date(session) -> str: - if "date" not in session: - session["date"] = date.today().strftime("%d-%b-%Y") - return session["date"] - - -def set_date(date_, session): - session["date"] = date_ - return session["date"] - - -def get_start_date(session): - if "start" not in session: - session["start"] = get_first_day(date.today()).strftime("%d-%b-%Y") - return session["start"] - - -def get_finish_date(session): - if "finish" not in session: - session["finish"] = get_last_day(date.today()).strftime("%d-%b-%Y") - return session["finish"] - - -def set_period(start, finish, session): - session["start"] = start if isinstance(start, str) else start.strftime("%d-%b-%Y") - session["finish"] = finish if isinstance(finish, str) else finish.strftime("%d-%b-%Y") - - -def get_first_day(dt, d_years=0, d_months=0): - # d_years, d_months are "deltas" to apply to dt - y, m = dt.year + d_years, dt.month + d_months - a, m = divmod(m - 1, 12) - return date(y + a, m + 1, 1) - - -def get_last_day(dt): - return get_first_day(dt, 0, 1) + timedelta(-1) diff --git a/luthor/luthor/db/base.py b/luthor/luthor/db/base.py index 13395a9..fa8ae10 100644 --- a/luthor/luthor/db/base.py +++ b/luthor/luthor/db/base.py @@ -1,21 +1,21 @@ # Import all the models, so that Base has them before being # imported by Alembic -from luthor.db.base_class import Base # noqa -from luthor.models.act import Act # noqa -from luthor.models.advocate import Advocate # noqa -from luthor.models.case import Case # noqa -from luthor.models.case_source import CaseSource # noqa -from luthor.models.case_type import CaseType # noqa -from luthor.models.contact import Contact # noqa -from luthor.models.court import Court # noqa -from luthor.models.court_status import CourtStatus # noqa -from luthor.models.department import Department # noqa -from luthor.models.hearing import Hearing # noqa -from luthor.models.nature import Nature # noqa -from luthor.models.office import Office # noqa -from luthor.models.office_status import OfficeStatus # noqa -from luthor.models.permission import Permission # noqa -from luthor.models.role import Role # noqa -from luthor.models.role_permission import role_permissions # noqa -from luthor.models.user import User # noqa -from luthor.models.user_role import user_roles # noqa +from luthor.db.base_class import Base # noqa: F401 +from luthor.models.act import Act # noqa: F401 +from luthor.models.advocate import Advocate # noqa: F401 +from luthor.models.case import Case # noqa: F401 +from luthor.models.case_source import CaseSource # noqa: F401 +from luthor.models.case_type import CaseType # noqa: F401 +from luthor.models.contact import Contact # noqa: F401 +from luthor.models.court import Court # noqa: F401 +from luthor.models.court_status import CourtStatus # noqa: F401 +from luthor.models.department import Department # noqa: F401 +from luthor.models.hearing import Hearing # noqa: F401 +from luthor.models.nature import Nature # noqa: F401 +from luthor.models.office import Office # noqa: F401 +from luthor.models.office_status import OfficeStatus # noqa: F401 +from luthor.models.permission import Permission # noqa: F401 +from luthor.models.role import Role # noqa: F401 +from luthor.models.role_permission import role_permissions # noqa: F401 +from luthor.models.user import User # noqa: F401 +from luthor.models.user_role import user_roles # noqa: F401 diff --git a/luthor/luthor/db/init_db.py b/luthor/luthor/db/init_db.py deleted file mode 100644 index ce03db8..0000000 --- a/luthor/luthor/db/init_db.py +++ /dev/null @@ -1,217 +0,0 @@ -import uuid - -from barker.core.config import settings # noqa: F401 -from barker.models.auth import Permission, Role, User -from barker.models.master import ( - Customer, - DbSetting, - ModifierCategory, - Section, - SettleOption, -) -from brewman.db import base # noqa: F401 -from sqlalchemy.orm import Session - - -# make sure all SQL Alchemy models are imported (app.db.base) before initializing DB -# otherwise, SQL Alchemy might fail to initialize relationships properly -# for more details: https://github.com/tiangolo/full-stack-fastapi-postgresql/issues/28 - - -def init_db(db: Session) -> None: - # Tables should be created with Alembic migrations - # But if you don't want to use migrations, create - # the tables un-commenting the next line - # Base.metadata.create_all(bind=engine) - - prod = True - if prod: - db.add(Permission("Guest Book", uuid.UUID("7669dfc9-cc75-4e48-b267-145c8832a83c"))) - db.add(Permission("Printers", uuid.UUID("5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c"))) - db.add(Permission("Sections", uuid.UUID("c973f32c-a37b-496a-8dc5-60d2e4c39e97"))) - db.add( - Permission( - "Section Printers", - uuid.UUID("7a04ba63-5d08-4078-9051-a6d91cce3e48"), - ) - ) - else: - add_permissions(db) - - main_section = Section("Main", uuid.UUID("3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df")) - db.add(main_section) - mcs = [ - ModifierCategory( - "Old Modifiers", - 0, - 0, - True, - 0, - uuid.UUID("e046ad33-dc65-4c78-8833-c3d3538d44c0"), - ), - ModifierCategory( - "Bar Instructions", - 0, - 0, - True, - 0, - uuid.UUID("b572f401-3c2f-48b9-8973-ada5a6e4d3a6"), - ), - ModifierCategory( - "Delivery", - 0, - 0, - True, - 0, - uuid.UUID("caa72832-5034-405e-8442-68a8cc12ace9"), - ), - ModifierCategory( - "Kitchen Instructions", - 0, - 0, - True, - 0, - uuid.UUID("d6a0595f-e209-42e4-bb12-b7499f9a9c4d"), - ), - ModifierCategory( - "Mixers", - 0, - 0, - True, - 0, - uuid.UUID("60ca9122-adc5-463b-ad5f-33a68df8c3ae"), - ), - ModifierCategory( - "Pasta Sauce", - 0, - 0, - True, - 0, - uuid.UUID("ef5b1a0b-5eb1-45ff-bd82-3209c8b888df"), - ), - ] - for item in mcs: - db.add(item) - - options = [ - SettleOption("Unsettled", False, 1, True, 1), - SettleOption("Cash", True, 2, False, 2), - SettleOption("Credit Card", True, 2, True, 3), - SettleOption("No Charge", True, 3, True, 4), - SettleOption("Bill To Company", True, 2, True, 5), - SettleOption("Tip", True, 2, True, 6), - SettleOption("Round Off", False, 1, False, 7), - SettleOption("Amount", False, 1, False, 8), - SettleOption("Void", True, 1, True, 9), - SettleOption("Staff", True, 4, True, 10), - ] - for option in options: - db.add(option) - db.add(Customer("", "Cash", "", "", uuid.UUID("2c716f4b-0736-429a-ad51-610d7c47cb5e"))) - db.add( - DbSetting( - uuid.UUID("fb738ba2-a3c9-40ed-891c-b930e6454974"), - "Header", - { - "Text": """ Hops n Grains - The Microbrewery - SCO 358, Sector 9, Panchkula - A Unit of Peitho Foods Pvt. Ltd. - CIN: U15139CH2010PTC032202 - (Reg Add: Plot No. 907, Indl Area II, Chd) - TIN: 06592507323 - Service Tax: AAFCP5097GSD001 - """ - }, - ) - ) - db.add( - DbSetting( - uuid.UUID("f7799871-d16e-4c4d-9b57-2299a5839acb"), - "Footer", - {"Text": "Call: 0172-4026666, 8054923853, 8054923856"}, - ) - ) - - -def add_permissions(db: Session): - permissions = [ - Permission("Audit", uuid.UUID("f30fd1fb-df09-46f5-8c5d-181fd46f38de")), - Permission("Beer Consumption", uuid.UUID("efbb8f31-9631-4491-92f4-17cc98e6a0c0")), - Permission("Bill Details", uuid.UUID("612bb529-b50d-4653-a1c0-ebb725c7d728")), - Permission("Cashier Checkout", uuid.UUID("a86f8bcf-66f4-4c44-89e1-b714488b8331")), - Permission("Change Rate", uuid.UUID("10c63aae-0e48-4e54-b3b8-dd8a80b88fbf")), - Permission("Customers", uuid.UUID("e5fef133-cdbe-441f-bb54-1f0db0c5db79")), - Permission("Discount", uuid.UUID("1f66f131-0105-4466-8f8e-21e0ccc2ac27")), - Permission("Discount Report", uuid.UUID("0d8ba1d5-6731-417c-ab0e-be03cfdc96db")), - Permission("Edit Printed Bill", uuid.UUID("4ff6cb0f-93cb-4760-8219-4de280eaa957")), - Permission( - "Edit Printed Product", - uuid.UUID("959713be-d753-4e14-8ecd-e27f33587499"), - ), - Permission("Guest Book", uuid.UUID("7669dfc9-cc75-4e48-b267-145c8832a83c")), - Permission("Machines", uuid.UUID("f12b573f-edcb-490d-91c3-fa76f6502ffd")), - Permission("Merge Kots", uuid.UUID("bed774e9-4857-43b0-a4af-40230c9eb5db")), - Permission("Merge Tables", uuid.UUID("dfc493fb-ac14-4602-8596-f93f47b617de")), - Permission("Modifiers", uuid.UUID("9dc82529-1e86-41b4-a152-eaea9f775fea")), - Permission( - "Move Kot to New Table", - uuid.UUID("5ed5796a-ca99-437f-8f67-483b1ade81ed"), - ), - Permission("Move Table", uuid.UUID("cfdb69c9-d37a-40af-bef2-e29c04602543")), - Permission("NC Product", uuid.UUID("54263587-773e-4cbb-b1e4-4e814141158e")), - Permission("Open Bill", uuid.UUID("5811d233-a1ae-4d32-af52-cebbf46d274a")), - Permission("Owner", uuid.UUID("6d109b66-8452-42aa-bbe9-d4cef440b7a1")), - Permission("Print Bill", uuid.UUID("92242eae-bd38-4223-829b-2f981933b7f2")), - Permission("Print Kot", uuid.UUID("0eef56fb-7741-49fd-8b84-5069cccae767")), - Permission("Products", uuid.UUID("f1f892ed-34aa-4c50-be12-dbaf48be7d4c")), - Permission("Roles", uuid.UUID("d39f86f6-14e4-4fc3-b07e-01e2501a6f65")), - Permission("Sales", uuid.UUID("92ba45c4-2d34-4cbd-b5b8-d9164c3595d5")), - Permission("Sales Analysis", uuid.UUID("0c1acb7c-9116-46e2-a3be-9d632e811330")), - Permission("Sales Detail", uuid.UUID("e6476396-ef83-4c47-bc20-9f3b936813f9")), - Permission("Settle Bill", uuid.UUID("9f7b658a-25bc-4a53-8560-2dde1c7a188a")), - Permission("Split Bill", uuid.UUID("0a8cfaf4-624e-478f-be65-c3b6392078c7")), - Permission("Tables", uuid.UUID("ac4512e8-efdd-429e-a7ae-a34d18782663")), - Permission("Tax Analysis", uuid.UUID("bab36396-53dd-44ea-ab3c-426efa7830c8")), - Permission("Taxes", uuid.UUID("5c8fcdde-460d-4047-810f-e34fb899fadc")), - Permission("Users", uuid.UUID("243447b8-b403-47e6-8b3d-8e76f4df44a9")), - Permission("Void Bill", uuid.UUID("e3c76262-adc0-4936-8b4d-217c6292298b")), - Permission( - "Void or Reprinted Bill Report", - uuid.UUID("30c8e743-c710-42d7-843a-0b75543b3516"), - ), - Permission("Printers", uuid.UUID("5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c")), - Permission("Sections", uuid.UUID("c973f32c-a37b-496a-8dc5-60d2e4c39e97")), - ] - - for permission in permissions: - db.add(permission) - - roles = [ - Role("Owner", uuid.UUID("06ec0ddb-949c-4357-aefb-65e5e55a9ae7")), - Role("Accountant", uuid.UUID("57d4538c-257a-4bf4-9a42-342992cb6af3")), - Role("Bar Captain", uuid.UUID("5a8ebb05-4817-45a5-866f-e523c30bfa25")), - Role("Captain", uuid.UUID("8db7001f-0964-4607-84f5-b6f4d9183fef")), - Role("Cashier", uuid.UUID("f1f0b112-1404-4b55-b121-f07ee6e08d12")), - Role("Controller", uuid.UUID("d9a5a478-1fe4-4847-84da-63cfba1a094a")), - Role("Manager", uuid.UUID("90ea7b14-9057-4bfd-a7cf-0ee7a3bb2463")), - Role("Senior Captain", uuid.UUID("d9b1b433-1ed5-4109-8ab2-cbd48ff010cd")), - Role("Server", uuid.UUID("6b378b71-f091-4485-a589-8db94ff1d6a4")), - ] - - roles[0].permissions = permissions - roles[1].permissions = list(permissions[i] for i in [2, 3, 11, 18, 24, 25, 26, 30, 34]) - roles[2].permissions = list(permissions[i] for i in [26]) - roles[3].permissions = list(permissions[i] for i in [16]) - roles[4].permissions = list(permissions[i] for i in [20, 24, 27]) - roles[5].permissions = list(permissions[i] for i in [0, 2, 7, 11, 18, 22, 24, 25, 26, 34]) - roles[6].permissions = list(permissions[i] for i in [2, 3, 4, 5, 6, 8, 11, 14, 18, 22, 25, 26, 28, 29, 33, 34]) - roles[7].permissions = list(permissions[i] for i in [9, 12, 13, 15, 16]) - roles[8].permissions = list(permissions[i] for i in [21, 24]) - - for role in roles: - db.add(role) - - admin = User("Admin", "123456", False) - admin.roles.append(roles[0]) - db.add(admin) diff --git a/luthor/luthor/models/case_source.py b/luthor/luthor/models/case_source.py index 1382fe5..a14a6b5 100644 --- a/luthor/luthor/models/case_source.py +++ b/luthor/luthor/models/case_source.py @@ -4,7 +4,7 @@ from sqlalchemy import Column, Unicode, text from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import relationship -from .case import Case +from .case import Case # noqa: F401 from .meta import Base diff --git a/luthor/luthor/models/court_status.py b/luthor/luthor/models/court_status.py index 48317bc..128cf2b 100644 --- a/luthor/luthor/models/court_status.py +++ b/luthor/luthor/models/court_status.py @@ -4,8 +4,8 @@ from sqlalchemy import Column, Unicode, text from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import relationship -from .case import Case -from .hearing import Hearing +from .case import Case # noqa: F401 +from .hearing import Hearing # noqa: F401 from .meta import Base diff --git a/luthor/luthor/models/department.py b/luthor/luthor/models/department.py index 26d3bae..cbafce2 100644 --- a/luthor/luthor/models/department.py +++ b/luthor/luthor/models/department.py @@ -1,27 +1,7 @@ -import enum import uuid -from sqlalchemy import ( - JSON, - Boolean, - Column, - Date, - Enum, - ForeignKey, - Integer, - Numeric, - Table, - Unicode, - UniqueConstraint, - case, - func, - text, -) -from sqlalchemy.dialects import postgresql +from sqlalchemy import Column, Unicode, text from sqlalchemy.dialects.postgresql import UUID -from sqlalchemy.ext.hybrid import hybrid_property -from sqlalchemy.orm import relationship -from sqlalchemy.sql import expression from .meta import Base diff --git a/luthor/luthor/routers/menu_category.py b/luthor/luthor/routers/menu_category.py deleted file mode 100644 index 82561bc..0000000 --- a/luthor/luthor/routers/menu_category.py +++ /dev/null @@ -1,195 +0,0 @@ -# import uuid -# -# from datetime import date -# from operator import and_, or_ -# from typing import List, Optional -# -# import luthor.schemas.menu_category as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# from sqlalchemy import distinct -# 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.master import MenuCategory, ProductVersion -# from ..schemas.user_token import UserToken -# from . import effective_date -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("", response_model=schemas.MenuCategory) -# def save( -# data: schemas.MenuCategoryIn, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.MenuCategory: -# try: -# item = MenuCategory( -# name=data.name, -# is_active=data.is_active, -# sort_order=0, -# ) -# db.add(item) -# db.commit() -# return menu_category_info(item) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.put("/{id_}", response_model=schemas.MenuCategory) -# def update( -# id_: uuid.UUID, -# data: schemas.MenuCategoryIn, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.MenuCategory: -# try: -# item: MenuCategory = db.query(MenuCategory).filter(MenuCategory.id == id_).first() -# if item.is_fixture: -# raise HTTPException( -# status_code=status.HTTP_423_LOCKED, -# detail=f"{item.name} is a fixture and cannot be edited or deleted.", -# ) -# item.name = data.name -# item.is_active = data.is_active -# db.commit() -# return menu_category_info(item) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.delete("/{id_}", response_model=schemas.MenuCategoryBlank) -# def delete( -# id_: uuid.UUID, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.MenuCategoryBlank: -# try: -# item: MenuCategory = db.query(MenuCategory).filter(MenuCategory.id == id_).first() -# if item is None: -# raise HTTPException( -# status_code=status.HTTP_404_NOT_FOUND, -# detail="Menu Category not found", -# ) -# elif item.is_fixture: -# raise HTTPException( -# status_code=status.HTTP_423_LOCKED, -# detail=f"{item.name} is a fixture and cannot be edited or deleted.", -# ) -# else: -# raise HTTPException( -# status_code=status.HTTP_501_NOT_IMPLEMENTED, -# detail="Menu Category deletion not implemented", -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.get("", response_model=schemas.MenuCategoryBlank) -# def show_blank( -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.MenuCategoryBlank: -# return menu_category_blank() -# -# -# @router.get("/list", response_model=List[schemas.MenuCategory]) -# def show_list( -# p: Optional[bool] = None, -# date_: date = Depends(effective_date), -# db: Session = Depends(get_db), -# user: UserToken = Depends(get_user), -# ) -> List[schemas.MenuCategory]: -# -# if p is not None: -# sq = db.query(distinct(ProductVersion.menu_category_id)).filter( -# and_( -# or_( -# ProductVersion.valid_from == None, # noqa: E711 -# ProductVersion.valid_from <= date_, -# ), -# or_( -# ProductVersion.valid_till == None, # noqa: E711 -# ProductVersion.valid_till >= date_, -# ), -# ) -# ) -# query = ( -# db.query(MenuCategory) -# .filter(MenuCategory.id.in_(sq)) -# .order_by(MenuCategory.sort_order) -# .order_by(MenuCategory.name) -# .all() -# ) -# else: -# query = db.query(MenuCategory).order_by(MenuCategory.sort_order).order_by(MenuCategory.name).all() -# return [menu_category_info(item) for item in query] -# -# -# @router.get("/{id_}", response_model=schemas.MenuCategory) -# def show_id( -# id_: uuid.UUID, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.MenuCategory: -# item: MenuCategory = db.query(MenuCategory).filter(MenuCategory.id == id_).first() -# return menu_category_info(item) -# -# -# # @view_config( -# # request_method="POST", route_name="v1_menu_categories_list", renderer="json", permission="Products", trans=True, -# # ) -# # def sort_order(request): -# # json = request.json_body -# # for index, item in enumerate(json): -# # request.dbsession.query(MenuCategory).filter(MenuCategory.id == uuid.UUID(item["id"])).update( -# # {MenuCategory.sort_order: index} -# # ) -# # return True -# -# -# def menu_category_info(item: MenuCategory) -> schemas.MenuCategory: -# return schemas.MenuCategory( -# id=item.id, -# name=item.name, -# isActive=item.is_active, -# isFixture=item.is_fixture, -# sortOrder=item.sort_order, -# ) -# -# -# def menu_category_blank() -> schemas.MenuCategoryBlank: -# return schemas.MenuCategoryBlank( -# name="", -# isActive=True, -# isFixture=False, -# sortOrder=0, -# ) diff --git a/luthor/luthor/routers/modifier.py b/luthor/luthor/routers/modifier.py deleted file mode 100644 index 3e75add..0000000 --- a/luthor/luthor/routers/modifier.py +++ /dev/null @@ -1,149 +0,0 @@ -# import uuid -# -# from typing import List -# -# import barker.schemas.modifier as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# 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.master import Modifier -# from ..schemas.user_token import UserToken -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("", response_model=schemas.Modifier) -# def save( -# data: schemas.ModifierIn, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.Modifier: -# try: -# item = Modifier( -# name=data.name, -# show_in_bill=data.show_in_bill, -# price=data.price, -# modifier_category_id=data.modifier_category.id_, -# is_active=data.is_active, -# ) -# db.add(item) -# db.commit() -# return modifier_info(item) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.put("/{id_}", response_model=schemas.Modifier) -# def update( -# id_: uuid.UUID, -# data: schemas.ModifierIn, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.Modifier: -# try: -# item: Modifier = db.query(Modifier).filter(Modifier.id == id_).first() -# item.name = data.name -# item.show_in_bill = data.show_in_bill -# item.price = data.price -# item.modifier_category_id = data.modifier_category.id_ -# item.is_active = data.is_active -# db.commit() -# return modifier_info(item) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.delete("/{id_}", response_model=schemas.ModifierBlank) -# def delete( -# id_: uuid.UUID, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.ModifierBlank: -# try: -# item: Modifier = db.query(Modifier).filter(Modifier.id == id_).first() -# db.delete(item) -# db.commit() -# return modifier_blank() -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.get("", response_model=schemas.ModifierBlank) -# def show_blank( -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.ModifierBlank: -# return modifier_blank() -# -# -# @router.get("/list", response_model=List[schemas.Modifier]) -# def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)) -> List[schemas.Modifier]: -# return [modifier_info(item) for item in db.query(Modifier).order_by(Modifier.name).all()] -# -# -# @router.get("/{id_}", response_model=schemas.Modifier) -# def show_id( -# id_: uuid.UUID, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.Modifier: -# item: Modifier = db.query(Modifier).filter(Modifier.id == id_).first() -# return modifier_info(item) -# -# -# def modifier_info(item: Modifier) -> schemas.Modifier: -# return schemas.Modifier( -# id=item.id, -# name=item.name, -# showInBill=item.show_in_bill, -# price=item.price, -# isActive=item.is_active, -# modifierCategory=schemas.ModifierCategoryLink( -# id=item.modifier_category.id, -# name=item.modifier_category.name, -# ), -# ) -# -# -# def modifier_blank() -> schemas.ModifierBlank: -# return schemas.ModifierBlank( -# name="", -# showInBill=False, -# price=0, -# isActive=True, -# ) diff --git a/luthor/luthor/routers/modifier_category.py b/luthor/luthor/routers/modifier_category.py deleted file mode 100644 index 57b4726..0000000 --- a/luthor/luthor/routers/modifier_category.py +++ /dev/null @@ -1,311 +0,0 @@ -# import uuid -# -# from datetime import date -# from functools import reduce -# from typing import List -# -# import barker.schemas.modifier_category as schemas -# -# from barker.schemas.product_link import ProductLink as ProductLinkSchema -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# from sqlalchemy import and_, or_ -# from sqlalchemy.exc import SQLAlchemyError -# from sqlalchemy.orm import Session, contains_eager, joinedload -# -# from ..core.security import get_current_active_user as get_user -# from ..db.session import SessionLocal -# from ..models.master import MenuCategory, ModifierCategory, Product, ProductVersion -# from ..schemas.user_token import UserToken -# from . import effective_date -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("", response_model=schemas.ModifierCategory) -# def save( -# data: schemas.ModifierCategoryIn, -# date_: date = Depends(effective_date), -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.ModifierCategory: -# try: -# item = ModifierCategory( -# name=data.name, -# minimum=data.minimum, -# maximum=None if data.maximum == 0 else data.maximum, -# is_active=data.is_active, -# ) -# db.add(item) -# add_products(item, data.menu_categories, db) -# db.commit() -# return modifier_category_info(item, date_, db=db) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.put("/{id_}", response_model=schemas.ModifierCategory) -# def update( -# id_: uuid.UUID, -# data: schemas.ModifierCategoryIn, -# date_: date = Depends(effective_date), -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.ModifierCategory: -# try: -# item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first() -# item.name = data.name -# item.minimum = data.minimum -# item.maximum = None if data.maximum == 0 else data.maximum -# item.is_active = data.is_active -# add_products(item, data.menu_categories, db) -# db.commit() -# return modifier_category_info(item, date_, db=db) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.delete("/{id_}", response_model=schemas.ModifierCategoryBlank) -# def delete( -# id_: uuid.UUID, -# date_: date = Depends(effective_date), -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.ModifierCategoryBlank: -# try: -# item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first() -# db.delete(item) -# db.commit() -# return modifier_category_blank(date_, db=db) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.get("", response_model=schemas.ModifierCategoryBlank) -# def show_blank( -# db: Session = Depends(get_db), -# date_: date = Depends(effective_date), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.ModifierCategoryBlank: -# return modifier_category_blank(date_, db=db) -# -# -# @router.get("/list") -# def show_list( -# date_: date = Depends(effective_date), db: Session = Depends(get_db), user: UserToken = Depends(get_user) -# ): -# list_ = db.query(ModifierCategory).order_by(ModifierCategory.sort_order).order_by(ModifierCategory.name).all() -# menu_categories = ( -# db.query(MenuCategory) -# .join(MenuCategory.products) -# .filter( -# and_( -# or_( -# ProductVersion.valid_from == None, # noqa: E711 -# ProductVersion.valid_from <= date_, -# ), -# or_( -# ProductVersion.valid_till == None, # noqa: E711 -# ProductVersion.valid_till >= date_, -# ), -# ) -# ) -# .order_by(MenuCategory.sort_order, ProductVersion.sort_order, ProductVersion.name) -# .options( -# joinedload(MenuCategory.products, innerjoin=True), -# contains_eager(MenuCategory.products), -# ) -# .all() -# ) -# modifier_categories = [] -# for item in list_: -# products = [x.id for x in item.products] -# modifier_category = { -# "id": item.id, -# "name": item.name, -# "minimum": item.minimum, -# "maximum": item.maximum, -# "isActive": item.is_active, -# "menuCategories": [ -# { -# "id": mc.id, -# "name": mc.name, -# "enabled": reduce(lambda x, y: x and (y.product_id in products), mc.products, True), -# "products": [{"id": p.id, "name": p.name} for p in mc.products if p.product_id in products], -# } -# for mc in menu_categories -# ], -# } -# modifier_category["menuCategories"] = [i for i in modifier_category["menuCategories"] if len(i["products"]) > 0] -# modifier_categories.append(modifier_category) -# return modifier_categories -# -# -# @router.get("/for-product/{id_}") -# def for_product( -# id_: uuid.UUID, -# date_: date = Depends(effective_date), -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user), -# ): -# product: Product = db.query(Product).filter(Product.id == id_).first() -# -# return [ -# { -# "id": item.id, -# "name": item.name, -# "minimum": item.minimum, -# "maximum": item.maximum, -# "isActive": item.is_active, -# "modifiers": [ -# {"id": m.id, "name": m.name, "price": m.price} -# for m in item.modifiers -# if m.is_active == True # noqa: E712 -# ], -# } -# for item in product.modifier_categories -# if item.is_active == True -# ] -# -# -# @router.get("/{id_}", response_model=schemas.ModifierCategory) -# def show_id( -# id_: uuid.UUID, -# date_: date = Depends(effective_date), -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["modifiers"]), -# ) -> schemas.ModifierCategory: -# item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first() -# return modifier_category_info(item, date_, db=db) -# -# -# def modifier_category_info(item: ModifierCategory, date_: date, db: Session) -> schemas.ModifierCategory: -# menu_categories = ( -# db.query(MenuCategory) -# .join(MenuCategory.products) -# .filter( -# and_( -# or_( -# ProductVersion.valid_from == None, # noqa: E711 -# ProductVersion.valid_from <= date_, -# ), -# or_( -# ProductVersion.valid_till == None, # noqa: E711 -# ProductVersion.valid_till >= date_, -# ), -# ) -# ) -# .order_by(MenuCategory.sort_order, ProductVersion.sort_order, ProductVersion.name) -# .options( -# joinedload(MenuCategory.products, innerjoin=True), -# contains_eager(MenuCategory.products), -# ) -# .all() -# ) -# products = [p.id for p in item.products] -# return schemas.ModifierCategory( -# id=item.id, -# name=item.name, -# minimum=item.minimum, -# maximum=item.maximum, -# isActive=item.is_active, -# menuCategories=[ -# schemas.MenuCategoryLink( -# id=mc.id, -# name=mc.name, -# enabled=False, -# products=[ -# ProductLinkSchema( -# id=p.product_id, -# name=p.name, -# enabled=True if p.product_id in products else False, -# ) -# for p in mc.products -# ], -# ) -# for mc in menu_categories -# ], -# sortOrder=item.sort_order, -# ) -# -# -# def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategoryBlank: -# menu_categories = ( -# db.query(MenuCategory) -# .join(MenuCategory.products) -# .filter( -# and_( -# or_( -# ProductVersion.valid_from == None, # noqa: E711 -# ProductVersion.valid_from <= date_, -# ), -# or_( -# ProductVersion.valid_till == None, # noqa: E711 -# ProductVersion.valid_till >= date_, -# ), -# ) -# ) -# .order_by(MenuCategory.sort_order, ProductVersion.sort_order, ProductVersion.name) -# .options( -# joinedload(MenuCategory.products, innerjoin=True), -# contains_eager(MenuCategory.products), -# ) -# .all() -# ) -# return schemas.ModifierCategoryBlank( -# name="", -# minimum=0, -# maximum=0, -# isActive=True, -# menuCategories=[ -# schemas.MenuCategoryLink( -# id=mc.id, -# name=mc.name, -# enabled=False, -# products=[ProductLinkSchema(id=p.product_id, name=p.name, enabled=False) for p in mc.products], -# ) -# for mc in menu_categories -# ], -# ) -# -# -# def add_products(modifier_category: ModifierCategory, menu_categories: List[schemas.MenuCategoryLink], db: Session): -# for mc in menu_categories: -# for p in mc.products: -# old = [x for x in modifier_category.products if x.id == p.id_] -# old = None if len(old) == 0 else old[0] -# if p.enabled and old is None: -# product_object = db.query(Product).filter(Product.id == p.id_).one() -# modifier_category.products.append(product_object) -# elif not p.enabled and old: -# modifier_category.products.remove(old) diff --git a/luthor/luthor/routers/sale_category.py b/luthor/luthor/routers/sale_category.py deleted file mode 100644 index e80aeaa..0000000 --- a/luthor/luthor/routers/sale_category.py +++ /dev/null @@ -1,140 +0,0 @@ -# import uuid -# -# from typing import List -# -# import barker.schemas.sale_category as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# 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.master import SaleCategory -# from ..schemas.user_token import UserToken -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("", response_model=schemas.SaleCategory) -# def save( -# data: schemas.SaleCategoryIn, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.SaleCategory: -# try: -# item = SaleCategory(name=data.name, discount_limit=round(data.discount_limit, 2), tax_id=data.tax.id_) -# db.add(item) -# db.commit() -# return sale_category_info(item) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.put("/{id_}", response_model=schemas.SaleCategory) -# def update( -# id_: uuid.UUID, -# data: schemas.SaleCategoryIn, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.SaleCategory: -# try: -# item: SaleCategory = db.query(SaleCategory).filter(SaleCategory.id == id_).first() -# item.name = data.name -# item.discount_limit = round(data.discount_limit, 2) -# item.tax_id = data.tax.id_ -# db.commit() -# return sale_category_info(item) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.delete("/{id_}", response_model=schemas.SaleCategoryBlank) -# def delete( -# id_: uuid.UUID, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.SaleCategoryBlank: -# try: -# item: SaleCategory = db.query(SaleCategory).filter(SaleCategory.id == id_).first() -# if item is None: -# raise HTTPException( -# status_code=status.HTTP_404_NOT_FOUND, -# detail="Sale Category not found", -# ) -# else: -# raise HTTPException( -# status_code=status.HTTP_501_NOT_IMPLEMENTED, -# detail="Sale Category deletion not implemented", -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.get("", response_model=schemas.SaleCategoryBlank) -# def show_blank( -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.SaleCategoryBlank: -# return sale_category_blank() -# -# -# @router.get("/list", response_model=List[schemas.SaleCategory]) -# def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)) -> List[schemas.SaleCategory]: -# return [sale_category_info(item) for item in db.query(SaleCategory).order_by(SaleCategory.name).all()] -# -# -# @router.get("/for-discount", response_model=List[schemas.SaleCategoryForDiscount]) -# def for_discount(db: Session = Depends(get_db), user: UserToken = Depends(get_user)) -> List[schemas.SaleCategory]: -# return [ -# schemas.SaleCategoryForDiscount(id=item.id, name=item.name, discountLimit=item.discount_limit, discount=0) -# for item in db.query(SaleCategory).filter(SaleCategory.discount_limit != 0).order_by(SaleCategory.name).all() -# ] -# -# -# @router.get("/{id_}", response_model=schemas.SaleCategory) -# def show_id( -# id_: uuid.UUID, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> schemas.SaleCategory: -# item: SaleCategory = db.query(SaleCategory).filter(SaleCategory.id == id_).first() -# return sale_category_info(item) -# -# -# def sale_category_info(item: SaleCategory) -> schemas.SaleCategory: -# return schemas.SaleCategory( -# id=item.id, -# name=item.name, -# discountLimit=item.discount_limit, -# tax=schemas.TaxLink(id=item.tax_id, name=item.tax.name, rate=item.tax.rate), -# ) -# -# -# def sale_category_blank() -> schemas.SaleCategoryBlank: -# return schemas.SaleCategoryBlank(name="", discountLimit=1) diff --git a/luthor/luthor/routers/section_printer.py b/luthor/luthor/routers/section_printer.py deleted file mode 100644 index 9b6e805..0000000 --- a/luthor/luthor/routers/section_printer.py +++ /dev/null @@ -1,156 +0,0 @@ -# import uuid -# -# from typing import List, Optional -# -# import barker.schemas.section_printer as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# from sqlalchemy import and_, or_ -# from sqlalchemy.dialects.postgresql import insert as pg_insert -# 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.master import MenuCategory, SectionPrinter -# from ..schemas.user_token import UserToken -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("/{id_}", response_model=List[schemas.SectionPrinter]) -# def save( -# id_: uuid.UUID, -# data: List[schemas.SectionPrinter], -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["section-printers"]), -# ) -> List[schemas.SectionPrinter]: -# try: -# current = [] -# default_copies = 0 -# for mcs in data: -# if mcs.menu_category is None and mcs.printer is None: -# raise ValueError("Please choose a default printer") -# if mcs.printer is None: -# continue -# if mcs.menu_category is None: -# default_copies = mcs.copies -# stmt = ( -# pg_insert(SectionPrinter.__table__) -# .values( -# id=uuid.uuid4(), -# menu_category_id=mcs.menu_category.id_ if mcs.menu_category is not None else None, -# section_id=id_, -# printer_id=mcs.printer.id_, -# copies=mcs.copies, -# ) -# .on_conflict_do_update( -# index_elements=["menu_category_id", "section_id"], -# set_=dict(printer_id=mcs.printer.id_, copies=mcs.copies), -# ) -# ) -# db.execute(stmt) -# current.append(None if mcs.menu_category is None else mcs.menu_category.id_) -# db.execute( -# SectionPrinter.__table__.delete( -# or_( -# and_( -# SectionPrinter.section_id == id_, -# SectionPrinter.menu_category_id == None, # noqa: E711 -# SectionPrinter.copies != default_copies, -# ), -# and_( -# SectionPrinter.section_id == id_, -# SectionPrinter.menu_category_id != None, # noqa: E711 -# ~SectionPrinter.menu_category_id.in_([x for x in current if x is not None]), -# ), -# ) -# ) -# ) -# db.commit() -# -# return report(id_, db) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.delete("/{id_}", response_model=List[schemas.SectionPrinter]) -# def delete( -# id_: uuid.UUID, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["section-printers"]), -# ) -> List[schemas.SectionPrinter]: -# try: -# SectionPrinter.__table__.delete(SectionPrinter.section_id == id_) -# db.commit() -# return report(id_, db) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.get("", response_model=List[schemas.SectionPrinter]) -# def show_blank( -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["section-printers"]), -# ) -> List[schemas.SectionPrinter]: -# return report(None, db) -# -# -# @router.get("/{id_}", response_model=List[schemas.SectionPrinter]) -# def show_id( -# id_: uuid.UUID, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["section-printers"]), -# ) -> List[schemas.SectionPrinter]: -# return report(id_, db) -# -# -# def report(section_id: Optional[uuid.UUID], db: Session) -> List[schemas.SectionPrinter]: -# menu_categories = ( -# db.query(MenuCategory.id, MenuCategory.name) -# .filter(MenuCategory.is_active == True) # noqa: E712 -# .order_by(MenuCategory.sort_order) -# .all() -# ) -# list_ = [] -# for mc_id, mc_name in [(None, None)] + menu_categories: -# section_printer = ( -# db.query(SectionPrinter) -# .filter( -# SectionPrinter.section_id == section_id, -# SectionPrinter.menu_category_id == mc_id, -# ) -# .first() -# ) -# list_.append( -# schemas.SectionPrinter( -# menuCategory=None if mc_id is None else schemas.MenuCategoryLink(id=mc_id, name=mc_name), -# printer=None if section_printer is None else schemas.PrinterLink(id=section_printer.printer_id), -# copies=0 if section_printer is None else section_printer.copies, -# ) -# ) -# return list_ diff --git a/luthor/luthor/routers/update_product_prices.py b/luthor/luthor/routers/update_product_prices.py deleted file mode 100644 index ddbfe85..0000000 --- a/luthor/luthor/routers/update_product_prices.py +++ /dev/null @@ -1,182 +0,0 @@ -# import uuid -# -# from datetime import date, timedelta -# from decimal import Decimal -# from typing import List, Optional -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# from sqlalchemy import and_, or_ -# from sqlalchemy.orm import Session, contains_eager, joinedload -# -# from ..core.security import get_current_active_user as get_user -# from ..db.session import SessionLocal -# from ..models.master import MenuCategory, ProductVersion -# from ..schemas.update_product_prices import UpdateProductPrices, UpdateProductPricesItem -# from ..schemas.user_token import UserToken -# from . import optional_query_date -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db() -> Session: -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.get("", response_model=UpdateProductPrices) -# def get_update_product_prices( -# date_: Optional[date] = Depends(optional_query_date), -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> UpdateProductPrices: -# if date_ is None: -# return UpdateProductPrices( -# date=date.today(), -# items=[], -# ) -# return UpdateProductPrices( -# date=date_, -# items=update_product_prices_list(None, date_, db), -# ) -# -# -# @router.get("/{id_}", response_model=UpdateProductPrices) -# def get_update_product_prices_id( -# id_: uuid.UUID, -# date_: Optional[date] = Depends(optional_query_date), -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> UpdateProductPrices: -# if date_ is None: -# return UpdateProductPrices( -# date=date.today(), -# menuCategoryId=id_, -# items=[], -# ) -# return UpdateProductPrices( -# date=date_, -# menuCategoryId=id_, -# items=update_product_prices_list(id_, date_, db), -# ) -# -# -# def update_product_prices_list( -# menu_category_id: Optional[uuid.UUID], date_: date, db: Session -# ) -> List[UpdateProductPricesItem]: -# list_: List[ProductVersion] = ( -# db.query(ProductVersion) -# .join(ProductVersion.menu_category) -# .filter( -# and_( -# or_( -# ProductVersion.valid_from == None, # noqa: E711 -# ProductVersion.valid_from <= date_, -# ), -# or_( -# ProductVersion.valid_till == None, # noqa: E711 -# ProductVersion.valid_till >= date_, -# ), -# ) -# ) -# ) -# if menu_category_id is not None: -# list_ = list_.filter(ProductVersion.menu_category_id == menu_category_id) -# list_.order_by( -# MenuCategory.sort_order, -# MenuCategory.name, -# ProductVersion.sort_order, -# ProductVersion.name, -# ProductVersion.valid_from.nullsfirst(), -# ).options( -# joinedload(ProductVersion.menu_category, innerjoin=True), -# contains_eager(ProductVersion.menu_category), -# ).all() -# -# return [ -# UpdateProductPricesItem(id=item.product_id, name=item.full_name, oldPrice=item.price, newPrice=item.price) -# for item in list_ -# ] -# -# -# @router.post("", response_model=UpdateProductPrices) -# def save_update_product_prices( -# data: UpdateProductPrices, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> UpdateProductPrices: -# for item in data.items: -# update_product(item.id, item.new_price, data.date_, db) -# db.commit() -# return UpdateProductPrices( -# date=data.date_, -# items=update_product_prices_list(None, data.date_, db), -# ) -# -# -# @router.post("/{id_}", response_model=UpdateProductPrices) -# def save_update_product_prices_id( -# id_: uuid.UUID, -# data: UpdateProductPrices, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["products"]), -# ) -> UpdateProductPrices: -# for item in data.items: -# update_product(item.id, item.new_price, data.date_, db) -# db.commit() -# return UpdateProductPrices( -# date=data.date_, -# menuCategoryId=id_, -# items=update_product_prices_list(id_, data.date_, db), -# ) -# -# -# def update_product(id_: uuid.UUID, price: Decimal, date_: date, db: Session): -# item: ProductVersion = ( -# db.query(ProductVersion) -# .join(ProductVersion.menu_category) -# .filter( -# and_( -# ProductVersion.product_id == id_, -# or_( -# ProductVersion.valid_from == None, # noqa: E711 -# ProductVersion.valid_from <= date_, -# ), -# or_( -# ProductVersion.valid_till == None, # noqa: E711 -# ProductVersion.valid_till >= date_, -# ), -# ) -# ) -# .first() -# ) -# if item.valid_till is not None: -# # Allow adding a product here splitting the valid from and to, but not implemented right now -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail="Product has been invalidated", -# ) -# if item.valid_from == date_: # Update the product as valid from the the same -# item.price = price -# db.commit() -# else: # Create a new version of the product from the new details -# item.valid_till = date_ - timedelta(days=1) -# product_version = ProductVersion( -# product_id=item.product_id, -# name=item.name, -# units=item.units, -# menu_category_id=item.menu_category_id, -# sale_category_id=item.sale_category_id, -# price=price, -# has_happy_hour=item.has_happy_hour, -# is_not_available=item.is_not_available, -# quantity=item.quantity, -# valid_from=date_, -# valid_till=None, -# sort_order=item.sort_order, -# ) -# db.add(product_version) diff --git a/luthor/luthor/routers/voucher/__init__.py b/luthor/luthor/routers/voucher/__init__.py deleted file mode 100644 index b64cd8e..0000000 --- a/luthor/luthor/routers/voucher/__init__.py +++ /dev/null @@ -1,155 +0,0 @@ -# import uuid -# -# from decimal import Decimal -# from typing import List, Optional -# -# import barker.schemas.voucher as schemas -# -# from fastapi import HTTPException, status -# from sqlalchemy import func -# from sqlalchemy.orm import Session -# -# from ...models.master import SettleOption, VoucherType -# from ...models.voucher import GuestBook, Overview, Settlement, Voucher -# from ...schemas.receive_payment import ReceivePaymentItem as SettleSchema -# -# -# def get_tax(tax, voucher_type): -# if voucher_type in [VoucherType.STAFF, VoucherType.NO_CHARGE]: -# return 0 -# elif voucher_type in [VoucherType.KOT, VoucherType.REGULAR_BILL]: -# return tax -# else: -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Unexpected Voucher Type", -# ) -# -# -# def get_bill_id(voucher_type: VoucherType, db: Session) -> Optional[int]: -# if voucher_type == VoucherType.KOT: -# return None -# bill_id = ( -# db.query(func.coalesce(func.max(Voucher.bill_id), 0) + 1).filter(Voucher.voucher_type == voucher_type).scalar() -# ) -# if voucher_type == VoucherType.REGULAR_BILL and bill_id % 10000 == 0: -# bill_id += 1 -# return bill_id -# -# -# def do_update_table(item: Voucher, guest_book: Optional[GuestBook], db: Session): -# status_ = "running" if item.voucher_type == VoucherType.KOT else "printed" -# if item.status is None: -# item.status = Overview( -# voucher_id=item.id, -# food_table_id=item.food_table_id, -# guest_book_id=guest_book.id if guest_book is not None else None, -# status=status_, -# ) -# db.add(item.status) -# else: -# item.status.status = status_ -# -# -# def check_permissions(item: Optional[Voucher], voucher_type: VoucherType, permissions: List[str]): -# if voucher_type == VoucherType.KOT and "print-kot" not in permissions: -# raise HTTPException( -# status_code=status.HTTP_403_FORBIDDEN, -# detail="You are not allowed to print a kot", -# ) -# if voucher_type != VoucherType.KOT and "print-bill" not in permissions: -# raise HTTPException( -# status_code=status.HTTP_403_FORBIDDEN, -# detail="You are not allowed to print bill", -# ) -# -# if item is None: -# return -# if item.voucher_type != VoucherType.KOT and "edit-printed-bill" not in permissions: -# raise HTTPException( -# status_code=status.HTTP_403_FORBIDDEN, -# detail="You are not allowed to edit a printed bill", -# ) -# -# if item.voucher_type != VoucherType.KOT and voucher_type == VoucherType.KOT: -# raise HTTPException( -# status_code=status.HTTP_403_FORBIDDEN, -# detail="This Bill is already printed\nCannot add a Kot to it.", -# ) -# -# if item.voucher_type == VoucherType.VOID: -# raise HTTPException( -# status_code=status.HTTP_403_FORBIDDEN, -# detail=f"This Bill is already void.\nReason: {item.reason}", -# ) -# -# -# def get_guest_book(id_: uuid.UUID, db: Session): -# if id_ is None: -# return id_ -# return db.query(GuestBook).filter(GuestBook.id == id_).first() -# -# -# def do_update_settlements(voucher: Voucher, others: List[SettleSchema], db: Session) -> bool: -# fully_settled = True -# settlements: List[SettleSchema] = [] -# settlements += others -# total_amount = voucher.amount -# settlements.append(SettleSchema(id=SettleOption.AMOUNT(), amount=-total_amount)) -# round_off = round(total_amount) - total_amount -# if round_off != 0: -# settlements.append(SettleSchema(id=SettleOption.ROUND_OFF(), amount=-round_off)) -# unsettled = sum(x.amount for x in settlements) -# if len(others) and unsettled != 0: # This should not be allowed -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Payment received is not equal to bill amount", -# ) -# if unsettled != 0: -# settlements.append(SettleSchema(id=SettleOption.UNSETTLED(), amount=unsettled)) -# fully_settled = False -# -# for i in settlements: -# old = [s for s in voucher.settlements if s.settled == i.id_] -# if len(old) == 1: -# old[0].amount = i.amount -# else: -# s = Settlement(voucher.id, i.id_, i.amount) -# voucher.settlements.append(s) -# db.add(s) -# -# for i in (i for i in voucher.settlements if i.settled not in [x.id_ for x in settlements]): -# voucher.settlements.remove(i) -# db.delete(i) -# return fully_settled -# -# -# def happy_hour_items_balanced(inventories: List[schemas.Inventory]) -> bool: -# happy = set((i.product.id_, i.quantity) for i in inventories if i.is_happy_hour) -# products = set(i.product.id_ for i in inventories if i.is_happy_hour) -# other = set((i.product.id_, i.quantity) for i in inventories if not i.is_happy_hour and i.product.id_ in products) -# return happy == other -# -# -# def happy_hour_has_discount(inventories: List[schemas.Inventory]) -> bool: -# happy = set(i.product.id_ for i in inventories if i.is_happy_hour) -# offenders = [i for i in inventories if i.product.id_ in happy and i.discount != 0] -# return len(offenders) > 0 -# -# -# # This is for the whole bill. eg. Kot 1 => Reg 2 + HH 2; Kot 2 => Reg 4; Kot 3 => Reg - 4 -# # This is pass okay in happy hours items balanced, but overall this is wrong. Hence this check -# def happy_hour_items_more_than_regular(kots: List[schemas.Kot]) -> bool: -# inventories = {} -# for kot in kots: -# for inventory in kot.inventories: -# if inventory.product.id_ not in inventories: -# inventories[inventory.product.id_] = {"normal": Decimal(0), "happy": Decimal(0)} -# if inventory.is_happy_hour: -# inventories[inventory.product.id_]["happy"] += inventory.quantity -# else: -# inventories[inventory.product.id_]["normal"] += inventory.quantity -# for value in inventories.values(): -# if value["happy"] > value["normal"]: -# return True -# return False diff --git a/luthor/luthor/routers/voucher/change.py b/luthor/luthor/routers/voucher/change.py deleted file mode 100644 index f50172e..0000000 --- a/luthor/luthor/routers/voucher/change.py +++ /dev/null @@ -1,99 +0,0 @@ -# import uuid -# -# from typing import Optional -# -# import barker.schemas.voucher as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# 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.master import SettleOption, VoucherType -# from ...models.voucher import Overview, Reprint, Voucher -# from ...routers.voucher import do_update_settlements, get_guest_book -# from ...schemas.receive_payment import ReceivePaymentItem as SettleSchema -# from ...schemas.user_token import UserToken -# from .save import do_save -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.put("/change/{id_}") -# def change( -# id_: uuid.UUID, -# data: schemas.VoucherIn, -# u: bool, # Update table? -# g: Optional[uuid.UUID] = None, # Guest book id -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["edit-printed-bill"]), -# ): -# try: -# old: Voucher = db.query(Voucher).filter(Voucher.id == id_).first() -# if old.voucher_type == VoucherType.VOID: -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Voucher cannot be reprinted. It is already void.", -# ) -# bill_changed: bool = ( -# len( -# set((i.id, i.amount) for k in old.kots for i in k.inventories) -# ^ set((i.id_, i.amount) for k in data.kots for i in k.inventories) -# ) -# != 0 -# ) -# if bill_changed: -# void_and_issue_new_bill(data, u, g, old, db, user) -# else: -# reprint_bill(id_, user.id_, db) -# db.commit() -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# def reprint_bill(voucher_id: uuid.UUID, user_id: uuid.UUID, db: Session): -# item = Reprint(voucher_id=voucher_id, user_id=user_id) -# db.add(item) -# -# -# def void_and_issue_new_bill( -# data: schemas.VoucherIn, -# u: bool, -# g: Optional[uuid.UUID], -# old: Voucher, -# db: Session, -# user: UserToken, -# ): -# update_table = u -# guest_book = get_guest_book(g, db) -# item: Voucher = do_save(data, old.voucher_type, guest_book, db, user) -# db.flush() -# old.bill_id = None -# old.voucher_type = VoucherType.VOID -# old.reason = f"Bill Discounted / Changed. New Bill ID is {item.full_bill_id}" -# do_update_settlements(old, [SettleSchema(id=SettleOption.VOID(), amount=round(old.amount))], db) -# -# if update_table: -# if old.status is None: -# item.status = Overview(voucher_id=None, food_table_id=item.food_table_id, status="printed") -# db.add(item.status) -# else: -# db.query(Overview).filter(Overview.voucher_id == old.id).update({Overview.voucher_id: item.id}) diff --git a/luthor/luthor/routers/voucher/merge_move.py b/luthor/luthor/routers/voucher/merge_move.py deleted file mode 100644 index 397db8a..0000000 --- a/luthor/luthor/routers/voucher/merge_move.py +++ /dev/null @@ -1,177 +0,0 @@ -# import uuid -# -# from datetime import datetime -# from typing import List -# -# import barker.schemas.merge_move as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# from sqlalchemy import func -# 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.master import VoucherType -# from ...models.voucher import Kot, Overview, Settlement, Voucher -# from ...routers.voucher import do_update_settlements, do_update_table, get_bill_id -# from ...schemas.user_token import UserToken -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("/move-kot/merge") -# def merge_kot( -# data: schemas.MergeKot, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["merge-kots"]), -# ): -# try: -# check_if_voucher_is_unprinted(data.voucher_id, db) -# kots: int = db.query(func.count(Kot.id)).filter(Kot.voucher_id == data.voucher_id).scalar() -# if kots <= 1: -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail="Single kot cannot be used, move table instead. This error should not show up in frontend", -# ) -# check_if_voucher_is_unprinted(data.new_voucher_id, db) -# -# db.query(Kot).filter(Kot.id == data.kot_id, Kot.voucher_id == data.voucher_id).update( -# {Kot.voucher_id: data.new_voucher_id} -# ) -# update_settlements([data.voucher_id, data.new_voucher_id], db) -# db.commit() -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.post("/move-kot/move") -# def move_kot( -# data: schemas.MoveKot, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["move-kot-to-new-table"]), -# ): -# try: -# now = datetime.now() -# check_if_voucher_is_unprinted(data.voucher_id, db) -# kots: int = db.query(func.count(Kot.id)).filter(Kot.voucher_id == data.voucher_id).scalar() -# if kots <= 1: -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail="Single kot cannot be used, move table instead. This error should not show up in frontend", -# ) -# kot = db.query(Kot).filter(Kot.id == data.kot_id).first() -# bill_id = get_bill_id(kot.voucher.voucher_type, db) -# kot_id = db.query(func.coalesce(func.max(Voucher.kot_id), 0) + 1).scalar() -# -# item = Voucher( -# now, -# kot.voucher.pax, -# bill_id, -# kot_id, -# data.table_id, -# kot.voucher.customer_id if kot.voucher.customer is not None else None, -# kot.voucher.voucher_type, -# user.id_, -# ) -# db.add(item) -# item.kots.append(kot) -# db.flush() -# do_update_table(item, None, db) -# update_settlements([data.voucher_id, item.id], db) -# db.commit() -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.post("/move-table/move") -# def move_table( -# data: schemas.MoveTable, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["move-table"]), -# ): -# try: -# db.query(Overview).filter(Overview.voucher_id == data.voucher_id).update( -# {Overview.food_table_id: data.table_id} -# ) -# db.query(Voucher).filter(Voucher.id == data.voucher_id).update({Voucher.food_table_id: data.table_id}) -# db.commit() -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# @router.post("/move-table/merge") -# def merge_table( -# data: schemas.MergeTable, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["merge-tables"]), -# ): -# try: -# check_if_voucher_is_unprinted(data.voucher_id, db) -# check_if_voucher_is_unprinted(data.new_voucher_id, db) -# db.query(Kot).filter(Kot.voucher_id == data.voucher_id).update({Kot.voucher_id: data.new_voucher_id}) -# db.query(Overview).filter(Overview.voucher_id == data.voucher_id).delete() -# db.query(Settlement).filter(Settlement.voucher_id == data.voucher_id).delete() -# db.query(Voucher).filter(Voucher.id == data.voucher_id).delete() -# update_settlements([data.new_voucher_id], db) -# db.commit() -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# def update_settlements(vouchers: List[uuid.UUID], db: Session): -# for v in vouchers: -# voucher: Voucher = db.query(Voucher).filter(Voucher.id == v).first() -# do_update_settlements(voucher, [], db) -# -# -# def check_if_voucher_is_unprinted(voucher_id: uuid.UUID, db: Session) -> None: -# voucher_type: VoucherType = db.query(Voucher.voucher_type).filter(Voucher.id == voucher_id).scalar() -# if voucher_type is None: -# raise HTTPException( -# status_code=status.HTTP_404_NOT_FOUND, -# detail="Original bill not found", -# ) -# if voucher_type != VoucherType.KOT: -# raise HTTPException( -# status_code=status.HTTP_403_FORBIDDEN, -# detail="Bill is printed or void.", -# ) diff --git a/luthor/luthor/routers/voucher/receive_payment.py b/luthor/luthor/routers/voucher/receive_payment.py deleted file mode 100644 index 1b5f588..0000000 --- a/luthor/luthor/routers/voucher/receive_payment.py +++ /dev/null @@ -1,67 +0,0 @@ -# import uuid -# -# import barker.schemas.receive_payment as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# 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.master import SettleOption, VoucherType -# from ...models.voucher import Overview, Voucher -# from ...schemas.user_token import UserToken -# from . import do_update_settlements -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("/receive-payment/{id_}") -# def update( -# id_: uuid.UUID, -# data: schemas.ReceivePayment, -# u: bool, # Update table? -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["settle-bill"]), -# ): -# try: -# update_table = u -# amounts = [ -# j for j in data.amounts if j.amount != 0 and j.id_ not in [SettleOption.AMOUNT(), SettleOption.ROUND_OFF()] -# ] -# for i in amounts: -# i.amount = round(i.amount, 0) -# item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first() -# -# if item.voucher_type in [VoucherType.NO_CHARGE, VoucherType.STAFF]: -# item.reason = data.reason.title() -# -# if not do_update_settlements(item, amounts, db): -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Bill amount not fully settled", -# ) -# -# if update_table: -# db.query(Overview).filter(Overview.voucher_id == item.id).delete() -# db.commit() -# return True -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise diff --git a/luthor/luthor/routers/voucher/save.py b/luthor/luthor/routers/voucher/save.py deleted file mode 100644 index 164e115..0000000 --- a/luthor/luthor/routers/voucher/save.py +++ /dev/null @@ -1,179 +0,0 @@ -# import uuid -# -# from datetime import datetime, timedelta -# from typing import Optional -# -# import barker.schemas.voucher as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# from sqlalchemy import and_, func, or_ -# from sqlalchemy.exc import SQLAlchemyError -# from sqlalchemy.orm import Session -# -# from ...core.config import settings -# from ...core.security import get_current_active_user as get_user -# from ...db.session import SessionLocal -# from ...models.master import ProductVersion, VoucherType -# from ...models.voucher import GuestBook, Inventory, InventoryModifier, Kot, Voucher -# from ...printing.bill import print_bill -# from ...printing.kot import print_kot -# from ...routers.voucher import ( -# check_permissions, -# do_update_settlements, -# do_update_table, -# get_bill_id, -# get_guest_book, -# get_tax, -# happy_hour_has_discount, -# happy_hour_items_balanced, -# ) -# from ...schemas.user_token import UserToken -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("/save") -# def save( -# data: schemas.VoucherIn, -# u: bool, # Update table? -# p: int, # Print type -# g: Optional[uuid.UUID] = None, # Guest book id -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user), -# ): -# try: -# update_table = u -# voucher_type = VoucherType(p) -# guest_book = get_guest_book(g, db) -# item: Voucher = do_save(data, voucher_type, guest_book, db, user) -# if update_table: -# do_update_table(item, guest_book, db) -# db.commit() -# print_kot(item.id, db) -# if item.voucher_type != VoucherType.KOT: -# print_bill(item.id, db) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# def do_save( -# data: schemas.VoucherIn, -# voucher_type: VoucherType, -# guest_book: GuestBook, -# db: Session, -# user: UserToken, -# ): -# now = datetime.now() -# product_date = (now - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date() -# check_permissions(None, voucher_type, user.permissions) -# -# bill_id = get_bill_id(voucher_type, db) -# kot_id = db.query(func.coalesce(func.max(Voucher.kot_id), 0) + 1).scalar() -# -# item = Voucher( -# now, -# guest_book.pax if guest_book is not None else data.pax, -# bill_id, -# kot_id, -# data.table.id_, -# data.customer.id_ if data.customer is not None else None, -# voucher_type, -# user.id_, -# ) -# db.add(item) -# for k in data.kots: -# if not len(k.inventories): -# continue -# if not happy_hour_items_balanced(k.inventories): -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Happy hour products are not balanced.", -# ) -# if happy_hour_has_discount(k.inventories): -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Discount is not allowed on happy hour products.", -# ) -# code = db.query(func.coalesce(func.max(Kot.code), 0) + 1).scalar() -# kot = Kot(item.id, code, item.food_table_id, item.date, item.user_id) -# item.kots.append(kot) -# db.add(kot) -# for index, i in enumerate(k.inventories): -# if i.quantity == 0: -# continue -# total_quantity = round( -# sum(inv.quantity for ko in data.kots for inv in ko.inventories if inv.product.id_ == i.product.id_), -# 2, -# ) -# product: ProductVersion = ( -# db.query(ProductVersion) -# .filter( -# and_( -# ProductVersion.product_id == i.product.id_, -# or_( -# ProductVersion.valid_from == None, # noqa: E711 -# ProductVersion.valid_from <= product_date, -# ), -# or_( -# ProductVersion.valid_till == None, # noqa: E711 -# ProductVersion.valid_till >= product_date, -# ), -# ) -# ) -# .first() -# ) -# if total_quantity < 0: -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail=f"Quantity of {product.full_name} cannot be less than 0", -# ) -# if round(i.quantity, 2) < 0: -# if "edit-printed-product" not in user.permissions: -# raise HTTPException( -# status_code=status.HTTP_403_FORBIDDEN, -# detail=f"You are not allowed to delete printed products." -# f"\n In this case {product.full_name}", -# ) -# tax_rate = get_tax(product.sale_category.tax.rate, voucher_type) -# inv = Inventory( -# kot.id, -# product.product_id, -# round(i.quantity, 2), -# product.price, -# round(min(i.discount, product.sale_category.discount_limit), 5), -# i.is_happy_hour, -# product.sale_category.tax_id, -# tax_rate, -# index, -# ) -# kot.inventories.append(inv) -# db.add(inv) -# for m in i.modifiers: -# mod = InventoryModifier(None, m.id_, 0) -# inv.modifiers.append(mod) -# db.add(mod) -# db.flush() -# do_update_settlements(item, [], db) -# if len(item.kots) == 0 or len(item.kots[0].inventories) == 0: -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Please add some products", -# ) -# return item diff --git a/luthor/luthor/routers/voucher/show.py b/luthor/luthor/routers/voucher/show.py deleted file mode 100644 index 0f218f5..0000000 --- a/luthor/luthor/routers/voucher/show.py +++ /dev/null @@ -1,207 +0,0 @@ -# import re -# import uuid -# -# from datetime import date -# from typing import Optional -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# from sqlalchemy import and_, or_ -# 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 FoodTable, ProductVersion, VoucherType -# from ...models.voucher import GuestBook, Overview, Voucher -# from ...schemas.user_token import UserToken -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.get("/from-id/{id_}") -# def from_id( -# id_: str, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user), -# ): -# item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first() -# return voucher_info(item, db) -# -# -# @router.get("/from-bill/{id_}") -# def from_bill( -# id_: str, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user), -# ): -# item: Voucher = db.query(Voucher) -# if re.compile(r"^\d{2,}-\d{4}$").match(id_): -# item = item.filter( -# Voucher.bill_id == int(id_.replace("-", "")), Voucher.voucher_type == VoucherType.REGULAR_BILL -# ) -# elif re.compile(r"^K-\d+$").match(id_): -# item = item.filter( -# Voucher.kot_id == int(id_.replace("K-", "")), -# Voucher.voucher_type == VoucherType.KOT, -# ) -# elif re.compile(r"^NC-\d+$").match(id_): -# item = item.filter( -# Voucher.bill_id == int(id_.replace("NC-", "")), -# Voucher.voucher_type == VoucherType.NO_CHARGE, -# ) -# elif re.compile(r"^ST-\d+$").match(id_): -# item = item.filter( -# Voucher.bill_id == int(id_.replace("ST-", "")), -# Voucher.voucher_type == VoucherType.STAFF, -# ) -# else: -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Bill Number is invalid", -# ) -# item = item.first() -# if item is None: -# raise HTTPException( -# status_code=status.HTTP_404_NOT_FOUND, -# detail="Bill not found", -# ) -# return voucher_info(item, db) -# -# -# @router.get("/from-table/{id_}") -# def from_table( -# id_: str, # table id -# v: Optional[uuid.UUID] = None, # voucher id -# g: Optional[uuid.UUID] = None, # guest id -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user), -# ): -# if v is not None: -# item = ( -# db.query(Overview) -# .filter( -# Overview.voucher_id == v, -# Overview.food_table_id == id_, -# ) -# .first() -# ) -# if item is None: -# raise HTTPException( -# status_code=status.HTTP_404_NOT_FOUND, -# detail="Voucher not found", -# ) -# else: -# return voucher_info(item.voucher, db) -# table = db.query(FoodTable).filter(FoodTable.id == id_).first() -# if g is not None: -# guest = db.query(GuestBook).filter(GuestBook.id == g).first() -# else: -# guest = None -# return voucher_blank(table, guest) -# -# -# def voucher_product(product_id: uuid.UUID, date_: date, is_happy_hour: bool, db: Session): -# product: ProductVersion = ( -# db.query(ProductVersion) -# .filter( -# and_( -# ProductVersion.product_id == product_id, -# or_( -# ProductVersion.valid_from == None, # noqa: E711 -# ProductVersion.valid_from <= date_, -# ), -# or_( -# ProductVersion.valid_till == None, # noqa: E711 -# ProductVersion.valid_till >= date_, -# ), -# ) -# ) -# .first() -# ) -# -# return { -# "id": product_id, -# "name": ("H H " if is_happy_hour else "") + product.full_name, -# "menuCategory": { -# "id": product.menu_category_id, -# "name": product.menu_category.name, -# }, -# "saleCategory": { -# "id": product.sale_category_id, -# "name": product.sale_category.name, -# "discountLimit": product.sale_category.discount_limit, -# }, -# } -# -# -# def voucher_info(item: Voucher, db: Session): -# return { -# "id": item.id, -# "date": item.date.strftime("%H:%M"), -# "dateTip": item.date.strftime("%d-%b-%Y %H:%M:%S"), -# "pax": item.pax, -# "user": {"id": item.user_id, "name": item.user.name}, -# "creationDate": item.creation_date.strftime("%H:%M"), -# "creationDateTip": item.creation_date.strftime("%d-%b-%Y %H:%M:%S"), -# "lastEditDate": item.last_edit_date.strftime("%H:%M"), -# "lastEditDateTip": item.last_edit_date.strftime("%d-%b-%Y %H:%M:%S"), -# "billId": item.full_bill_id, -# "table": {"id": item.food_table_id, "name": item.food_table.name}, -# "customer": {"id": item.customer_id, "name": item.customer.name} if item.customer is not None else None, -# "settlements": [], -# "narration": item.narration, -# "reason": item.reason, -# "voucherType": item.voucher_type, -# "kotId": item.kot_id, -# "kots": [ -# { -# "id": k.id, -# "code": k.code, -# "date": k.date.strftime("%d-%b-%Y %H:%M:%S"), -# "user": {"id": k.user_id, "name": k.user.name}, -# "inventories": [ -# { -# "id": i.id, -# "sortOrder": i.sort_order, -# "product": voucher_product(i.product_id, item.date.date(), i.is_happy_hour, db), -# "quantity": i.quantity, -# "price": i.price, -# "isHappyHour": i.is_happy_hour, -# "taxRate": i.tax_rate, -# "tax": {"id": i.tax_id, "name": i.tax.name}, -# "discount": i.discount, -# "modifiers": [ -# { -# "id": m.modifier.id, -# "name": m.modifier.name, -# "price": m.price, -# } -# for m in i.modifiers -# ], -# } -# for i in k.inventories -# ], -# } -# for k in item.kots -# ], -# "reprints": [], -# } -# -# -# def voucher_blank(table: FoodTable, guest: Optional[GuestBook]): -# return { -# "pax": table.seats if guest is None else guest.pax, -# "table": {"id": table.id, "name": table.name}, -# "voucherType": VoucherType.KOT, -# "customer": {"id": guest.customer_id, "name": guest.customer.name} if guest is not None else None, -# "kots": [], -# } diff --git a/luthor/luthor/routers/voucher/split.py b/luthor/luthor/routers/voucher/split.py deleted file mode 100644 index fa2f377..0000000 --- a/luthor/luthor/routers/voucher/split.py +++ /dev/null @@ -1,204 +0,0 @@ -# import uuid -# -# from collections import defaultdict -# from datetime import datetime -# from decimal import Decimal -# from typing import List, Optional -# -# import barker.schemas.split as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# from sqlalchemy import func -# 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.master import SettleOption, VoucherType -# from ...models.voucher import Inventory, InventoryModifier, Kot, Overview, Voucher -# from ...routers.voucher import ( -# check_permissions, -# do_update_settlements, -# do_update_table, -# get_bill_id, -# ) -# from ...schemas.receive_payment import ReceivePaymentItem as SettleSchema -# from ...schemas.user_token import UserToken -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("/split-bill/{id_}") -# def split( -# id_: uuid.UUID, -# data: schemas.Split, -# u: bool, # Update table? -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["split-bill"]), -# ): -# try: -# now = datetime.now() -# update_table = u -# item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first() -# item.bill_id = None -# original_voucher_type = item.voucher_type -# item.voucher_type = VoucherType.VOID -# item.reason = "Bill Split" -# do_update_settlements(item, [SettleSchema(id=SettleOption.VOID(), amount=round(item.amount))], db) -# if update_table: -# db.query(Overview).filter(Overview.voucher_id == item.id).delete() -# check_permissions(None, item.voucher_type, user.permissions) -# -# one_inventories = [i for k in item.kots for i in k.inventories if i.id in data.inventories] -# two_inventories = [i for k in item.kots for i in k.inventories if i.id not in data.inventories] -# -# one = save( -# one_inventories, -# now, -# original_voucher_type, -# 0, -# data.table_id, -# item.customer_id, -# user.id_, -# db, -# ) -# if update_table: -# do_update_table(one, None, db) -# two = save( -# two_inventories, -# now, -# original_voucher_type, -# item.pax, -# item.food_table_id, -# item.customer_id, -# user.id_, -# db, -# ) -# if update_table: -# do_update_table(two, None, db) -# db.commit() -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise -# -# -# def save( -# inventories: List[Inventory], -# now: datetime, -# voucher_type: VoucherType, -# pax: int, -# table_id: uuid.UUID, -# customer_id: Optional[uuid.UUID], -# user_id: uuid.UUID, -# db: Session, -# ): -# if not are_product_quantities_positive(inventories): -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Quantity of a product is negative", -# ) -# if len(inventories) == 0: -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="No inventories selected", -# ) -# if happy_hour_items_more_than_regular(inventories): -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="When product has happy hours\n" -# "Minimum same number of regular items also needed in the whole bill.", -# ) -# bill_id = get_bill_id(voucher_type, db) -# kot_id = db.query(func.coalesce(func.max(Voucher.kot_id), 0) + 1).scalar() -# -# item: Voucher = Voucher(now, pax, bill_id, kot_id, table_id, customer_id, voucher_type, user_id) -# db.add(item) -# for split_inventories in split_into_kots(inventories): -# if not happy_hour_items_balanced(split_inventories): -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Happy hour products are not balanced.", -# ) -# code = db.query(func.coalesce(func.max(Kot.code), 0) + 1).scalar() -# kot = Kot(item.id, code, item.food_table_id, item.date, item.user_id) -# item.kots.append(kot) -# db.add(kot) -# db.flush() -# for old_inventory in split_inventories: -# inv = Inventory( -# kot.id, -# old_inventory.product_id, -# old_inventory.quantity, -# old_inventory.price, -# old_inventory.discount, -# old_inventory.is_happy_hour, -# old_inventory.tax_id, -# old_inventory.tax_rate, -# old_inventory.sort_order, -# ) -# kot.inventories.append(inv) -# db.add(inv) -# for m in old_inventory.modifiers: -# mod = InventoryModifier(None, m.modifier_id, m.price) -# inv.modifiers.append(mod) -# db.add(mod) -# db.flush() -# do_update_settlements(item, [], db) -# db.flush() -# return item -# -# -# def split_into_kots(inventories: List[Inventory]) -> list: -# kots = defaultdict(list) -# for item in inventories: -# kots[item.kot_id].append(item) -# return [k for k in kots.values() if len(k) > 0] -# -# -# def happy_hour_items_balanced(inventories: List[Inventory]) -> bool: -# happy = set((i.product_id, i.quantity) for i in inventories if i.is_happy_hour) -# products = set(i.product_id for i in inventories if i.is_happy_hour) -# other = set((i.product_id, i.quantity) for i in inventories if not i.is_happy_hour and i.product_id in products) -# return happy == other -# -# -# def are_product_quantities_positive(inventories: List[Inventory]) -> bool: -# quantities = defaultdict(Decimal) -# for i in inventories: -# key = (i.product_id, i.is_happy_hour) -# quantities[key] += i.quantity -# for i in quantities.values(): -# if i < 0: -# return False -# return True -# -# -# def happy_hour_items_more_than_regular(invs: List[Inventory]) -> bool: -# inventories = {} -# for inventory in invs: -# if inventory.product_id not in inventories: -# inventories[inventory.product_id] = {"normal": Decimal(0), "happy": Decimal(0)} -# if inventory.is_happy_hour: -# inventories[inventory.product_id]["happy"] += inventory.quantity -# else: -# inventories[inventory.product_id]["normal"] += inventory.quantity -# for value in inventories.values(): -# if value["happy"] > value["normal"]: -# return True -# return False diff --git a/luthor/luthor/routers/voucher/update.py b/luthor/luthor/routers/voucher/update.py deleted file mode 100644 index 01625f6..0000000 --- a/luthor/luthor/routers/voucher/update.py +++ /dev/null @@ -1,190 +0,0 @@ -# import uuid -# -# from datetime import datetime, timedelta -# from typing import Optional -# -# import barker.schemas.voucher as schemas -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# from sqlalchemy import and_, func, or_ -# from sqlalchemy.exc import SQLAlchemyError -# from sqlalchemy.orm import Session -# -# from ...core.config import settings -# from ...core.security import get_current_active_user as get_user -# from ...db.session import SessionLocal -# from ...models.master import ProductVersion, VoucherType -# from ...models.voucher import Inventory, InventoryModifier, Kot, Voucher -# from ...printing.bill import print_bill -# from ...printing.kot import print_kot -# from ...routers.voucher import ( -# check_permissions, -# do_update_settlements, -# do_update_table, -# get_bill_id, -# get_guest_book, -# get_tax, -# happy_hour_has_discount, -# happy_hour_items_balanced, -# happy_hour_items_more_than_regular, -# ) -# from ...schemas.user_token import UserToken -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.put("/update/{id_}") -# def update( -# id_: uuid.UUID, -# data: schemas.VoucherIn, -# u: bool, # Update table? -# p: int, # Print type -# g: Optional[uuid.UUID] = None, # Guest book id -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user), -# ): -# try: -# now = datetime.now() -# product_date = (now - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date() -# update_table = u -# voucher_type = VoucherType(p) -# guest_book = get_guest_book(g, db) -# need_to_print_kot = False -# -# item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first() -# -# check_permissions(item, voucher_type, user.permissions) -# -# if guest_book is not None: -# item.pax = guest_book.pax -# item.food_table_id = data.table.id_ -# if data.customer is not None: -# item.customer_id = data.customer.id_ -# if item.voucher_type != VoucherType.KOT: -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail="Internal error, reprints should not reach here", -# ) -# if item.voucher_type == VoucherType.KOT and voucher_type != VoucherType.KOT: -# item.date = now -# item.bill_id = get_bill_id(voucher_type, db) -# item.voucher_type = voucher_type -# item.user_id = user.id_ -# item.last_edit_date = now -# if happy_hour_items_more_than_regular(data.kots): -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="When product has happy hours\n" -# "Minimum same number of regular items also needed in the whole bill.", -# ) -# for k in item.kots: -# for i in k.inventories: -# i.tax_rate = get_tax(i.tax_rate, voucher_type) -# # TODO: Need to check from the database product for the max discount -# # However simple relationship does not work as we need the product validity as well -# # Still we should not fret too much as we are checking this in the frontend. -# i.discount = next( -# round(inv.discount, 5) for ko in data.kots for inv in ko.inventories if inv.id_ == i.id -# ) -# for k in data.kots: -# if happy_hour_has_discount(k.inventories): -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Discount is not allowed on happy hour products.", -# ) -# if not happy_hour_items_balanced(k.inventories): -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail="Happy hour products are not balanced.", -# ) -# for k in (k for k in data.kots if k.id_ is None and len(k.inventories) > 0): -# need_to_print_kot = True -# code = db.query(func.coalesce(func.max(Kot.code), 0) + 1).scalar() -# kot = Kot(item.id, code, item.food_table_id, now, item.user_id) -# item.kots.append(kot) -# db.add(kot) -# for index, i in enumerate(k.inventories): -# product: ProductVersion = ( -# db.query(ProductVersion) -# .filter( -# and_( -# ProductVersion.product_id == i.product.id_, -# or_( -# ProductVersion.valid_from == None, # noqa: E711 -# ProductVersion.valid_from <= product_date, -# ), -# or_( -# ProductVersion.valid_till == None, # noqa: E711 -# ProductVersion.valid_till >= product_date, -# ), -# ) -# ) -# .first() -# ) -# if round(i.quantity, 2) < 0: -# if "edit-printed-product" not in user.permissions: -# raise HTTPException( -# status_code=status.HTTP_403_FORBIDDEN, -# detail=f"You are not allowed to delete printed products." -# f"\n In this case {product.full_name}", -# ) -# minimum = round( -# sum( -# inv.quantity -# for ko in item.kots -# for inv in ko.inventories -# if ko.id and inv.product_id == product.id -# ) -# * -1, -# 2, -# ) -# if round(i.quantity, 2) < minimum: -# raise HTTPException( -# status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, -# detail=f"Quantity of {product.full_name} cannot be less than {minimum}", -# ) -# tax_rate = get_tax(product.sale_category.tax.rate, voucher_type) -# inv = Inventory( -# kot.id, -# product.product_id, -# round(i.quantity, 2), -# product.price, -# round(min(i.discount, product.sale_category.discount_limit), 5), -# i.is_happy_hour, -# product.sale_category.tax_id, -# tax_rate, -# index, -# ) -# kot.inventories.append(inv) -# db.add(inv) -# for m in i.modifiers: -# mod = InventoryModifier(None, m.id_, 0) -# inv.modifiers.append(mod) -# db.add(mod) -# do_update_settlements(item, [], db) -# if update_table: -# do_update_table(item, guest_book, db) -# db.commit() -# if need_to_print_kot: -# print_kot(item.id, db) -# if item.voucher_type != VoucherType.KOT: -# print_bill(item.id, db) -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise diff --git a/luthor/luthor/routers/voucher/void.py b/luthor/luthor/routers/voucher/void.py deleted file mode 100644 index 444eb76..0000000 --- a/luthor/luthor/routers/voucher/void.py +++ /dev/null @@ -1,55 +0,0 @@ -# import uuid -# -# from fastapi import APIRouter, Depends, HTTPException, Security, status -# 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.master import SettleOption, VoucherType -# from ...models.voucher import Overview, Voucher -# from ...schemas.receive_payment import ReceivePaymentItem as SettleSchema -# from ...schemas.user_token import UserToken -# from . import do_update_settlements -# -# -# router = APIRouter() -# -# -# # Dependency -# def get_db(): -# try: -# db = SessionLocal() -# yield db -# finally: -# db.close() -# -# -# @router.post("/void-bill/{id_}") -# def void( -# id_: uuid.UUID, -# u: bool, # Update table? -# reason: str, -# db: Session = Depends(get_db), -# user: UserToken = Security(get_user, scopes=["void-bill"]), -# ): -# try: -# item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first() -# item.reason = reason -# item.bill_id = None -# item.voucher_type = VoucherType.VOID -# do_update_settlements(item, [SettleSchema(id=SettleOption.VOID(), amount=round(item.amount))], db) -# -# if u: # Update table -# db.query(Overview).filter(Overview.voucher_id == item.id).delete() -# db.commit() -# return True -# except SQLAlchemyError as e: -# db.rollback() -# raise HTTPException( -# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -# detail=str(e), -# ) -# except Exception: -# db.rollback() -# raise diff --git a/luthor/luthor/schemas/discount_report.py b/luthor/luthor/schemas/discount_report.py deleted file mode 100644 index 9617fcd..0000000 --- a/luthor/luthor/schemas/discount_report.py +++ /dev/null @@ -1,39 +0,0 @@ -from datetime import date, datetime -from decimal import Decimal -from typing import List - -from pydantic import BaseModel, validator - -from . import to_camel - - -class DiscountReportItem(BaseModel): - name: str - amount: Decimal - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class DiscountReport(BaseModel): - start_date: date - finish_date: date - amounts: List[DiscountReportItem] - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")} - - @validator("start_date", pre=True) - def parse_start_date(cls, value): - if isinstance(value, date): - return value - return datetime.strptime(value, "%d-%b-%Y").date() - - @validator("finish_date", pre=True) - def parse_finish_date(cls, value): - if isinstance(value, date): - return value - return datetime.strptime(value, "%d-%b-%Y").date() diff --git a/luthor/luthor/schemas/guest_book.py b/luthor/luthor/schemas/guest_book.py deleted file mode 100644 index 9ea3a3d..0000000 --- a/luthor/luthor/schemas/guest_book.py +++ /dev/null @@ -1,79 +0,0 @@ -import uuid - -from datetime import date, datetime -from typing import List, Optional - -from pydantic import BaseModel, Field, validator - -from . import to_camel - - -class GuestBookIn(BaseModel): - name: str - phone: str - address: str - pax: int = Field(ge=0) - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel - - -class GuestBook(GuestBookIn): - id_: uuid.UUID - date_: datetime - - @validator("date_", pre=True) - def parse_date(cls, value): - if isinstance(value, datetime): - return value - return datetime.strptime(value, "%d-%b-%Y %H:%M") - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel - json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M")} - - -class GuestBookListItem(BaseModel): - id_: uuid.UUID - serial: int - name: str - phone: str - pax: int - date_: datetime - status: Optional[str] - table_id: Optional[uuid.UUID] - voucher_id: Optional[uuid.UUID] - table_name: Optional[str] - - @validator("date_", pre=True) - def parse_date(cls, value): - if isinstance(value, datetime): - return value - return datetime.strptime(value, "%d-%b-%Y %H:%M") - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel - json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")} - - -class GuestBookList(BaseModel): - date_: date - list: List[GuestBookListItem] - - @validator("date_", pre=True) - def parse_date(cls, value): - if isinstance(value, date): - return value - return datetime.strptime(value, "%d-%b-%Y").date() - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel - json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")} diff --git a/luthor/luthor/schemas/header_footer.py b/luthor/luthor/schemas/header_footer.py deleted file mode 100644 index 49a63bc..0000000 --- a/luthor/luthor/schemas/header_footer.py +++ /dev/null @@ -1,14 +0,0 @@ -import uuid - -from pydantic import BaseModel - -from . import to_camel - - -class HeaderFooter(BaseModel): - id_: uuid.UUID - name: str - text: str - - class Config: - alias_generator = to_camel diff --git a/luthor/luthor/schemas/login_history.py b/luthor/luthor/schemas/login_history.py deleted file mode 100644 index b985576..0000000 --- a/luthor/luthor/schemas/login_history.py +++ /dev/null @@ -1,17 +0,0 @@ -import uuid - -from datetime import datetime - -from barker.schemas import to_camel -from pydantic import BaseModel - - -class LoginHistory(BaseModel): - id_: uuid.UUID - user_id: uuid.UUID - client_id: uuid.UUID - date: datetime - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel diff --git a/luthor/luthor/schemas/master.py b/luthor/luthor/schemas/master.py deleted file mode 100644 index 40fd573..0000000 --- a/luthor/luthor/schemas/master.py +++ /dev/null @@ -1,78 +0,0 @@ -import uuid - -from datetime import date, datetime -from decimal import Decimal -from typing import Optional - -from pydantic import BaseModel, Field, validator - -from . import to_camel - - -class AccountBase(BaseModel): - name: str = Field(..., min_length=1) - is_starred: bool - is_active: bool - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel - - -class AccountIn(AccountBase): - type: int - is_reconcilable: bool - - -class Account(AccountIn): - id_: uuid.UUID - code: int - is_fixture: bool - - -class EmployeeIn(AccountBase): - designation: str - salary: int = Field(ge=0) - points: Decimal = Field(ge=0, lt=1000, multiple_of=0.01) - joining_date: date - leaving_date: Optional[date] - - @validator("joining_date", pre=True) - def parse_joining_date(cls, value): - return datetime.strptime(value, "%d-%b-%Y").date() - - @validator("leaving_date", pre=True) - def parse_leaving_date(cls, value): - if value is None or value == "": - return None - else: - return datetime.strptime(value, "%d-%b-%Y").date() - - @validator("leaving_date") - def leaving_date_more_than_joining_date(cls, v, values, **kwargs): - if values["is_active"]: - return None - if v < values["joining_date"]: - raise ValueError("Leaving Date cannot be less than Joining Date") - return v - - -class Employee(EmployeeIn): - id_: uuid.UUID - code: int - is_fixture: bool - - -class DbSetting(BaseModel): - id_: uuid.UUID - name: str - data: bytes - - -class AccountType(BaseModel): - id_: int - name: str - - class Config: - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/menu_category.py b/luthor/luthor/schemas/menu_category.py deleted file mode 100644 index ee25db2..0000000 --- a/luthor/luthor/schemas/menu_category.py +++ /dev/null @@ -1,44 +0,0 @@ -import uuid - -from typing import List, Optional - -from pydantic import BaseModel, Field - -from . import to_camel -from .product_link import ProductLink - - -class MenuCategoryIn(BaseModel): - name: str = Field(..., min_length=1) - is_active: bool - is_fixture: bool - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class MenuCategory(MenuCategoryIn): - id_: uuid.UUID - sort_order: int - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class MenuCategoryBlank(MenuCategoryIn): - name: str - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class MenuCategoryLink(BaseModel): - id_: uuid.UUID = Field(...) - name: Optional[str] - products: Optional[List[ProductLink]] - - class Config: - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/merge_move.py b/luthor/luthor/schemas/merge_move.py deleted file mode 100644 index bcd00a9..0000000 --- a/luthor/luthor/schemas/merge_move.py +++ /dev/null @@ -1,45 +0,0 @@ -import uuid - -from pydantic import BaseModel - -from . import to_camel - - -class MergeKot(BaseModel): - voucher_id: uuid.UUID - kot_id: uuid.UUID - table_id: uuid.UUID - new_voucher_id: uuid.UUID - - class Config: - alias_generator = to_camel - fields = {"id_": "id"} - - -class MoveKot(BaseModel): - voucher_id: uuid.UUID - kot_id: uuid.UUID - table_id: uuid.UUID - - class Config: - alias_generator = to_camel - fields = {"id_": "id"} - - -class MergeTable(BaseModel): - voucher_id: uuid.UUID - table_id: uuid.UUID - new_voucher_id: uuid.UUID - - class Config: - alias_generator = to_camel - fields = {"id_": "id"} - - -class MoveTable(BaseModel): - voucher_id: uuid.UUID - table_id: uuid.UUID - - class Config: - alias_generator = to_camel - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/modifier.py b/luthor/luthor/schemas/modifier.py deleted file mode 100644 index 715899c..0000000 --- a/luthor/luthor/schemas/modifier.py +++ /dev/null @@ -1,44 +0,0 @@ -import uuid - -from decimal import Decimal -from typing import Optional - -from pydantic import BaseModel, Field - -from . import to_camel -from .modifier_category import ModifierCategoryLink - - -class ModifierIn(BaseModel): - name: str = Field(..., min_length=1) - show_in_bill: bool - price: Decimal = Field(ge=0, multiple_of=0.01, default=0) - is_active: bool - modifier_category: ModifierCategoryLink - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel - - -class Modifier(ModifierIn): - id_: uuid.UUID - - -class ModifierLink(BaseModel): - id_: uuid.UUID = Field(...) - name: Optional[str] - - class Config: - fields = {"id_": "id"} - - -class ModifierBlank(ModifierIn): - name: str - modifier_category: Optional[ModifierCategoryLink] - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel diff --git a/luthor/luthor/schemas/modifier_category.py b/luthor/luthor/schemas/modifier_category.py deleted file mode 100644 index f69d44c..0000000 --- a/luthor/luthor/schemas/modifier_category.py +++ /dev/null @@ -1,46 +0,0 @@ -import uuid - -from typing import List, Optional - -from pydantic import BaseModel, Field - -from . import to_camel -from .menu_category import MenuCategoryLink - - -class ModifierCategoryIn(BaseModel): - name: str = Field(..., min_length=1) - minimum: int = Field(ge=0) - maximum: Optional[int] = Field(ge=0) - is_active: bool - menu_categories: Optional[List[MenuCategoryLink]] - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class ModifierCategory(ModifierCategoryIn): - id_: uuid.UUID - sort_order: int - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel - - -class ModifierCategoryBlank(ModifierCategoryIn): - name: str - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class ModifierCategoryLink(BaseModel): - id_: uuid.UUID = Field(...) - name: Optional[str] - - class Config: - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/printer.py b/luthor/luthor/schemas/printer.py deleted file mode 100644 index 7057c90..0000000 --- a/luthor/luthor/schemas/printer.py +++ /dev/null @@ -1,41 +0,0 @@ -import uuid - -from typing import Optional - -from pydantic import BaseModel, Field - -from . import to_camel - - -class PrinterIn(BaseModel): - name: str = Field(..., min_length=1) - address: str = Field(..., min_length=1) - cut_code: Optional[str] - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class Printer(PrinterIn): - id_: uuid.UUID - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class PrinterBlank(PrinterIn): - name: str - address: str - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class PrinterLink(BaseModel): - id_: uuid.UUID = Field(...) - - class Config: - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/product.py b/luthor/luthor/schemas/product.py deleted file mode 100644 index 7d64ab9..0000000 --- a/luthor/luthor/schemas/product.py +++ /dev/null @@ -1,45 +0,0 @@ -import uuid - -from decimal import Decimal -from typing import Optional - -from pydantic import BaseModel, Field - -from . import to_camel -from .menu_category import MenuCategoryLink -from .sale_category import SaleCategoryLink - - -class ProductIn(BaseModel): - name: str = Field(..., min_length=1) - units: str - menu_category: MenuCategoryLink = Field(...) - sale_category: SaleCategoryLink = Field(...) - price: Decimal # = Field(ge=0, multiple_of=0.01, default=0) - has_happy_hour: bool - is_not_available: bool - quantity: Decimal = Field(ge=0, multiple_of=0.01, default=0) - is_active: bool - sort_order: int - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class Product(ProductIn): - id_: uuid.UUID - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class ProductBlank(ProductIn): - name: str - menu_category: Optional[MenuCategoryLink] - sale_category: Optional[SaleCategoryLink] - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel diff --git a/luthor/luthor/schemas/product_link.py b/luthor/luthor/schemas/product_link.py deleted file mode 100644 index b92d147..0000000 --- a/luthor/luthor/schemas/product_link.py +++ /dev/null @@ -1,14 +0,0 @@ -import uuid - -from typing import Optional - -from pydantic import BaseModel, Field - - -class ProductLink(BaseModel): - id_: uuid.UUID = Field(...) - name: Optional[str] - enabled: Optional[bool] - - class Config: - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/receive_payment.py b/luthor/luthor/schemas/receive_payment.py deleted file mode 100644 index ff43de6..0000000 --- a/luthor/luthor/schemas/receive_payment.py +++ /dev/null @@ -1,23 +0,0 @@ -from decimal import Decimal -from typing import List - -from pydantic import BaseModel - -from . import to_camel - - -class ReceivePaymentItem(BaseModel): - id_: int - amount: Decimal - - class Config: - fields = {"id_": "id"} - - -class ReceivePayment(BaseModel): - reason: str - amounts: List[ReceivePaymentItem] - - class Config: - alias_generator = to_camel - anystr_strip_whitespace = True diff --git a/luthor/luthor/schemas/sale_category.py b/luthor/luthor/schemas/sale_category.py deleted file mode 100644 index 629b08a..0000000 --- a/luthor/luthor/schemas/sale_category.py +++ /dev/null @@ -1,53 +0,0 @@ -import uuid - -from decimal import Decimal -from typing import Optional - -from pydantic import BaseModel, Field - -from . import to_camel -from .tax import TaxLink - - -class SaleCategoryIn(BaseModel): - name: str = Field(..., min_length=1) - discount_limit: Decimal = Field(ge=0, multiple_of=0.0001, default=0, le=1) - tax: TaxLink = Field(...) - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class SaleCategory(SaleCategoryIn): - id_: uuid.UUID - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class SaleCategoryBlank(SaleCategoryIn): - name: str - tax: Optional[TaxLink] - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class SaleCategoryForDiscount(SaleCategory): - discount: Decimal - tax: Optional[TaxLink] - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class SaleCategoryLink(BaseModel): - id_: uuid.UUID = Field(...) - name: Optional[str] - - class Config: - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/sale_report.py b/luthor/luthor/schemas/sale_report.py deleted file mode 100644 index 21d4c7f..0000000 --- a/luthor/luthor/schemas/sale_report.py +++ /dev/null @@ -1,41 +0,0 @@ -from datetime import date, datetime -from decimal import Decimal -from typing import List - -from pydantic import BaseModel, validator - -from . import to_camel -from .user import UserLink - - -class SaleReportItem(BaseModel): - name: str - amount: Decimal - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class SaleReport(BaseModel): - start_date: date - finish_date: date - amounts: List[SaleReportItem] - user: UserLink - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")} - - @validator("start_date", pre=True) - def parse_start_date(cls, value): - if isinstance(value, date): - return value - return datetime.strptime(value, "%d-%b-%Y").date() - - @validator("finish_date", pre=True) - def parse_finish_date(cls, value): - if isinstance(value, date): - return value - return datetime.strptime(value, "%d-%b-%Y").date() diff --git a/luthor/luthor/schemas/section.py b/luthor/luthor/schemas/section.py deleted file mode 100644 index 1934ac4..0000000 --- a/luthor/luthor/schemas/section.py +++ /dev/null @@ -1,35 +0,0 @@ -import uuid - -from typing import Optional - -from pydantic import BaseModel, Field - - -class SectionIn(BaseModel): - name: str = Field(..., min_length=1) - - class Config: - anystr_strip_whitespace = True - - -class Section(SectionIn): - id_: uuid.UUID - - class Config: - anystr_strip_whitespace = True - fields = {"id_": "id"} - - -class SectionBlank(BaseModel): - name: str - - class Config: - anystr_strip_whitespace = True - - -class SectionLink(BaseModel): - id_: uuid.UUID = Field(...) - name: Optional[str] - - class Config: - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/section_printer.py b/luthor/luthor/schemas/section_printer.py deleted file mode 100644 index 1e27181..0000000 --- a/luthor/luthor/schemas/section_printer.py +++ /dev/null @@ -1,16 +0,0 @@ -from typing import Optional - -from pydantic import BaseModel, Field - -from . import to_camel -from .menu_category import MenuCategoryLink -from .printer import PrinterLink - - -class SectionPrinter(BaseModel): - menu_category: Optional[MenuCategoryLink] - printer: Optional[PrinterLink] - copies: int = Field(ge=0) - - class Config: - alias_generator = to_camel diff --git a/luthor/luthor/schemas/split.py b/luthor/luthor/schemas/split.py deleted file mode 100644 index cf9ed03..0000000 --- a/luthor/luthor/schemas/split.py +++ /dev/null @@ -1,16 +0,0 @@ -import uuid - -from typing import List - -from pydantic import BaseModel - -from . import to_camel - - -class Split(BaseModel): - inventories: List[uuid.UUID] - table_id: uuid.UUID - - class Config: - alias_generator = to_camel - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/table.py b/luthor/luthor/schemas/table.py deleted file mode 100644 index eeaabea..0000000 --- a/luthor/luthor/schemas/table.py +++ /dev/null @@ -1,44 +0,0 @@ -import uuid - -from typing import Optional - -from pydantic import BaseModel, Field - -from . import to_camel -from .section import SectionLink - - -class TableIn(BaseModel): - name: str = Field(..., min_length=1) - seats: int = Field(ge=0) - section: SectionLink - is_active: bool - sort_order: int - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class Table(TableIn): - id_: uuid.UUID - - class Config: - alias_generator = to_camel - - -class TableBlank(TableIn): - name: str - section: Optional[SectionLink] - - class Config: - alias_generator = to_camel - - -class TableLink(BaseModel): - id_: uuid.UUID = Field(...) - name: Optional[str] - - class Config: - fields = {"id_": "id"} - alias_generator = to_camel diff --git a/luthor/luthor/schemas/tax.py b/luthor/luthor/schemas/tax.py deleted file mode 100644 index 518aab1..0000000 --- a/luthor/luthor/schemas/tax.py +++ /dev/null @@ -1,43 +0,0 @@ -import uuid - -from decimal import Decimal -from typing import Optional - -from pydantic import BaseModel, Field - -from . import to_camel - - -class TaxIn(BaseModel): - name: str = Field(..., min_length=1) - rate: Decimal = Field(ge=0, default=0) - is_fixture: bool - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class Tax(TaxIn): - id_: uuid.UUID - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class TaxBlank(TaxIn): - name: str - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class TaxLink(BaseModel): - id_: uuid.UUID = Field(...) - name: Optional[str] - rate: Optional[Decimal] - - class Config: - fields = {"id_": "id"} diff --git a/luthor/luthor/schemas/tax_report.py b/luthor/luthor/schemas/tax_report.py deleted file mode 100644 index 4ae805d..0000000 --- a/luthor/luthor/schemas/tax_report.py +++ /dev/null @@ -1,41 +0,0 @@ -from datetime import date, datetime -from decimal import Decimal -from typing import List - -from pydantic import BaseModel, validator - -from . import to_camel - - -class TaxReportItem(BaseModel): - name: str - tax_rate: Decimal - sale_amount: Decimal - amount: Decimal - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class TaxReport(BaseModel): - start_date: date - finish_date: date - amounts: List[TaxReportItem] - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")} - - @validator("start_date", pre=True) - def parse_start_date(cls, value): - if isinstance(value, date): - return value - return datetime.strptime(value, "%d-%b-%Y").date() - - @validator("finish_date", pre=True) - def parse_finish_date(cls, value): - if isinstance(value, date): - return value - return datetime.strptime(value, "%d-%b-%Y").date() diff --git a/luthor/luthor/schemas/update_product_prices.py b/luthor/luthor/schemas/update_product_prices.py deleted file mode 100644 index b8315c1..0000000 --- a/luthor/luthor/schemas/update_product_prices.py +++ /dev/null @@ -1,35 +0,0 @@ -import uuid - -from datetime import date, datetime -from decimal import Decimal -from typing import List, Optional - -from pydantic import BaseModel, validator - -from . import to_camel - - -class UpdateProductPricesItem(BaseModel): - id: uuid.UUID - name: str - old_price: Decimal - new_price: Decimal - - class Config: - alias_generator = to_camel - - -class UpdateProductPrices(BaseModel): - date_: date - menu_category_id: Optional[uuid.UUID] - items: List[UpdateProductPricesItem] - - class Config: - alias_generator = to_camel - json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")} - - @validator("date_", pre=True) - def parse_date(cls, value): - if isinstance(value, date): - return value - return datetime.strptime(value, "%d-%b-%Y").date() diff --git a/luthor/luthor/schemas/voucher.py b/luthor/luthor/schemas/voucher.py deleted file mode 100644 index e6b691f..0000000 --- a/luthor/luthor/schemas/voucher.py +++ /dev/null @@ -1,68 +0,0 @@ -import uuid - -from decimal import Decimal -from typing import List, Optional - -from pydantic import BaseModel, Field, validator - -from . import to_camel -from .customer import CustomerLink -from .modifier import ModifierLink -from .product_link import ProductLink -from .table import TableLink -from .tax import TaxLink - - -class Inventory(BaseModel): - id_: Optional[uuid.UUID] - product: ProductLink - quantity: Decimal = Field(multiple_of=0.01) - price: Optional[Decimal] - tax: Optional[TaxLink] - tax_rate: Optional[Decimal] - discount: Decimal = Field(ge=0, multiple_of=0.00001, le=1) - is_happy_hour: bool - modifiers: Optional[List[ModifierLink]] - amount: Optional[Decimal] - - class Config: - alias_generator = to_camel - - @validator("amount", always=True) - def calculate_amount(cls, v, values): - is_happy_hour = values["is_happy_hour"] if "is_happy_hour" in values else False - price = values["price"] if "price" in values and not is_happy_hour else 0 - quantity = values["quantity"] if "quantity" in values else 0 - discount = values["discount"] if "discount" in values else 0 - tax_rate = values["tax_rate"] if "tax_rate" in values else 0 - return round(Decimal(price * quantity * (1 - discount) * (1 + tax_rate)), 2) - - -class Kot(BaseModel): - id_: Optional[uuid.UUID] - inventories: List[Inventory] - - class Config: - anystr_strip_whitespace = True - alias_generator = to_camel - - -class VoucherIn(BaseModel): - pax: int - table: TableLink - customer: Optional[CustomerLink] - kots: List[Kot] - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel - - -class Voucher(VoucherIn): - id_: uuid.UUID - - class Config: - fields = {"id_": "id"} - anystr_strip_whitespace = True - alias_generator = to_camel diff --git a/otis/package.json b/otis/package.json index 8b70ab1..ff8db74 100644 --- a/otis/package.json +++ b/otis/package.json @@ -14,43 +14,42 @@ }, "private": true, "dependencies": { - "@angular/animations": "^11.0.5", + "@angular/animations": "^11.0.8", "@angular/cdk": "^11.0.3", - "@angular/common": "^11.0.5", - "@angular/compiler": "^11.0.5", - "@angular/core": "^11.0.5", + "@angular/common": "^11.0.8", + "@angular/compiler": "^11.0.8", + "@angular/core": "^11.0.8", "@angular/flex-layout": "^11.0.0-beta.33", - "@angular/forms": "^11.0.5", + "@angular/forms": "^11.0.8", "@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/platform-browser": "^11.0.8", + "@angular/platform-browser-dynamic": "^11.0.8", + "@angular/router": "^11.0.8", "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", + "@angular-devkit/build-angular": "~0.1100.6", + "@angular-eslint/builder": "1.0.0", + "@angular-eslint/eslint-plugin": "1.0.0", + "@angular-eslint/eslint-plugin-template": "1.0.0", + "@angular-eslint/schematics": "1.0.0", + "@angular-eslint/template-parser": "1.0.0", + "@angular/cli": "^11.0.6", + "@angular/compiler-cli": "^11.0.8", + "@angular/language-service": "^11.0.8", "@types/jasmine": "~3.6.2", - "@types/node": "^14.14.14", - "@typescript-eslint/eslint-plugin": "^4.10.0", - "@typescript-eslint/parser": "^4.10.0", - "eslint": "^7.16.0", - "eslint-config-prettier": "^7.1.0", + "@types/node": "^14.14.20", + "@typescript-eslint/eslint-plugin": "^4.13.0", + "@typescript-eslint/parser": "^4.13.0", + "eslint": "^7.17.0", "eslint-plugin-import": "^2.22.1", - "eslint-plugin-jsdoc": "^30.7.9", + "eslint-plugin-jsdoc": "^31.0.3", "eslint-plugin-prefer-arrow": "1.2.2", - "husky": "^4.3.6", + "husky": "^4.3.7", "jasmine-core": "^3.6.0", "jasmine-spec-reporter": "^6.0.0", "karma": "^5.2.3", @@ -60,7 +59,7 @@ "karma-jasmine-html-reporter": "^1.5.0", "lint-staged": "^10.5.3", "prettier": "^2.2.1", - "standard-version": "^9.0.0", + "standard-version": "^9.1.0", "ts-node": "^9.1.1", "typescript": "~4.0.5" }, diff --git a/otis/src/app/cases/case-detail/case-detail.component.html b/otis/src/app/cases/case-detail/case-detail.component.html index e8e6167..72d22e6 100644 --- a/otis/src/app/cases/case-detail/case-detail.component.html +++ b/otis/src/app/cases/case-detail/case-detail.component.html @@ -42,12 +42,8 @@ fxLayoutGap.lt-md="0px" > - Mobile - - - - Land Line - + Court Case Number +
- Email - + Case Type + + -- Not Applicable -- + + {{ ct.name }} + +
- Address - + Year + + +
+
+ + Connected Cases + + +
+
+ + Appearing for the + + Petitioner + Respondent + + +
+
+ + Forum + + -- Not Applicable -- + + {{ c.name }} + +
+ + Department + + -- Not Applicable -- + + {{ o.name }} + + +
- Department - + Contact Person + + +
+
+ + Court Status + -- Not Applicable -- - - {{ o.name }} + + {{ cs.name }} + + + + + Office Status + + -- Not Applicable -- + + {{ os.name }} + + + +
+
+ + Act + + -- Not Applicable -- + + {{ a.name }} + + + + + Nature + + -- Not Applicable -- + + {{ n.name }} diff --git a/otis/src/app/cases/case-detail/case-detail.component.ts b/otis/src/app/cases/case-detail/case-detail.component.ts index d555dfc..75a04c1 100644 --- a/otis/src/app/cases/case-detail/case-detail.component.ts +++ b/otis/src/app/cases/case-detail/case-detail.component.ts @@ -27,8 +27,14 @@ import { CaseService } from '../case.service'; export class CaseDetailComponent implements OnInit, AfterViewInit { @ViewChild('nameElement', { static: true }) nameElement?: ElementRef; form: FormGroup; + caseTypes: CaseType[] = []; + courts: Court[] = []; departments: Department[] = []; offices: Observable = new Observable(); + courtStatuses: CourtStatus[] = []; + officeStatuses: OfficeStatus[] = []; + acts: Act[] = []; + natures: Nature[] = []; item: Case = new Case(); constructor( @@ -76,8 +82,23 @@ export class CaseDetailComponent implements OnInit, AfterViewInit { ngOnInit() { this.route.data.subscribe((value) => { - const data = value as { item: Case; departments: Department[] }; + const data = value as { + item: Case; + caseTypes: CaseType[]; + courts: Court[]; + departments: Department[]; + courtStatuses: CourtStatus[]; + officeStatuses: OfficeStatus[]; + acts: Act[]; + natures: Nature[]; + }; + this.caseTypes = data.caseTypes; + this.courts = data.courts; this.departments = data.departments; + this.courtStatuses = data.courtStatuses; + this.officeStatuses = data.officeStatuses; + this.acts = data.acts; + this.natures = data.natures; this.showItem(data.item); }); } diff --git a/otis/src/app/cases/cases-routing.module.ts b/otis/src/app/cases/cases-routing.module.ts index fb09422..fda21fa 100644 --- a/otis/src/app/cases/cases-routing.module.ts +++ b/otis/src/app/cases/cases-routing.module.ts @@ -2,9 +2,19 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { ActListResolver } from '../acts/act-list-resolver.service'; import { AuthGuard } from '../auth/auth-guard.service'; import { CaseSourceListResolver } from '../case-sources/case-source-list-resolver.service'; +import { CaseTypeListResolver } from '../case-types/case-type-list-resolver.service'; +import { Case } from '../core/case'; +import { CaseType } from '../core/case-type'; +import { Court } from '../core/court'; +import { Department } from '../core/department'; +import { CourtStatusListResolver } from '../court-statuses/court-status-list-resolver.service'; +import { CourtListResolver } from '../courts/court-list-resolver.service'; import { DepartmentListResolver } from '../departments/department-list-resolver.service'; +import { NatureListResolver } from '../natures/nature-list-resolver.service'; +import { OfficeStatusListResolver } from '../office-statuses/office-status-list-resolver.service'; import { CaseDetailComponent } from './case-detail/case-detail.component'; import { CaseListResolver } from './case-list-resolver.service'; @@ -33,7 +43,13 @@ const advocatesRoutes: Routes = [ }, resolve: { item: CaseResolver, + caseTypes: CaseTypeListResolver, + courts: CourtListResolver, departments: DepartmentListResolver, + courtStatuses: CourtStatusListResolver, + officeStatuses: OfficeStatusListResolver, + acts: ActListResolver, + natures: NatureListResolver, }, }, { @@ -45,7 +61,13 @@ const advocatesRoutes: Routes = [ }, resolve: { item: CaseResolver, + caseTypes: CaseTypeListResolver, + courts: CourtListResolver, departments: DepartmentListResolver, + courtStatuses: CourtStatusListResolver, + officeStatuses: OfficeStatusListResolver, + acts: ActListResolver, + natures: NatureListResolver, }, }, ]; diff --git a/otis/src/app/contacts/contact-detail/contact-detail.component.html b/otis/src/app/contacts/contact-detail/contact-detail.component.html index 4792e77..e2c9126 100644 --- a/otis/src/app/contacts/contact-detail/contact-detail.component.html +++ b/otis/src/app/contacts/contact-detail/contact-detail.component.html @@ -79,14 +79,6 @@ -
-
Department diff --git a/otis/src/environments/environment.prod.ts b/otis/src/environments/environment.prod.ts index efa3356..d110362 100644 --- a/otis/src/environments/environment.prod.ts +++ b/otis/src/environments/environment.prod.ts @@ -1,5 +1,5 @@ export const environment = { production: true, ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry - version: '6.3.0', + version: '1.0.0', }; diff --git a/otis/src/environments/environment.ts b/otis/src/environments/environment.ts index df2ae70..7571df4 100644 --- a/otis/src/environments/environment.ts +++ b/otis/src/environments/environment.ts @@ -5,7 +5,7 @@ export const environment = { production: false, ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry - version: '6.3.0', + version: '1.0.0', }; /*