blacked, isorted, flake8ed and moved to arq/redis from celery/rabbitmq
This commit is contained in:
1 parent
1d6baa9d1d
commit
00fe2410b7
67 files changed
+295
-712
No files matched your search
@@ -5,7 +5,9 @@ DEBUG=true
|
||||
SQLALCHEMY_DATABASE_URI=
|
||||
MODULE_NAME=barker.main
|
||||
PROJECT_NAME=barker
|
||||
RABBITMQ_URI=
|
||||
|
||||
REDIS_HOST=
|
||||
REDIS_PORT=6379
|
||||
|
||||
# openssl rand -hex 32
|
||||
SECRET_KEY=
|
||||
|
||||
@@ -25,4 +25,4 @@
|
||||
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\u-ProductGroupModifiers.sql
|
||||
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\v-Reprints.sql
|
||||
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\w-Settings.sql
|
||||
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\x-VoucherSettlements.sql
|
||||
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\x-VoucherSettlements.sql
|
||||
@@ -6,4 +6,4 @@ update permissions set name = 'Sale Report' where name = 'Sales Analysis';
|
||||
update permissions set name = 'Tax Report' where name = 'Tax Analysis';
|
||||
delete from role_permissions where permission_id = (select id from permissions where name = 'Void or Reprinted Bill Report');
|
||||
delete from permissions where name = 'Void or Reprinted Bill Report';
|
||||
update settlements as s set settled = 9 from vouchers v where v.id = s.voucher_id and v.voucher_type = 5 and s.settled = 1;
|
||||
update settlements as s set settled = 9 from vouchers v where v.id = s.voucher_id and v.voucher_type = 5 and s.settled = 1;
|
||||
@@ -24,7 +24,7 @@ sudo apt-get install libpq-dev python3-dev
|
||||
```
|
||||
|
||||
## Setup the virutal environment
|
||||
1. Create the virtual environment
|
||||
1. Create the virtual environment
|
||||
**Currently the ensurepip is broken in Python 3.4 / Ubuntu 14.04, therefore --without-pip is needed.**
|
||||
```bash
|
||||
pyvenv-3.4 env --without-pip --system-site-packages
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
[flake8]
|
||||
max-line-length = 120
|
||||
exclude = .git,__pycache__,__init__.py,.mypy_cache,.pytest_cache
|
||||
@@ -0,0 +1,3 @@
|
||||
*.pyc
|
||||
*/__pycache__/
|
||||
*.egg-info/
|
||||
@@ -0,0 +1,29 @@
|
||||
# See https://pre-commit.com for more information
|
||||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 20.8b1
|
||||
hooks:
|
||||
- id: black
|
||||
|
||||
- repo: https://gitlab.com/pycqa/flake8
|
||||
rev: 3.8.4
|
||||
hooks:
|
||||
- id: flake8
|
||||
args: ['--config=barker/.flake8']
|
||||
|
||||
- repo: https://github.com/timothycrosley/isort
|
||||
rev: 5.6.2
|
||||
hooks:
|
||||
- id: isort
|
||||
additional_dependencies: [toml]
|
||||
exclude: ^.*/?setup\.py$
|
||||
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v3.2.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-yaml
|
||||
- id: check-added-large-files
|
||||
- id: debug-statements
|
||||
@@ -1 +1 @@
|
||||
Generic single-database configuration.
|
||||
Generic single-database configuration.
|
||||
@@ -61,9 +61,7 @@ def run_migrations_online():
|
||||
)
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection, target_metadata=target_metadata, compare_type=True
|
||||
)
|
||||
context.configure(connection=connection, target_metadata=target_metadata, compare_type=True)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
"""Initial Commit
|
||||
|
||||
Revision ID: 8c06ac60d125
|
||||
Revises:
|
||||
Revises:
|
||||
Create Date: 2020-06-04 08:14:34.132248
|
||||
|
||||
"""
|
||||
import uuid
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
@@ -138,9 +136,7 @@ def upgrade():
|
||||
sa.Column("id", postgresql.UUID(), nullable=False),
|
||||
sa.Column("name", sa.Unicode(length=255), nullable=False),
|
||||
sa.Column("section_id", postgresql.UUID(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["section_id"], ["sections.id"], name=op.f("fk_devices_section_id_sections")
|
||||
),
|
||||
sa.ForeignKeyConstraint(["section_id"], ["sections.id"], name=op.f("fk_devices_section_id_sections")),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_devices")),
|
||||
sa.UniqueConstraint("name", name=op.f("uq_devices_name")),
|
||||
)
|
||||
@@ -199,22 +195,16 @@ def upgrade():
|
||||
["permissions.id"],
|
||||
name=op.f("fk_role_permissions_permission_id_permissions"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["role_id"], ["roles.id"], name=op.f("fk_role_permissions_role_id_roles")
|
||||
),
|
||||
sa.ForeignKeyConstraint(["role_id"], ["roles.id"], name=op.f("fk_role_permissions_role_id_roles")),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_role_permissions")),
|
||||
sa.UniqueConstraint(
|
||||
"permission_id", "role_id", name=op.f("uq_role_permissions_permission_id")
|
||||
),
|
||||
sa.UniqueConstraint("permission_id", "role_id", name=op.f("uq_role_permissions_permission_id")),
|
||||
)
|
||||
op.create_table(
|
||||
"sale_categories",
|
||||
sa.Column("id", postgresql.UUID(), nullable=False),
|
||||
sa.Column("name", sa.Unicode(length=255), nullable=False),
|
||||
sa.Column("tax_id", postgresql.UUID(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["tax_id"], ["taxes.id"], name=op.f("fk_sale_categories_tax_id_taxes")
|
||||
),
|
||||
sa.ForeignKeyConstraint(["tax_id"], ["taxes.id"], name=op.f("fk_sale_categories_tax_id_taxes")),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_sale_categories")),
|
||||
sa.UniqueConstraint("name", name=op.f("uq_sale_categories_name")),
|
||||
)
|
||||
@@ -252,12 +242,8 @@ def upgrade():
|
||||
sa.Column("id", postgresql.UUID(), nullable=False),
|
||||
sa.Column("user_id", postgresql.UUID(), nullable=False),
|
||||
sa.Column("role_id", postgresql.UUID(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["role_id"], ["roles.id"], name=op.f("fk_user_roles_role_id_roles")
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["user_id"], ["users.id"], name=op.f("fk_user_roles_user_id_users")
|
||||
),
|
||||
sa.ForeignKeyConstraint(["role_id"], ["roles.id"], name=op.f("fk_user_roles_role_id_roles")),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_user_roles_user_id_users")),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_user_roles")),
|
||||
sa.UniqueConstraint("user_id", "role_id", name=op.f("uq_user_roles_user_id")),
|
||||
)
|
||||
@@ -312,13 +298,9 @@ def upgrade():
|
||||
["food_tables.id"],
|
||||
name=op.f("fk_vouchers_food_table_id_food_tables"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["user_id"], ["users.id"], name=op.f("fk_vouchers_user_id_users")
|
||||
),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_vouchers_user_id_users")),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_vouchers")),
|
||||
sa.UniqueConstraint(
|
||||
"bill_id", "voucher_type", name=op.f("uq_vouchers_bill_id")
|
||||
),
|
||||
sa.UniqueConstraint("bill_id", "voucher_type", name=op.f("uq_vouchers_bill_id")),
|
||||
sa.UniqueConstraint("kot_id", name=op.f("uq_vouchers_kot_id")),
|
||||
)
|
||||
op.create_index(op.f("ix_vouchers_date"), "vouchers", ["date"], unique=False)
|
||||
@@ -335,12 +317,8 @@ def upgrade():
|
||||
["food_tables.id"],
|
||||
name=op.f("fk_kots_food_table_id_food_tables"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["user_id"], ["users.id"], name=op.f("fk_kots_user_id_users")
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["voucher_id"], ["vouchers.id"], name=op.f("fk_kots_voucher_id_vouchers")
|
||||
),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_kots_user_id_users")),
|
||||
sa.ForeignKeyConstraint(["voucher_id"], ["vouchers.id"], name=op.f("fk_kots_voucher_id_vouchers")),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_kots")),
|
||||
sa.UniqueConstraint("code", name=op.f("uq_kots_code")),
|
||||
)
|
||||
@@ -354,9 +332,7 @@ def upgrade():
|
||||
sa.ForeignKeyConstraint(
|
||||
["modifier_categories_id"],
|
||||
["modifier_categories.id"],
|
||||
name=op.f(
|
||||
"fk_modifier_categories_products_modifier_categories_id_modifier_categories"
|
||||
),
|
||||
name=op.f("fk_modifier_categories_products_modifier_categories_id_modifier_categories"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["product_id"],
|
||||
@@ -403,9 +379,7 @@ def upgrade():
|
||||
sa.Column("date", sa.DateTime(), nullable=False),
|
||||
sa.Column("voucher_id", postgresql.UUID(), nullable=False),
|
||||
sa.Column("user_id", postgresql.UUID(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["user_id"], ["users.id"], name=op.f("fk_reprints_user_id_users")
|
||||
),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_reprints_user_id_users")),
|
||||
sa.ForeignKeyConstraint(
|
||||
["voucher_id"],
|
||||
["vouchers.id"],
|
||||
@@ -414,9 +388,7 @@ def upgrade():
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_reprints")),
|
||||
)
|
||||
op.create_index(op.f("ix_reprints_date"), "reprints", ["date"], unique=False)
|
||||
op.create_index(
|
||||
op.f("ix_reprints_voucher_id"), "reprints", ["voucher_id"], unique=False
|
||||
)
|
||||
op.create_index(op.f("ix_reprints_voucher_id"), "reprints", ["voucher_id"], unique=False)
|
||||
op.create_table(
|
||||
"settlements",
|
||||
sa.Column("id", postgresql.UUID(), nullable=False),
|
||||
@@ -434,13 +406,9 @@ def upgrade():
|
||||
name=op.f("fk_settlements_voucher_id_vouchers"),
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_settlements")),
|
||||
sa.UniqueConstraint(
|
||||
"voucher_id", "settled", name=op.f("uq_settlements_voucher_id")
|
||||
),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_settlements_voucher_id"), "settlements", ["voucher_id"], unique=False
|
||||
sa.UniqueConstraint("voucher_id", "settled", name=op.f("uq_settlements_voucher_id")),
|
||||
)
|
||||
op.create_index(op.f("ix_settlements_voucher_id"), "settlements", ["voucher_id"], unique=False)
|
||||
op.create_table(
|
||||
"inventories",
|
||||
sa.Column("id", postgresql.UUID(), nullable=False),
|
||||
@@ -453,17 +421,13 @@ def upgrade():
|
||||
sa.Column("tax_id", postgresql.UUID(), nullable=False),
|
||||
sa.Column("discount", sa.Numeric(), nullable=True),
|
||||
sa.Column("sort_order", sa.Numeric(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["kot_id"], ["kots.id"], name=op.f("fk_inventories_kot_id_kots")
|
||||
),
|
||||
sa.ForeignKeyConstraint(["kot_id"], ["kots.id"], name=op.f("fk_inventories_kot_id_kots")),
|
||||
sa.ForeignKeyConstraint(
|
||||
["product_id"],
|
||||
["products.id"],
|
||||
name=op.f("fk_inventories_product_id_products"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["tax_id"], ["taxes.id"], name=op.f("fk_inventories_tax_id_taxes")
|
||||
),
|
||||
sa.ForeignKeyConstraint(["tax_id"], ["taxes.id"], name=op.f("fk_inventories_tax_id_taxes")),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_inventories")),
|
||||
sa.UniqueConstraint(
|
||||
"kot_id",
|
||||
@@ -473,9 +437,7 @@ def upgrade():
|
||||
name=op.f("uq_inventories_kot_id"),
|
||||
),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_inventories_kot_id"), "inventories", ["kot_id"], unique=False
|
||||
)
|
||||
op.create_index(op.f("ix_inventories_kot_id"), "inventories", ["kot_id"], unique=False)
|
||||
op.create_table(
|
||||
"inventory_modifiers",
|
||||
sa.Column("id", postgresql.UUID(), nullable=False),
|
||||
@@ -500,31 +462,11 @@ def upgrade():
|
||||
),
|
||||
)
|
||||
|
||||
op.execute(
|
||||
Permission.__table__.insert().values(
|
||||
id="7669dfc9-cc75-4e48-b267-145c8832a83c", name="Guest Book"
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
Permission.__table__.insert().values(
|
||||
id="5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c", name="Printers"
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
Permission.__table__.insert().values(
|
||||
id="c973f32c-a37b-496a-8dc5-60d2e4c39e97", name="Sections"
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
Permission.__table__.insert().values(
|
||||
id="7a04ba63-5d08-4078-9051-a6d91cce3e48", name="Section Printers"
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
Section.__table__.insert().values(
|
||||
id="3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df", name="Main"
|
||||
)
|
||||
)
|
||||
op.execute(Permission.__table__.insert().values(id="7669dfc9-cc75-4e48-b267-145c8832a83c", name="Guest Book"))
|
||||
op.execute(Permission.__table__.insert().values(id="5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c", name="Printers"))
|
||||
op.execute(Permission.__table__.insert().values(id="c973f32c-a37b-496a-8dc5-60d2e4c39e97", name="Sections"))
|
||||
op.execute(Permission.__table__.insert().values(id="7a04ba63-5d08-4078-9051-a6d91cce3e48", name="Section Printers"))
|
||||
op.execute(Section.__table__.insert().values(id="3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df", name="Main"))
|
||||
|
||||
op.execute(
|
||||
ModifierCategory.__table__.insert().values(
|
||||
@@ -597,9 +539,7 @@ def upgrade():
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=2, name="Cash", show_in_choices=True, display_group=2, is_print=False
|
||||
)
|
||||
SettleOption.__table__.insert().values(id=2, name="Cash", show_in_choices=True, display_group=2, is_print=False)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
@@ -625,9 +565,7 @@ def upgrade():
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=6, name="Tip", show_in_choices=True, display_group=2, is_print=True
|
||||
)
|
||||
SettleOption.__table__.insert().values(id=6, name="Tip", show_in_choices=True, display_group=2, is_print=True)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
@@ -644,9 +582,7 @@ def upgrade():
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=9, name="Void", show_in_choices=True, display_group=1, is_print=True
|
||||
)
|
||||
SettleOption.__table__.insert().values(id=9, name="Void", show_in_choices=True, display_group=1, is_print=True)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import logging
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def init() -> None:
|
||||
pass
|
||||
|
||||
|
||||
def main() -> None:
|
||||
logger.info("Initializing service")
|
||||
init()
|
||||
logger.info("Service finished initializing")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,5 @@
|
||||
from arq.connections import RedisSettings
|
||||
from barker.core.config import settings as sett
|
||||
|
||||
|
||||
settings = RedisSettings(host=sett.REDIS_HOST, port=sett.REDIS_PORT)
|
||||
@@ -1,7 +0,0 @@
|
||||
from barker.core.config import settings
|
||||
from celery import Celery
|
||||
|
||||
|
||||
celery_app = Celery("tasks", broker=settings.RABBITMQ_URI)
|
||||
|
||||
celery_app.conf.task_routes = {"barker.worker.sent_to_printer": "main-queue"}
|
||||
@@ -1,9 +1,7 @@
|
||||
import secrets
|
||||
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from pydantic import BaseSettings, PostgresDsn, validator
|
||||
from pydantic import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
@@ -19,7 +17,9 @@ class Settings(BaseSettings):
|
||||
DEBUG: bool = False
|
||||
LOG_LEVEL: str = "NOTSET"
|
||||
SQLALCHEMY_DATABASE_URI: str = None
|
||||
RABBITMQ_URI: str = None
|
||||
|
||||
REDIS_HOST: str = "127.0.0.1"
|
||||
REDIS_PORT: int = 6379
|
||||
|
||||
ALEMBIC_LOG_LEVEL: str = "INFO"
|
||||
ALEMBIC_SQLALCHEMY_LOG_LEVEL: str = "WARN"
|
||||
|
||||
@@ -55,9 +55,7 @@ def create_access_token(*, data: dict, expires_delta: timedelta = None):
|
||||
else:
|
||||
expire = datetime.utcnow() + timedelta(minutes=15)
|
||||
to_encode.update({"exp": expire})
|
||||
encoded_jwt = jwt.encode(
|
||||
to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM
|
||||
)
|
||||
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM)
|
||||
return encoded_jwt
|
||||
|
||||
|
||||
@@ -78,15 +76,9 @@ def authenticate_user(
|
||||
return user
|
||||
|
||||
|
||||
def client_allowed(
|
||||
user: UserModel, client_id: int, otp: Optional[int] = None, db: Session = None
|
||||
) -> (bool, int):
|
||||
client = (
|
||||
db.query(Client).filter(Client.id == client_id).first() if client_id else None
|
||||
)
|
||||
allowed = "clients" in set(
|
||||
[p.name.replace(" ", "-").lower() for r in user.roles for p in r.permissions]
|
||||
)
|
||||
def client_allowed(user: UserModel, client_id: int, otp: Optional[int] = None, db: Session = None) -> (bool, int):
|
||||
client = db.query(Client).filter(Client.id == client_id).first() if client_id else None
|
||||
allowed = "clients" in set([p.name.replace(" ", "-").lower() for r in user.roles for p in r.permissions])
|
||||
if allowed or True:
|
||||
return True, 0
|
||||
elif client is None:
|
||||
@@ -109,16 +101,14 @@ async def get_current_user(
|
||||
if security_scopes.scopes:
|
||||
authenticate_value = f'Bearer scope="{security_scopes.scope_str}"'
|
||||
else:
|
||||
authenticate_value = f"Bearer"
|
||||
authenticate_value = "Bearer"
|
||||
credentials_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Could not validate credentials",
|
||||
headers={"WWW-Authenticate": authenticate_value},
|
||||
)
|
||||
try:
|
||||
payload = jwt.decode(
|
||||
token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM]
|
||||
)
|
||||
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
|
||||
username: str = payload.get("sub")
|
||||
if username is None:
|
||||
raise credentials_exception
|
||||
|
||||
@@ -26,9 +26,7 @@ def get_finish_date(session):
|
||||
|
||||
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")
|
||||
)
|
||||
session["finish"] = finish if isinstance(finish, str) else finish.strftime("%d-%b-%Y")
|
||||
|
||||
|
||||
def get_first_day(dt, d_years=0, d_months=0):
|
||||
|
||||
+12
-35
@@ -1,6 +1,6 @@
|
||||
import uuid
|
||||
|
||||
from barker.core.config import settings
|
||||
from barker.core.config import settings # noqa: F401
|
||||
from barker.models import (
|
||||
Customer,
|
||||
DbSetting,
|
||||
@@ -28,15 +28,9 @@ def init_db(db: Session) -> None:
|
||||
|
||||
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("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",
|
||||
@@ -115,9 +109,7 @@ def init_db(db: Session) -> None:
|
||||
]
|
||||
for option in options:
|
||||
db.add(option)
|
||||
db.add(
|
||||
Customer("", "Cash", "", "", uuid.UUID("2c716f4b-0736-429a-ad51-610d7c47cb5e"))
|
||||
)
|
||||
db.add(Customer("", "Cash", "", "", uuid.UUID("2c716f4b-0736-429a-ad51-610d7c47cb5e")))
|
||||
db.add(
|
||||
DbSetting(
|
||||
uuid.UUID("fb738ba2-a3c9-40ed-891c-b930e6454974"),
|
||||
@@ -147,22 +139,14 @@ def init_db(db: Session) -> None:
|
||||
def add_permissions(db: Session):
|
||||
permissions = [
|
||||
Permission("Accounts Audit", uuid.UUID("f30fd1fb-df09-46f5-8c5d-181fd46f38de")),
|
||||
Permission(
|
||||
"Beer Consumption", uuid.UUID("efbb8f31-9631-4491-92f4-17cc98e6a0c0")
|
||||
),
|
||||
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("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("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"),
|
||||
@@ -218,19 +202,12 @@ def add_permissions(db: Session):
|
||||
]
|
||||
|
||||
roles[0].permissions = permissions
|
||||
roles[1].permissions = list(
|
||||
permissions[i] for i in [2, 3, 11, 18, 24, 25, 26, 30, 34]
|
||||
)
|
||||
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[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])
|
||||
|
||||
|
||||
+7
-21
@@ -55,24 +55,16 @@ app.include_router(role.router, prefix="/api/roles", tags=["users"])
|
||||
app.include_router(user.router, prefix="/api/users", tags=["users"])
|
||||
|
||||
app.include_router(modifier.router, prefix="/api/modifiers", tags=["modifiers"])
|
||||
app.include_router(
|
||||
modifier_category.router, prefix="/api/modifier-categories", tags=["modifiers"]
|
||||
)
|
||||
app.include_router(modifier_category.router, prefix="/api/modifier-categories", tags=["modifiers"])
|
||||
|
||||
app.include_router(printer.router, prefix="/api/printers", tags=["printers"])
|
||||
|
||||
app.include_router(
|
||||
menu_category.router, prefix="/api/menu-categories", tags=["products"]
|
||||
)
|
||||
app.include_router(menu_category.router, prefix="/api/menu-categories", tags=["products"])
|
||||
app.include_router(product.router, prefix="/api/products", tags=["products"])
|
||||
app.include_router(
|
||||
sale_category.router, prefix="/api/sale-categories", tags=["products"]
|
||||
)
|
||||
app.include_router(sale_category.router, prefix="/api/sale-categories", tags=["products"])
|
||||
|
||||
app.include_router(section.router, prefix="/api/sections", tags=["sections"])
|
||||
app.include_router(
|
||||
section_printer.router, prefix="/api/section-printers", tags=["section-printers"]
|
||||
)
|
||||
app.include_router(section_printer.router, prefix="/api/section-printers", tags=["section-printers"])
|
||||
|
||||
app.include_router(tax.router, prefix="/api/taxes", tags=["taxes"])
|
||||
|
||||
@@ -88,15 +80,9 @@ app.include_router(
|
||||
prefix="/api/bill-settlement-report",
|
||||
tags=["reports"],
|
||||
)
|
||||
app.include_router(
|
||||
cashier_report.router, prefix="/api/cashier-report", tags=["reports"]
|
||||
)
|
||||
app.include_router(
|
||||
discount_report.router, prefix="/api/discount-report", tags=["reports"]
|
||||
)
|
||||
app.include_router(
|
||||
product_sale_report.router, prefix="/api/product-sale-report", tags=["reports"]
|
||||
)
|
||||
app.include_router(cashier_report.router, prefix="/api/cashier-report", tags=["reports"])
|
||||
app.include_router(discount_report.router, prefix="/api/discount-report", tags=["reports"])
|
||||
app.include_router(product_sale_report.router, prefix="/api/product-sale-report", tags=["reports"])
|
||||
app.include_router(sale_report.router, prefix="/api/sale-report", tags=["reports"])
|
||||
app.include_router(tax_report.router, prefix="/api/tax-report", tags=["reports"])
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ class Client(Base):
|
||||
otp = Column("otp", Integer)
|
||||
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
||||
|
||||
def __init__(
|
||||
self, id_=None, name=None, enabled=False, otp=None, creation_date=None
|
||||
):
|
||||
def __init__(self, id_=None, name=None, enabled=False, otp=None, creation_date=None):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.enabled = enabled
|
||||
@@ -47,9 +45,7 @@ class Client(Base):
|
||||
def create(cls, db: Session):
|
||||
client_code = random.randint(1000, 9999)
|
||||
otp = random.randint(1000, 9999)
|
||||
name = "".join(
|
||||
random.choice(string.ascii_uppercase + string.digits) for x in range(6)
|
||||
)
|
||||
name = "".join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
|
||||
client = Client(client_code, name, False, otp)
|
||||
db.add(client)
|
||||
return client
|
||||
|
||||
@@ -50,9 +50,7 @@ class FoodTable(Base):
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), nullable=False, unique=True)
|
||||
seats = Column("seats", Integer, nullable=False)
|
||||
section_id = Column(
|
||||
"section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False
|
||||
)
|
||||
section_id = Column("section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False)
|
||||
is_active = Column("is_active", Boolean, nullable=False)
|
||||
sort_order = Column("sort_order", Integer, nullable=False)
|
||||
|
||||
@@ -105,9 +103,7 @@ class MenuCategory(Base):
|
||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||
sort_order = Column("sort_order", Integer, nullable=False)
|
||||
|
||||
def __init__(
|
||||
self, name, discount_limit, is_active, sort_order, is_fixture=False, id_=None
|
||||
):
|
||||
def __init__(self, name, discount_limit, is_active, sort_order, is_fixture=False, id_=None):
|
||||
self.name = name
|
||||
self.discount_limit = discount_limit
|
||||
self.is_active = is_active
|
||||
@@ -121,9 +117,7 @@ class SaleCategory(Base):
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), nullable=False, unique=True)
|
||||
tax_id = Column(
|
||||
"tax_id", UUID(as_uuid=True), ForeignKey("taxes.id"), nullable=False
|
||||
)
|
||||
tax_id = Column("tax_id", UUID(as_uuid=True), ForeignKey("taxes.id"), nullable=False)
|
||||
tax = relationship("Tax", foreign_keys=tax_id)
|
||||
|
||||
def __init__(self, name, tax_id=False, id_=None):
|
||||
@@ -316,9 +310,7 @@ class Device(Base):
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||
section_id = Column(
|
||||
"section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False
|
||||
)
|
||||
section_id = Column("section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False)
|
||||
|
||||
section = relationship("Section", foreign_keys=section_id)
|
||||
|
||||
@@ -348,15 +340,9 @@ class SectionPrinter(Base):
|
||||
__table_args__ = (UniqueConstraint("menu_category_id", "section_id"),)
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
menu_category_id = Column(
|
||||
"menu_category_id", UUID(as_uuid=True), ForeignKey("menu_categories.id")
|
||||
)
|
||||
section_id = Column(
|
||||
"section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False
|
||||
)
|
||||
printer_id = Column(
|
||||
"printer_id", UUID(as_uuid=True), ForeignKey("printers.id"), nullable=False
|
||||
)
|
||||
menu_category_id = Column("menu_category_id", UUID(as_uuid=True), ForeignKey("menu_categories.id"))
|
||||
section_id = Column("section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False)
|
||||
printer_id = Column("printer_id", UUID(as_uuid=True), ForeignKey("printers.id"), nullable=False)
|
||||
copies = Column("copies", Integer, nullable=False)
|
||||
|
||||
menu_category = relationship("MenuCategory", backref="section_printers")
|
||||
|
||||
@@ -34,9 +34,7 @@ class VoucherType(Enum):
|
||||
class GuestBook(Base):
|
||||
__tablename__ = "guest_book"
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
customer_id = Column(
|
||||
"customer_id", UUID(as_uuid=True), ForeignKey("customers.id"), nullable=False
|
||||
)
|
||||
customer_id = Column("customer_id", UUID(as_uuid=True), ForeignKey("customers.id"), nullable=False)
|
||||
pax = Column("pax", Numeric, nullable=False)
|
||||
date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
||||
|
||||
@@ -70,9 +68,7 @@ class Overview(Base):
|
||||
nullable=False,
|
||||
unique=True,
|
||||
)
|
||||
guest_book_id = Column(
|
||||
"guest_book_id", UUID(as_uuid=True), ForeignKey("guest_book.id"), unique=True
|
||||
)
|
||||
guest_book_id = Column("guest_book_id", UUID(as_uuid=True), ForeignKey("guest_book.id"), unique=True)
|
||||
status = Column("status", Unicode(255), nullable=False)
|
||||
|
||||
voucher = relationship("Voucher", backref=backref("status", uselist=False))
|
||||
@@ -92,12 +88,8 @@ class InventoryModifier(Base):
|
||||
__table_args__ = (UniqueConstraint("inventory_id", "modifier_id"),)
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
inventory_id = Column(
|
||||
"inventory_id", UUID(as_uuid=True), ForeignKey("inventories.id"), nullable=False
|
||||
)
|
||||
modifier_id = Column(
|
||||
"modifier_id", UUID(as_uuid=True), ForeignKey("modifiers.id"), nullable=False
|
||||
)
|
||||
inventory_id = Column("inventory_id", UUID(as_uuid=True), ForeignKey("inventories.id"), nullable=False)
|
||||
modifier_id = Column("modifier_id", UUID(as_uuid=True), ForeignKey("modifiers.id"), nullable=False)
|
||||
price = Column("price", Numeric, nullable=False)
|
||||
|
||||
inventory = relationship("Inventory", backref="modifiers")
|
||||
@@ -130,9 +122,7 @@ class Voucher(Base):
|
||||
narration = Column("narration", Unicode(1000), nullable=False)
|
||||
reason = Column("reason", Unicode(255))
|
||||
_voucher_type = Column("voucher_type", Integer, nullable=False)
|
||||
user_id = Column(
|
||||
"user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False
|
||||
)
|
||||
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
||||
|
||||
user = relationship("User", backref="vouchers")
|
||||
food_table = relationship("FoodTable", backref="vouchers")
|
||||
@@ -228,9 +218,7 @@ class Kot(Base):
|
||||
nullable=False,
|
||||
)
|
||||
date = Column("date", DateTime, nullable=False, index=True)
|
||||
user_id = Column(
|
||||
"user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False
|
||||
)
|
||||
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
||||
|
||||
user = relationship("User", backref="kots")
|
||||
food_table = relationship("FoodTable", backref="kots")
|
||||
@@ -288,9 +276,7 @@ class Reprint(Base):
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
user_id = Column(
|
||||
"user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False
|
||||
)
|
||||
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
||||
|
||||
user = relationship("User", backref="reprints")
|
||||
|
||||
@@ -303,24 +289,16 @@ class Reprint(Base):
|
||||
|
||||
class Inventory(Base):
|
||||
__tablename__ = "inventories"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("kot_id", "product_id", "is_happy_hour", "price"),
|
||||
)
|
||||
__table_args__ = (UniqueConstraint("kot_id", "product_id", "is_happy_hour", "price"),)
|
||||
|
||||
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
kot_id = Column(
|
||||
"kot_id", UUID(as_uuid=True), ForeignKey("kots.id"), nullable=False, index=True
|
||||
)
|
||||
product_id = Column(
|
||||
"product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False
|
||||
)
|
||||
kot_id = Column("kot_id", UUID(as_uuid=True), ForeignKey("kots.id"), nullable=False, index=True)
|
||||
product_id = Column("product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False)
|
||||
quantity = Column("quantity", Numeric)
|
||||
price = Column("price", Numeric)
|
||||
is_happy_hour = Column("is_happy_hour", Boolean, nullable=False)
|
||||
tax_rate = Column("tax_rate", Numeric)
|
||||
tax_id = Column(
|
||||
"tax_id", UUID(as_uuid=True), ForeignKey("taxes.id"), nullable=False
|
||||
)
|
||||
tax_id = Column("tax_id", UUID(as_uuid=True), ForeignKey("taxes.id"), nullable=False)
|
||||
discount = Column("discount", Numeric)
|
||||
sort_order = Column("sort_order", Numeric, nullable=False)
|
||||
|
||||
@@ -356,7 +334,7 @@ class Inventory(Base):
|
||||
|
||||
@effective_price.expression
|
||||
def effective_price(cls):
|
||||
return case([(cls.is_happy_hour == True, 0)], else_=cls.price)
|
||||
return case([(cls.is_happy_hour == True, 0)], else_=cls.price) # noqa: E712
|
||||
|
||||
@hybrid_property
|
||||
def net(self):
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
import asyncio
|
||||
import uuid
|
||||
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
from typing import List, Tuple
|
||||
|
||||
from arq import ArqRedis, create_pool
|
||||
from barker.core.config import settings
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.arq import settings as redis_settings
|
||||
from ..models import DbSetting, Inventory, Printer, SectionPrinter, Voucher, VoucherType
|
||||
from ..worker import sent_to_printer
|
||||
|
||||
|
||||
def print_bill(voucher_id: uuid.UUID, db: Session):
|
||||
async def print_bill(voucher_id: uuid.UUID, db: Session):
|
||||
voucher: Voucher = db.query(Voucher).filter(Voucher.id == voucher_id).first()
|
||||
|
||||
printer = (
|
||||
db.query(Printer)
|
||||
.join(SectionPrinter.printer)
|
||||
.filter(SectionPrinter.section_id == voucher.food_table.section_id)
|
||||
.filter(SectionPrinter.menu_category_id == None)
|
||||
.filter(SectionPrinter.menu_category_id == None) # noqa: E711
|
||||
.first()
|
||||
)
|
||||
|
||||
@@ -37,7 +41,8 @@ def print_bill(voucher_id: uuid.UUID, db: Session):
|
||||
else:
|
||||
tax[i.tax_id] = (i.tax.name, i.tax_amount)
|
||||
data = design_bill(voucher, items_dict.values(), tax.values(), db)
|
||||
sent_to_printer.delay(data, printer.address, printer.cut_code)
|
||||
redis: ArqRedis = asyncio.run(create_pool(redis_settings))
|
||||
asyncio.run(redis.enqueue_job("sent_to_printer", data, printer.address, printer.cut_code))
|
||||
|
||||
|
||||
def design_bill(
|
||||
@@ -47,10 +52,7 @@ def design_bill(
|
||||
db: Session,
|
||||
):
|
||||
# Header
|
||||
s = (
|
||||
"\n\r"
|
||||
+ db.query(DbSetting).filter(DbSetting.name == "Header").first().data["Text"]
|
||||
)
|
||||
s = "\n\r" + db.query(DbSetting).filter(DbSetting.name == "Header").first().data["Text"]
|
||||
if voucher.voucher_type == VoucherType.REGULAR_BILL:
|
||||
s += "\n\r" + "Retail Invoice".center(42)
|
||||
s += "\n\r"
|
||||
@@ -62,21 +64,15 @@ def design_bill(
|
||||
s += "\n\r"
|
||||
|
||||
# Products
|
||||
s += "\n\r" + f"Bill No: {voucher.full_bill_id:>12} {voucher.date:%d-%b-%Y %H:%M}"
|
||||
date = voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)
|
||||
s += "\n\r" + f"Bill No: {voucher.full_bill_id:>12} {date:%d-%b-%Y %H:%M}"
|
||||
s += "\n\r" + "Table No.: " + voucher.food_table.name
|
||||
s += "\n\r" + "-" * 42
|
||||
s += "\n\r" + "Qty. Particulars Price Amount"
|
||||
s += "\n\r" + "-" * 42
|
||||
for item in [i for i in items if i.quantity != 0]:
|
||||
name = (
|
||||
"H H " + item.product.full_name
|
||||
if item.is_happy_hour
|
||||
else item.product.full_name
|
||||
)
|
||||
s += (
|
||||
"\n\r"
|
||||
+ f"{item.quantity: >5.2f} {name:<22.22} {item.price: >6.2f} {item.price * item.quantity: >6.2f}"
|
||||
)
|
||||
name = "H H " + item.product.full_name if item.is_happy_hour else item.product.full_name
|
||||
s += "\n\r" + f"{item.quantity: >5.2f} {name:<22.22} {item.price: >6.2f} {item.price * item.quantity: >6.2f}"
|
||||
for m in [m for m in item.modifiers if m.modifier.show_in_bill]:
|
||||
s += f"\n\r -- {m.modifier.name: <38.38}"
|
||||
s += "\n\r" + "------------------------------------------"
|
||||
@@ -97,7 +93,7 @@ def design_bill(
|
||||
if t[1] != 0:
|
||||
s += f"\n\r{t[0]: >30} : {t[1]: >9.2f}"
|
||||
|
||||
s += f"\n\r{'Total Amount :',32} {round(voucher.amount): >9.2f}"
|
||||
s += f"\n\r{'Total Amount :', 32} {round(voucher.amount): >9.2f}"
|
||||
s += "\n\r" + "-" * 42
|
||||
|
||||
if voucher.voucher_type != VoucherType.REGULAR_BILL:
|
||||
@@ -113,8 +109,5 @@ def design_bill(
|
||||
s += "\n\r" + "-" * 42
|
||||
|
||||
s += "\n\r" + "Cashier : " + voucher.user.name
|
||||
s += (
|
||||
"\n\r"
|
||||
+ db.query(DbSetting).filter(DbSetting.name == "Footer").first().data["Text"]
|
||||
)
|
||||
s += "\n\r" + db.query(DbSetting).filter(DbSetting.name == "Footer").first().data["Text"]
|
||||
return s
|
||||
@@ -1,25 +1,28 @@
|
||||
import asyncio
|
||||
import uuid
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import List
|
||||
|
||||
from arq import ArqRedis, create_pool
|
||||
from barker.core.config import settings
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.arq import settings as redis_settings
|
||||
from ..models import Inventory, Kot, Printer, SectionPrinter, Voucher
|
||||
from ..worker import sent_to_printer
|
||||
|
||||
|
||||
def design_kot(
|
||||
voucher: Voucher, kot: Kot, items: List[Inventory], copy_number: int
|
||||
) -> str:
|
||||
def design_kot(voucher: Voucher, kot: Kot, items: List[Inventory], copy_number: int) -> str:
|
||||
date = voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)
|
||||
s = (
|
||||
f"KOT / BOT".center(42)
|
||||
"KOT / BOT".center(42)
|
||||
+ "\n\r"
|
||||
+ f"Copy No. {copy_number}:".center(42)
|
||||
+ "\n\r"
|
||||
+ "".ljust(42, "-")
|
||||
+ "\n\r"
|
||||
+ f"KOT ID : K-{voucher.kot_id:>5}/S-{kot.code:>5} {kot.date:%d-%b-%Y %H:%M}"
|
||||
+ f"KOT ID : K-{voucher.kot_id:>5}/S-{kot.code:>5} {date:%d-%b-%Y %H:%M}"
|
||||
+ "\n\r"
|
||||
+ f"Table No.: {voucher.food_table.name}"
|
||||
+ "\n\r"
|
||||
@@ -30,11 +33,7 @@ def design_kot(
|
||||
+ "".ljust(42, "-")
|
||||
)
|
||||
for item in items:
|
||||
name = (
|
||||
"H H " + item.product.full_name
|
||||
if item.is_happy_hour
|
||||
else item.product.full_name
|
||||
)
|
||||
name = "H H " + item.product.full_name if item.is_happy_hour else item.product.full_name
|
||||
s += "\n\r" + f"{item.quantity:6.2} x {name:>33}"
|
||||
for m in item.modifiers:
|
||||
s += "\n\r" + f" --- {m.name:>32}"
|
||||
@@ -54,7 +53,7 @@ def print_kot(voucher_id: uuid.UUID, db: Session):
|
||||
.filter(
|
||||
or_(
|
||||
SectionPrinter.menu_category_id == item.product.menu_category_id,
|
||||
SectionPrinter.menu_category_id == None,
|
||||
SectionPrinter.menu_category_id == None, # noqa: E711
|
||||
)
|
||||
)
|
||||
.order_by(SectionPrinter.menu_category_id)
|
||||
@@ -64,9 +63,10 @@ def print_kot(voucher_id: uuid.UUID, db: Session):
|
||||
if key not in my_hash:
|
||||
my_hash[key] = (printer, [])
|
||||
my_hash[key][1].append(item)
|
||||
redis: ArqRedis = asyncio.run(create_pool(redis_settings))
|
||||
for key, value in my_hash.items():
|
||||
printer_id, copies = key
|
||||
printer, items = value
|
||||
for c in range(int(copies)):
|
||||
data = design_kot(voucher, kot, items, c)
|
||||
sent_to_printer.delay(data, printer.address, printer.cut_code)
|
||||
asyncio.run(redis.enqueue_job("sent_to_printer", data, printer.address, printer.cut_code))
|
||||
@@ -3,7 +3,6 @@ import uuid
|
||||
import barker.schemas.auth as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
@@ -78,9 +78,7 @@ def add_permissions(role: Role, permissions: List[schemas.PermissionItem], db):
|
||||
gp = [p for p in role.permissions if p.id == permission.id_]
|
||||
gp = None if len(gp) == 0 else gp[0]
|
||||
if permission.enabled and gp is None:
|
||||
role.permissions.append(
|
||||
db.query(Permission).filter(Permission.id == permission.id_).one()
|
||||
)
|
||||
role.permissions.append(db.query(Permission).filter(Permission.id == permission.id_).one())
|
||||
elif not permission.enabled and gp:
|
||||
role.permissions.remove(gp)
|
||||
|
||||
@@ -125,9 +123,7 @@ async def show_list(
|
||||
{
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"permissions": [
|
||||
p.name for p in sorted(item.permissions, key=lambda p: p.name)
|
||||
],
|
||||
"permissions": [p.name for p in sorted(item.permissions, key=lambda p: p.name)],
|
||||
}
|
||||
for item in db.query(Role).order_by(Role.name).all()
|
||||
]
|
||||
|
||||
@@ -170,12 +170,10 @@ async def show_list(
|
||||
|
||||
|
||||
@router.get("/active")
|
||||
async def show_active(
|
||||
db: Session = Depends(get_db), user: UserToken = Depends(get_user)
|
||||
):
|
||||
async def show_active(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
return [
|
||||
{"name": item.name}
|
||||
for item in db.query(User).filter(User.locked_out == False).order_by(User.name)
|
||||
for item in db.query(User).filter(User.locked_out == False).order_by(User.name) # noqa: E712
|
||||
]
|
||||
|
||||
|
||||
@@ -194,10 +192,7 @@ def user_info(item: Optional[User], db: Session, user: UserToken):
|
||||
return {
|
||||
"name": "",
|
||||
"lockedOut": False,
|
||||
"roles": [
|
||||
{"id": r.id, "name": r.name, "enabled": False}
|
||||
for r in db.query(Role).order_by(Role.name).all()
|
||||
],
|
||||
"roles": [{"id": r.id, "name": r.name, "enabled": False} for r in db.query(Role).order_by(Role.name).all()],
|
||||
}
|
||||
else:
|
||||
return {
|
||||
|
||||
@@ -33,9 +33,7 @@ def save(
|
||||
user: UserToken = Security(get_user, scopes=["customers"]),
|
||||
):
|
||||
try:
|
||||
item = Customer(
|
||||
company=data.company, name=data.name, phone=data.phone, address=data.address
|
||||
)
|
||||
item = Customer(company=data.company, name=data.name, phone=data.phone, address=data.address)
|
||||
db.add(item)
|
||||
db.commit()
|
||||
return customer_info(item)
|
||||
@@ -106,9 +104,7 @@ def show_blank(
|
||||
|
||||
@router.get("/list")
|
||||
def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
return [
|
||||
customer_info(item) for item in db.query(Customer).order_by(Customer.name).all()
|
||||
]
|
||||
return [customer_info(item) for item in db.query(Customer).order_by(Customer.name).all()]
|
||||
|
||||
|
||||
@router.get("/{id_}")
|
||||
|
||||
@@ -36,9 +36,7 @@ def save(
|
||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||
):
|
||||
try:
|
||||
customer: Customer = (
|
||||
db.query(Customer).filter(Customer.phone == data.phone).first()
|
||||
)
|
||||
customer: Customer = db.query(Customer).filter(Customer.phone == data.phone).first()
|
||||
if customer is None:
|
||||
customer = Customer(
|
||||
company=data.company,
|
||||
@@ -136,19 +134,13 @@ def show_list(
|
||||
list_ = (
|
||||
db.query(GuestBook)
|
||||
.filter(
|
||||
GuestBook.date
|
||||
>= q
|
||||
+ timedelta(
|
||||
minutes=settings.NEW_DAY_OFFSET_MINUTES
|
||||
- settings.TIMEZONE_OFFSET_MINUTES
|
||||
)
|
||||
GuestBook.date >= q + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES)
|
||||
)
|
||||
.filter(
|
||||
GuestBook.date
|
||||
< q
|
||||
+ timedelta(
|
||||
minutes=settings.NEW_DAY_OFFSET_MINUTES
|
||||
- settings.TIMEZONE_OFFSET_MINUTES,
|
||||
minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES,
|
||||
days=1,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -57,33 +57,21 @@ async def login_for_access_token(
|
||||
allowed, c_id = client_allowed(user, client_id, otp, db)
|
||||
db.commit()
|
||||
if c_id and c_id != client_id:
|
||||
response.set_cookie(
|
||||
key="client_id", value=str(c_id), max_age=10 * 365 * 24 * 60 * 60
|
||||
)
|
||||
response.set_cookie(key="client_id", value=str(c_id), max_age=10 * 365 * 24 * 60 * 60)
|
||||
if not allowed:
|
||||
not_allowed_response = JSONResponse(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
content={"detail": "Client is not registered"},
|
||||
)
|
||||
not_allowed_response.set_cookie(
|
||||
key="client_id", value=str(c_id), max_age=10 * 365 * 24 * 60 * 60
|
||||
)
|
||||
not_allowed_response.set_cookie(key="client_id", value=str(c_id), max_age=10 * 365 * 24 * 60 * 60)
|
||||
return not_allowed_response
|
||||
access_token_expires = timedelta(minutes=settings.JWT_TOKEN_EXPIRE_MINUTES)
|
||||
access_token = create_access_token(
|
||||
data={
|
||||
"sub": user.name,
|
||||
"scopes": ["authenticated"]
|
||||
+ list(
|
||||
set(
|
||||
[
|
||||
p.name.replace(" ", "-").lower()
|
||||
for r in user.roles
|
||||
for p in r.permissions
|
||||
]
|
||||
)
|
||||
),
|
||||
+ list(set([p.name.replace(" ", "-").lower() for r in user.roles for p in r.permissions])),
|
||||
"userId": str(user.id),
|
||||
"lockedOut": user.locked_out,
|
||||
"ver": __version__.__version__,
|
||||
|
||||
@@ -61,9 +61,7 @@ def update(
|
||||
user: UserToken = Security(get_user, scopes=["products"]),
|
||||
):
|
||||
try:
|
||||
item: MenuCategory = (
|
||||
db.query(MenuCategory).filter(MenuCategory.id == id_).first()
|
||||
)
|
||||
item: MenuCategory = db.query(MenuCategory).filter(MenuCategory.id == id_).first()
|
||||
if item.is_fixture:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_423_LOCKED,
|
||||
@@ -92,9 +90,7 @@ def delete(
|
||||
user: UserToken = Security(get_user, scopes=["products"]),
|
||||
):
|
||||
try:
|
||||
item: MenuCategory = (
|
||||
db.query(MenuCategory).filter(MenuCategory.id == id_).first()
|
||||
)
|
||||
item: MenuCategory = db.query(MenuCategory).filter(MenuCategory.id == id_).first()
|
||||
if item is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -127,10 +123,7 @@ def show_blank(
|
||||
def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
return [
|
||||
menu_category_info(item)
|
||||
for item in db.query(MenuCategory)
|
||||
.order_by(MenuCategory.sort_order)
|
||||
.order_by(MenuCategory.name)
|
||||
.all()
|
||||
for item in db.query(MenuCategory).order_by(MenuCategory.sort_order).order_by(MenuCategory.name).all()
|
||||
]
|
||||
|
||||
|
||||
@@ -141,7 +134,7 @@ async def sale_list(
|
||||
):
|
||||
list_ = (
|
||||
db.query(MenuCategory)
|
||||
.filter(MenuCategory.is_active == True)
|
||||
.filter(MenuCategory.is_active == True) # noqa: E712
|
||||
.order_by(MenuCategory.sort_order)
|
||||
.order_by(MenuCategory.name)
|
||||
.all()
|
||||
@@ -151,7 +144,7 @@ async def sale_list(
|
||||
products = (
|
||||
db.query(Product)
|
||||
.filter(Product.menu_category_id == item.id)
|
||||
.filter(Product.is_active == True)
|
||||
.filter(Product.is_active == True) # noqa: E712
|
||||
.order_by(Product.sort_order)
|
||||
.order_by(Product.name)
|
||||
.all()
|
||||
|
||||
@@ -113,9 +113,7 @@ def show_blank(
|
||||
|
||||
@router.get("/list")
|
||||
def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
return [
|
||||
modifier_info(item) for item in db.query(Modifier).order_by(Modifier.name).all()
|
||||
]
|
||||
return [modifier_info(item) for item in db.query(Modifier).order_by(Modifier.name).all()]
|
||||
|
||||
|
||||
@router.get("/{id_}")
|
||||
|
||||
@@ -63,9 +63,7 @@ def update(
|
||||
user: UserToken = Security(get_user, scopes=["modifiers"]),
|
||||
):
|
||||
try:
|
||||
item: ModifierCategory = (
|
||||
db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||
)
|
||||
item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||
item.name = data.name
|
||||
item.minimum = data.minimum
|
||||
item.maximum = data.maximum
|
||||
@@ -91,9 +89,7 @@ def delete(
|
||||
user: UserToken = Security(get_user, scopes=["modifiers"]),
|
||||
):
|
||||
try:
|
||||
item: ModifierCategory = (
|
||||
db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||
)
|
||||
item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||
db.delete(item)
|
||||
db.commit()
|
||||
return modifier_category_info(None, db=db)
|
||||
@@ -118,16 +114,11 @@ def show_blank(
|
||||
|
||||
@router.get("/list")
|
||||
def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
list_ = (
|
||||
db.query(ModifierCategory)
|
||||
.order_by(ModifierCategory.sort_order)
|
||||
.order_by(ModifierCategory.name)
|
||||
.all()
|
||||
)
|
||||
list_ = db.query(ModifierCategory).order_by(ModifierCategory.sort_order).order_by(ModifierCategory.name).all()
|
||||
menu_categories = (
|
||||
db.query(MenuCategory)
|
||||
.join(MenuCategory.products)
|
||||
.filter(Product.is_active == True)
|
||||
.filter(Product.is_active == True) # noqa: E712
|
||||
.order_by(MenuCategory.sort_order, Product.sort_order, Product.name)
|
||||
.all()
|
||||
)
|
||||
@@ -143,21 +134,13 @@ def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)
|
||||
{
|
||||
"id": mc.id,
|
||||
"name": mc.name,
|
||||
"enabled": reduce(
|
||||
lambda x, y: x and (y in item.products), mc.products, True
|
||||
),
|
||||
"products": [
|
||||
{"id": p.id, "name": p.name}
|
||||
for p in mc.products
|
||||
if p in item.products
|
||||
],
|
||||
"enabled": reduce(lambda x, y: x and (y in item.products), mc.products, True),
|
||||
"products": [{"id": p.id, "name": p.name} for p in mc.products if p in item.products],
|
||||
}
|
||||
for mc in menu_categories
|
||||
],
|
||||
}
|
||||
modifier_category["menuCategories"] = [
|
||||
i for i in modifier_category["menuCategories"] if len(i["products"]) > 0
|
||||
]
|
||||
modifier_category["menuCategories"] = [i for i in modifier_category["menuCategories"] if len(i["products"]) > 0]
|
||||
modifier_categories.append(modifier_category)
|
||||
return modifier_categories
|
||||
|
||||
@@ -180,7 +163,7 @@ def for_product(
|
||||
"modifiers": [
|
||||
{"id": m.id, "name": m.name, "price": m.price}
|
||||
for m in item.modifiers
|
||||
if m.is_active == True
|
||||
if m.is_active == True # noqa: E712
|
||||
],
|
||||
}
|
||||
for item in product.modifier_categories
|
||||
@@ -194,9 +177,7 @@ def show_id(
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["modifiers"]),
|
||||
):
|
||||
item: ModifierCategory = (
|
||||
db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||
)
|
||||
item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||
return modifier_category_info(item, db=db)
|
||||
|
||||
|
||||
@@ -204,7 +185,7 @@ def modifier_category_info(item: Optional[ModifierCategory], db: Session):
|
||||
menu_categories = (
|
||||
db.query(MenuCategory)
|
||||
.join(MenuCategory.products)
|
||||
.filter(Product.is_active == True)
|
||||
.filter(Product.is_active == True) # noqa: E712
|
||||
.order_by(MenuCategory.sort_order, Product.sort_order, Product.name)
|
||||
.all()
|
||||
)
|
||||
@@ -219,10 +200,7 @@ def modifier_category_info(item: Optional[ModifierCategory], db: Session):
|
||||
"id": mc.id,
|
||||
"name": mc.name,
|
||||
"enabled": False,
|
||||
"products": [
|
||||
{"id": p.id, "name": p.name, "enabled": False}
|
||||
for p in mc.products
|
||||
],
|
||||
"products": [{"id": p.id, "name": p.name, "enabled": False} for p in mc.products],
|
||||
}
|
||||
for mc in menu_categories
|
||||
],
|
||||
|
||||
@@ -105,9 +105,7 @@ def show_blank(
|
||||
|
||||
@router.get("/list")
|
||||
def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
return [
|
||||
printer_info(item) for item in db.query(Printer).order_by(Printer.name).all()
|
||||
]
|
||||
return [printer_info(item) for item in db.query(Printer).order_by(Printer.name).all()]
|
||||
|
||||
|
||||
@router.get("/{id_}")
|
||||
|
||||
@@ -49,9 +49,7 @@ def sort_order(
|
||||
.order_by(Product.menu_category_id)
|
||||
.order_by(Product.sort_order)
|
||||
.order_by(Product.name)
|
||||
.options(
|
||||
joinedload(Product.menu_category), joinedload(Product.sale_category)
|
||||
)
|
||||
.options(joinedload(Product.menu_category), joinedload(Product.sale_category))
|
||||
.all()
|
||||
]
|
||||
except SQLAlchemyError as e:
|
||||
|
||||
@@ -32,17 +32,13 @@ def beer_consumption(
|
||||
):
|
||||
start_date = date.today() if s is None else datetime.strptime(s, "%d-%b-%Y").date()
|
||||
finish_date = date.today() if f is None else datetime.strptime(f, "%d-%b-%Y").date()
|
||||
if (
|
||||
date.today() - start_date
|
||||
).days > 5 and "accounts-audit" not in user.permissions:
|
||||
if (date.today() - start_date).days > 5 and "accounts-audit" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Accounts Audit",
|
||||
)
|
||||
|
||||
day = func.date_trunc(
|
||||
"day", Voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)
|
||||
).label("day")
|
||||
day = func.date_trunc("day", Voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).label("day")
|
||||
sum_ = func.sum(Inventory.quantity * Product.quantity).label("sum")
|
||||
list_ = (
|
||||
db.query(day, Product.name, sum_)
|
||||
|
||||
@@ -31,9 +31,7 @@ def bill_details(
|
||||
):
|
||||
start_date = date.today() if s is None else datetime.strptime(s, "%d-%b-%Y").date()
|
||||
finish_date = date.today() if f is None else datetime.strptime(f, "%d-%b-%Y").date()
|
||||
if (
|
||||
date.today() - start_date
|
||||
).days > 5 and "accounts-audit" not in user.permissions:
|
||||
if (date.today() - start_date).days > 5 and "accounts-audit" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Accounts Audit",
|
||||
@@ -42,8 +40,7 @@ def bill_details(
|
||||
return {
|
||||
"startDate": start_date.strftime("%d-%b-%Y"),
|
||||
"finishDate": finish_date.strftime("%d-%b-%Y"),
|
||||
"amounts": settlements(start_date, finish_date, db)
|
||||
+ reprints(start_date, finish_date, db),
|
||||
"amounts": settlements(start_date, finish_date, db) + reprints(start_date, finish_date, db),
|
||||
}
|
||||
|
||||
|
||||
@@ -91,16 +88,9 @@ def reprints(s: date, f: date, db: Session):
|
||||
"billId": item.voucher.full_bill_id,
|
||||
"settlement": f"Reprinted by {item.user.name}",
|
||||
"Amount": round(
|
||||
next(
|
||||
s.amount
|
||||
for s in item.voucher.settlements
|
||||
if s.settled == SettleOption.AMOUNT()
|
||||
)
|
||||
* -1,
|
||||
next(s.amount for s in item.voucher.settlements if s.settled == SettleOption.AMOUNT()) * -1,
|
||||
2,
|
||||
),
|
||||
}
|
||||
for item in db.query(Reprint)
|
||||
.filter(Reprint.date >= start_date, Reprint.date <= finish_date)
|
||||
.all()
|
||||
for item in db.query(Reprint).filter(Reprint.date >= start_date, Reprint.date <= finish_date).all()
|
||||
]
|
||||
@@ -34,9 +34,7 @@ def active_cashiers(
|
||||
):
|
||||
start_date = date.today() if s is None else datetime.strptime(s, "%d-%b-%Y").date()
|
||||
finish_date = date.today() if f is None else datetime.strptime(f, "%d-%b-%Y").date()
|
||||
if (
|
||||
date.today() - start_date
|
||||
).days > 5 and "accounts-audit" not in user.permissions:
|
||||
if (date.today() - start_date).days > 5 and "accounts-audit" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Accounts Audit",
|
||||
@@ -47,11 +45,8 @@ def active_cashiers(
|
||||
.filter(
|
||||
User.id.in_(
|
||||
db.query(distinct(Voucher.user_id)).filter(
|
||||
Voucher.date
|
||||
>= start_date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES),
|
||||
Voucher.date
|
||||
<= finish_date
|
||||
+ timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES),
|
||||
Voucher.date >= start_date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES),
|
||||
Voucher.date <= finish_date + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES),
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -72,9 +67,7 @@ def show_id(
|
||||
):
|
||||
start_date = date.today() if s is None else datetime.strptime(s, "%d-%b-%Y").date()
|
||||
finish_date = date.today() if f is None else datetime.strptime(f, "%d-%b-%Y").date()
|
||||
if (
|
||||
date.today() - start_date
|
||||
).days > 5 and "accounts-audit" not in user.permissions:
|
||||
if (date.today() - start_date).days > 5 and "accounts-audit" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Accounts Audit",
|
||||
@@ -82,16 +75,10 @@ def show_id(
|
||||
|
||||
vouchers = (
|
||||
db.query(Voucher)
|
||||
.options(
|
||||
joinedload(Voucher.settlements, innerjoin=True).joinedload(
|
||||
Settlement.settle_option, innerjoin=True
|
||||
)
|
||||
)
|
||||
.options(joinedload(Voucher.settlements, innerjoin=True).joinedload(Settlement.settle_option, innerjoin=True))
|
||||
.filter(
|
||||
Voucher.date
|
||||
>= start_date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES),
|
||||
Voucher.date
|
||||
<= finish_date + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES),
|
||||
Voucher.date >= start_date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES),
|
||||
Voucher.date <= finish_date + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES),
|
||||
Voucher.user_id == id_,
|
||||
)
|
||||
.order_by(Voucher.voucher_type)
|
||||
@@ -133,9 +120,7 @@ def show_blank(
|
||||
):
|
||||
start_date = date.today() if s is None else datetime.strptime(s, "%d-%b-%Y").date()
|
||||
finish_date = date.today() if f is None else datetime.strptime(f, "%d-%b-%Y").date()
|
||||
if (
|
||||
date.today() - start_date
|
||||
).days > 5 and "accounts-audit" not in user.permissions:
|
||||
if (date.today() - start_date).days > 5 and "accounts-audit" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Accounts Audit",
|
||||
|
||||
@@ -7,17 +7,7 @@ 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 import (
|
||||
Inventory,
|
||||
Kot,
|
||||
Product,
|
||||
Reprint,
|
||||
SaleCategory,
|
||||
Settlement,
|
||||
SettleOption,
|
||||
Voucher,
|
||||
VoucherType,
|
||||
)
|
||||
from ...models import Inventory, Kot, Product, SaleCategory, Voucher, VoucherType
|
||||
from ...schemas.auth import UserToken
|
||||
|
||||
|
||||
@@ -42,9 +32,7 @@ def discount_report_view(
|
||||
):
|
||||
start_date = date.today() if s is None else datetime.strptime(s, "%d-%b-%Y").date()
|
||||
finish_date = date.today() if f is None else datetime.strptime(f, "%d-%b-%Y").date()
|
||||
if (
|
||||
date.today() - start_date
|
||||
).days > 5 and "accounts-audit" not in user.permissions:
|
||||
if (date.today() - start_date).days > 5 and "accounts-audit" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Accounts Audit",
|
||||
@@ -61,9 +49,7 @@ def discount_report(s: date, f: date, db: Session):
|
||||
start_date = s + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)
|
||||
finish_date = f + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES)
|
||||
|
||||
amount = func.sum(
|
||||
Inventory.quantity * Inventory.effective_price * Inventory.discount
|
||||
).label("Amount")
|
||||
amount = func.sum(Inventory.quantity * Inventory.effective_price * Inventory.discount).label("Amount")
|
||||
list_ = (
|
||||
db.query(SaleCategory.name, amount)
|
||||
.join(Voucher.kots)
|
||||
@@ -74,9 +60,7 @@ def discount_report(s: date, f: date, db: Session):
|
||||
Inventory.discount != 0,
|
||||
Voucher.date >= start_date,
|
||||
Voucher.date <= finish_date,
|
||||
Voucher.voucher_type.in_(
|
||||
[VoucherType.REGULAR_BILL.value, VoucherType.KOT.value]
|
||||
),
|
||||
Voucher.voucher_type.in_([VoucherType.REGULAR_BILL.value, VoucherType.KOT.value]),
|
||||
)
|
||||
.group_by(SaleCategory.name)
|
||||
.order_by(SaleCategory.name)
|
||||
|
||||
@@ -41,9 +41,7 @@ def product_sale_report_view(
|
||||
):
|
||||
start_date = date.today() if s is None else datetime.strptime(s, "%d-%b-%Y").date()
|
||||
finish_date = date.today() if f is None else datetime.strptime(f, "%d-%b-%Y").date()
|
||||
if (
|
||||
date.today() - start_date
|
||||
).days > 5 and "accounts-audit" not in user.permissions:
|
||||
if (date.today() - start_date).days > 5 and "accounts-audit" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Accounts Audit",
|
||||
|
||||
@@ -42,9 +42,7 @@ def get_sale_analysis(
|
||||
):
|
||||
start_date = date.today() if s is None else datetime.strptime(s, "%d-%b-%Y").date()
|
||||
finish_date = date.today() if f is None else datetime.strptime(f, "%d-%b-%Y").date()
|
||||
if (
|
||||
date.today() - start_date
|
||||
).days > 5 and "accounts-audit" not in user.permissions:
|
||||
if (date.today() - start_date).days > 5 and "accounts-audit" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Accounts Audit",
|
||||
|
||||
@@ -32,9 +32,7 @@ def get_tax_report(
|
||||
):
|
||||
start_date = date.today() if s is None else datetime.strptime(s, "%d-%b-%Y").date()
|
||||
finish_date = date.today() if f is None else datetime.strptime(f, "%d-%b-%Y").date()
|
||||
if (
|
||||
date.today() - start_date
|
||||
).days > 5 and "accounts-audit" not in user.permissions:
|
||||
if (date.today() - start_date).days > 5 and "accounts-audit" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Accounts Audit",
|
||||
|
||||
@@ -78,9 +78,7 @@ def add_permissions(role: Role, permissions: List[schemas.PermissionItem], db):
|
||||
gp = [p for p in role.permissions if p.id == permission.id_]
|
||||
gp = None if len(gp) == 0 else gp[0]
|
||||
if permission.enabled and gp is None:
|
||||
role.permissions.append(
|
||||
db.query(Permission).filter(Permission.id == permission.id_).one()
|
||||
)
|
||||
role.permissions.append(db.query(Permission).filter(Permission.id == permission.id_).one())
|
||||
elif not permission.enabled and gp:
|
||||
role.permissions.remove(gp)
|
||||
|
||||
@@ -125,9 +123,7 @@ async def show_list(
|
||||
{
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"permissions": [
|
||||
p.name for p in sorted(item.permissions, key=lambda p: p.name)
|
||||
],
|
||||
"permissions": [p.name for p in sorted(item.permissions, key=lambda p: p.name)],
|
||||
}
|
||||
for item in db.query(Role).order_by(Role.name).all()
|
||||
]
|
||||
|
||||
@@ -56,9 +56,7 @@ def update(
|
||||
user: UserToken = Security(get_user, scopes=["products"]),
|
||||
):
|
||||
try:
|
||||
item: SaleCategory = (
|
||||
db.query(SaleCategory).filter(SaleCategory.id == id_).first()
|
||||
)
|
||||
item: SaleCategory = db.query(SaleCategory).filter(SaleCategory.id == id_).first()
|
||||
item.name = data.name
|
||||
item.tax_id = data.tax.id_
|
||||
db.commit()
|
||||
@@ -81,9 +79,7 @@ def delete(
|
||||
user: UserToken = Security(get_user, scopes=["products"]),
|
||||
):
|
||||
try:
|
||||
item: SaleCategory = (
|
||||
db.query(SaleCategory).filter(SaleCategory.id == id_).first()
|
||||
)
|
||||
item: SaleCategory = db.query(SaleCategory).filter(SaleCategory.id == id_).first()
|
||||
if item is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -109,10 +105,7 @@ def show_blank(
|
||||
|
||||
@router.get("/list")
|
||||
def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
return [
|
||||
sale_category_info(item)
|
||||
for item in db.query(SaleCategory).order_by(SaleCategory.name).all()
|
||||
]
|
||||
return [sale_category_info(item) for item in db.query(SaleCategory).order_by(SaleCategory.name).all()]
|
||||
|
||||
|
||||
@router.get("/for-discount")
|
||||
|
||||
@@ -103,9 +103,7 @@ def show_blank(
|
||||
|
||||
@router.get("/list")
|
||||
def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
return [
|
||||
section_info(item) for item in db.query(Section).order_by(Section.name).all()
|
||||
]
|
||||
return [section_info(item) for item in db.query(Section).order_by(Section.name).all()]
|
||||
|
||||
|
||||
@router.get("/{id_}")
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import List, Optional
|
||||
import barker.schemas.master as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import and_
|
||||
from sqlalchemy import and_, or_
|
||||
from sqlalchemy.dialects.postgresql import insert as pg_insert
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -37,18 +37,19 @@ def save(
|
||||
):
|
||||
try:
|
||||
current = []
|
||||
default_copies = 0
|
||||
for mcs in data:
|
||||
if mcs.menu_category.id_ is None and mcs.printer.id_ is None:
|
||||
raise ValueError("Please choose a default printer")
|
||||
if mcs.printer.id_ is None:
|
||||
continue
|
||||
if mcs.menu_category.id_ 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,
|
||||
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,
|
||||
@@ -62,11 +63,16 @@ def save(
|
||||
current.append(mcs.menu_category.id_)
|
||||
db.execute(
|
||||
SectionPrinter.__table__.delete(
|
||||
and_(
|
||||
SectionPrinter.section_id == id_,
|
||||
SectionPrinter.menu_category_id != None,
|
||||
~SectionPrinter.menu_category_id.in_(
|
||||
[x for x in current if x is not None]
|
||||
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]),
|
||||
),
|
||||
)
|
||||
)
|
||||
@@ -146,7 +152,7 @@ def show_id(
|
||||
def report(section_id: uuid.UUID, db: Session):
|
||||
menu_categories = (
|
||||
db.query(MenuCategory.id, MenuCategory.name)
|
||||
.filter(MenuCategory.is_active == True)
|
||||
.filter(MenuCategory.is_active == True) # noqa: E712
|
||||
.order_by(MenuCategory.sort_order)
|
||||
.all()
|
||||
)
|
||||
@@ -162,9 +168,7 @@ def report(section_id: uuid.UUID, db: Session):
|
||||
)
|
||||
list_.append(
|
||||
{
|
||||
"menuCategory": {}
|
||||
if item[0] is None
|
||||
else {"id": item[0], "name": item[1]},
|
||||
"menuCategory": {} if item[0] is None else {"id": item[0], "name": item[1]},
|
||||
"printer": {} if mc is None else {"id": mc.printer_id},
|
||||
"copies": 0 if mc is None else mc.copies,
|
||||
}
|
||||
|
||||
@@ -35,9 +35,7 @@ def sort_order(
|
||||
):
|
||||
try:
|
||||
for index, item in enumerate(data):
|
||||
db.query(FoodTable).filter(FoodTable.id == item.id_).update(
|
||||
{FoodTable.sort_order: index}
|
||||
)
|
||||
db.query(FoodTable).filter(FoodTable.id == item.id_).update({FoodTable.sort_order: index})
|
||||
db.commit()
|
||||
return [
|
||||
{
|
||||
@@ -161,12 +159,7 @@ def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)
|
||||
|
||||
@router.get("/running")
|
||||
def show_running(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
list_ = (
|
||||
db.query(FoodTable)
|
||||
.filter(FoodTable.is_active == True)
|
||||
.order_by(FoodTable.sort_order)
|
||||
.all()
|
||||
)
|
||||
list_ = db.query(FoodTable).filter(FoodTable.is_active == True).order_by(FoodTable.sort_order).all() # noqa: E712
|
||||
|
||||
food_tables = []
|
||||
for item in list_:
|
||||
|
||||
@@ -56,9 +56,7 @@ def do_update_table(item: Voucher, guest_book: Optional[GuestBook], db: Session)
|
||||
item.status.status = status_
|
||||
|
||||
|
||||
def check_permissions(
|
||||
item: Optional[Voucher], voucher_type: VoucherType, permissions: List[str]
|
||||
):
|
||||
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,
|
||||
@@ -123,8 +121,6 @@ def do_update_settlements(voucher: Voucher, others: List[SettleSchema], db: Sess
|
||||
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]
|
||||
):
|
||||
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)
|
||||
@@ -1,6 +1,5 @@
|
||||
import uuid
|
||||
|
||||
from decimal import Decimal
|
||||
from typing import Optional
|
||||
|
||||
import barker.schemas.voucher as schemas
|
||||
@@ -90,17 +89,11 @@ def void_and_issue_new_bill(
|
||||
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
|
||||
)
|
||||
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"
|
||||
)
|
||||
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}
|
||||
)
|
||||
db.query(Overview).filter(Overview.voucher_id == old.id).update({Overview.voucher_id: item.id})
|
||||
@@ -36,9 +36,7 @@ def merge_kot(
|
||||
user: UserToken = Security(get_user, scopes=["merge-kots"]),
|
||||
):
|
||||
try:
|
||||
db.query(Kot).filter(Kot.id == data.kot_id).update(
|
||||
{Kot.voucher_id: data.new_voucher_id}
|
||||
)
|
||||
db.query(Kot).filter(Kot.id == data.kot_id).update({Kot.voucher_id: data.new_voucher_id})
|
||||
update_vouchers([data.voucher_id, data.new_voucher_id], db)
|
||||
db.commit()
|
||||
except SQLAlchemyError as e:
|
||||
@@ -102,9 +100,7 @@ def move_table(
|
||||
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.query(Voucher).filter(Voucher.id == data.voucher_id).update({Voucher.food_table_id: data.table_id})
|
||||
db.commit()
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
@@ -124,9 +120,7 @@ def merge_table(
|
||||
user: UserToken = Security(get_user, scopes=["merge-tables"]),
|
||||
):
|
||||
try:
|
||||
db.query(Kot).filter(Kot.voucher_id == data.voucher_id).update(
|
||||
{Kot.voucher_id: data.new_voucher_id}
|
||||
)
|
||||
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()
|
||||
|
||||
@@ -36,10 +36,7 @@ def update(
|
||||
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()]
|
||||
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)
|
||||
|
||||
@@ -112,12 +112,7 @@ def do_save(
|
||||
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_
|
||||
),
|
||||
sum(inv.quantity for ko in data.kots for inv in ko.inventories if inv.product.id_ == i.product.id_),
|
||||
2,
|
||||
)
|
||||
product = db.query(Product).filter(Product.id == i.product.id_).first()
|
||||
|
||||
@@ -63,7 +63,7 @@ def from_bill(
|
||||
|
||||
|
||||
@router.get("/from-table/{id_}")
|
||||
def from_bill(
|
||||
def from_table(
|
||||
id_: str, # table id
|
||||
v: Optional[uuid.UUID] = None, # voucher id
|
||||
g: Optional[uuid.UUID] = None, # guest id
|
||||
@@ -107,9 +107,7 @@ def voucher_info(item: Voucher):
|
||||
"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,
|
||||
"customer": {"id": item.customer_id, "name": item.customer.name} if item.customer is not None else None,
|
||||
"settlements": [],
|
||||
"narration": item.narration,
|
||||
"reason": item.reason,
|
||||
@@ -167,8 +165,6 @@ def voucher_blank(table: FoodTable, guest: Optional[GuestBook]):
|
||||
"pax": table.seats if guest is None else guest.pax,
|
||||
"table": {"id": table.id, "name": table.name},
|
||||
"voucherType": VoucherType.KOT.name,
|
||||
"customer": {"id": guest.customer_id, "name": guest.customer.name}
|
||||
if guest is not None
|
||||
else None,
|
||||
"customer": {"id": guest.customer_id, "name": guest.customer.name} if guest is not None else None,
|
||||
"kots": [],
|
||||
}
|
||||
@@ -58,19 +58,13 @@ def split(
|
||||
item.bill_id = None
|
||||
item.voucher_type = VoucherType.VOID
|
||||
item.reason = "Bill Split"
|
||||
do_update_settlements(
|
||||
item, [SettleSchema(id=SettleOption.VOID(), amount=round(item.amount))], db
|
||||
)
|
||||
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_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,
|
||||
@@ -133,20 +127,14 @@ def save(
|
||||
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
|
||||
)
|
||||
item: Voucher = Voucher(now, pax, bill_id, kot_id, table_id, customer_id, voucher_type, user_id)
|
||||
db.add(item)
|
||||
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
|
||||
) # Multiple inventories of the same product give a key error, but combining messes with modifiers, this
|
||||
db.add(kot) # Multiple inventories of the same product give a key error, but combining messes with modifiers, this
|
||||
# will get important when modifiers have a price.
|
||||
for index, (old_inventory, q) in enumerate(
|
||||
[i for i in product_quantities.values() if i[1] != 0]
|
||||
):
|
||||
for index, (old_inventory, q) in enumerate([i for i in product_quantities.values() if i[1] != 0]):
|
||||
inv = Inventory(
|
||||
kot.id,
|
||||
old_inventory.product_id,
|
||||
|
||||
@@ -78,10 +78,7 @@ def update(
|
||||
for i in k.inventories:
|
||||
i.tax_rate = get_tax(i.tax_rate, voucher_type)
|
||||
i.discount = next(
|
||||
round(inv.discount, 5)
|
||||
for ko in data.kots
|
||||
for inv in ko.inventories
|
||||
if inv.id_ == i.id
|
||||
round(inv.discount, 5) for ko in data.kots for inv in ko.inventories if inv.id_ == i.id
|
||||
)
|
||||
for k in (k for k in data.kots if k.id_ is None and len(k.inventories) > 0):
|
||||
need_to_print_kot = True
|
||||
|
||||
@@ -37,9 +37,7 @@ def void(
|
||||
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
|
||||
)
|
||||
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()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import uuid
|
||||
|
||||
from decimal import Decimal
|
||||
from typing import List
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
# package
|
||||
@@ -1,26 +0,0 @@
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
from barker.models import (
|
||||
Customer,
|
||||
DbSetting,
|
||||
ModifierCategory,
|
||||
Permission,
|
||||
Role,
|
||||
Section,
|
||||
SettleOption,
|
||||
User,
|
||||
get_engine,
|
||||
get_session_factory,
|
||||
get_tm_session,
|
||||
)
|
||||
|
||||
|
||||
def usage(argv):
|
||||
cmd = os.path.basename(argv[0])
|
||||
print(
|
||||
"usage: %s <config_uri> [var=value]\n"
|
||||
'(example: "%s development.ini")' % (cmd, cmd)
|
||||
)
|
||||
sys.exit(1)
|
||||
@@ -1,62 +0,0 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from barker.models import (
|
||||
Client,
|
||||
Customer,
|
||||
DbSetting,
|
||||
Device,
|
||||
FoodTable,
|
||||
GuestBook,
|
||||
Inventory,
|
||||
InventoryModifier,
|
||||
Kot,
|
||||
LoginHistory,
|
||||
MenuCategory,
|
||||
Modifier,
|
||||
ModifierCategory,
|
||||
Overview,
|
||||
Permission,
|
||||
Printer,
|
||||
Product,
|
||||
Reprint,
|
||||
Role,
|
||||
SaleCategory,
|
||||
Section,
|
||||
SectionPrinter,
|
||||
Settlement,
|
||||
SettleOption,
|
||||
Tax,
|
||||
User,
|
||||
Voucher,
|
||||
VoucherType,
|
||||
get_engine,
|
||||
get_session_factory,
|
||||
get_tm_session,
|
||||
role_permissions,
|
||||
user_roles,
|
||||
)
|
||||
from barker.models.meta import Base
|
||||
from pyramid.paster import get_appsettings, setup_logging
|
||||
from pyramid.scripts.common import parse_vars
|
||||
|
||||
|
||||
def usage(argv):
|
||||
cmd = os.path.basename(argv[0])
|
||||
print(
|
||||
"usage: %s <config_uri> [var=value]\n"
|
||||
'(example: "%s development.ini")' % (cmd, cmd)
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main(argv=sys.argv):
|
||||
if len(argv) < 2:
|
||||
usage(argv)
|
||||
config_uri = argv[1]
|
||||
options = parse_vars(argv[2:])
|
||||
setup_logging(config_uri)
|
||||
settings = get_appsettings(config_uri, options=options)
|
||||
|
||||
engine = get_engine(settings)
|
||||
Base.metadata.create_all(engine)
|
||||
@@ -5,13 +5,6 @@ from pyramid.httpexceptions import HTTPServiceUnavailable
|
||||
|
||||
@subscriber(NewRequest)
|
||||
def maintenance_mode(event):
|
||||
maintenance = (
|
||||
event.request.dbsession.query(DbSetting)
|
||||
.filter(DbSetting.name == "Maintenance")
|
||||
.first()
|
||||
)
|
||||
if (
|
||||
maintenance is not None
|
||||
and maintenance.data != event.request.authenticated_userid
|
||||
):
|
||||
maintenance = event.request.dbsession.query(DbSetting).filter(DbSetting.name == "Maintenance").first()
|
||||
if maintenance is not None and maintenance.data != event.request.authenticated_userid:
|
||||
raise HTTPServiceUnavailable
|
||||
Whitespace-only changes.
@@ -0,0 +1,19 @@
|
||||
import re # noqa: F401
|
||||
import socket # noqa: F401
|
||||
import sys # noqa: F401
|
||||
|
||||
|
||||
async def sent_to_printer(ctx: dict, data: str, address: str, cut_code: str):
|
||||
print(data, address, cut_code)
|
||||
# try:
|
||||
# regex = re.compile(r'pdl://(?P<host>[\w\d.-]+):(?P<port>[\d]+)')
|
||||
# match = regex.match(address)
|
||||
# s = socket.socket()
|
||||
# s.connect((match.group("host"), int(match.group("port"))))
|
||||
# s.send(bytearray(data + cut_code, "ascii"))
|
||||
# except LookupError as e:
|
||||
# print("Lookup error:", e)
|
||||
# except:
|
||||
# print("Unexpected error:", sys.exc_info()[0])
|
||||
# finally:
|
||||
# s.close()
|
||||
+12
-22
@@ -1,30 +1,20 @@
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
|
||||
from barker.core.celery_app import celery_app
|
||||
from celery.utils.log import get_task_logger
|
||||
from barker.tasks.printing import sent_to_printer
|
||||
|
||||
from .core.arq import settings
|
||||
|
||||
|
||||
# Create the celery app and get the logger
|
||||
logger = get_task_logger(__name__)
|
||||
sys.path.extend(["./"])
|
||||
|
||||
|
||||
@celery_app.task
|
||||
def sent_to_printer(data: str, address: str, cut_code: str):
|
||||
print(data, address, cut_code)
|
||||
# try:
|
||||
# regex = re.compile(r'pdl://(?P<host>[\w\d.-]+):(?P<port>[\d]+)')
|
||||
# match = regex.match(address)
|
||||
# s = socket.socket()
|
||||
# s.connect((match.group("host"), int(match.group("port"))))
|
||||
# s.send(bytearray(data + cut_code, "ascii"))
|
||||
# except LookupError as e:
|
||||
# print("Lookup error:", e)
|
||||
# except:
|
||||
# print("Unexpected error:", sys.exc_info()[0])
|
||||
# finally:
|
||||
# s.close()
|
||||
class WorkerSettings:
|
||||
"""
|
||||
Settings for the ARQ worker.
|
||||
"""
|
||||
|
||||
redis_settings = settings
|
||||
functions: list = [sent_to_printer]
|
||||
|
||||
|
||||
# celery --app=barker.worker.celery_app worker -c 2 --loglevel=INFO
|
||||
# command to run arq barker.worker.WorkerSettings
|
||||
@@ -19,12 +19,13 @@ itsdangerous = "^1.1.0"
|
||||
python-dotenv = "^0.14.0"
|
||||
pydantic = {extras = ["dotenv"], version = "^1.6.1"}
|
||||
starlette = "^0.13.6"
|
||||
celery = "^5.0.0"
|
||||
arq = "^0.19"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
flake8 = "^3.8.4"
|
||||
black = "^20.8b1"
|
||||
isort = "^5.6.2"
|
||||
pre-commit = "^2.7.1"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
@@ -43,7 +44,7 @@ filter_files = true
|
||||
known_first_party = "poetry"
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
line-length = 120
|
||||
include = '\.pyi?$'
|
||||
exclude = '''
|
||||
/(
|
||||
@@ -59,4 +60,4 @@ exclude = '''
|
||||
| dist
|
||||
| tests/.*/setup.py
|
||||
)/
|
||||
'''
|
||||
'''
|
||||
@@ -1,6 +1,5 @@
|
||||
#! /usr/bin/env bash
|
||||
set -e
|
||||
|
||||
python /app/barker/celeryworker_pre_start.py
|
||||
|
||||
celery --app barker.worker worker --loglevel INFO --queues main-queue --concurrency 1
|
||||
echo arq barker.worker.WorkerSettings
|
||||
celery arq barker.worker.WorkerSettings
|
||||
@@ -25,4 +25,4 @@ exports.config = {
|
||||
});
|
||||
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -10,4 +10,4 @@
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user