diff --git a/brewman/brewman/routers/__init__.py b/brewman/brewman/routers/__init__.py index 63d397bc..86bb4152 100644 --- a/brewman/brewman/routers/__init__.py +++ b/brewman/brewman/routers/__init__.py @@ -46,20 +46,16 @@ def get_lock_info( data = sorted(data, key=lambda d: d["index"], reverse=True) for it in data: li: LockInformation = LockInformation( - voucherTypes=[ - VoucherTypesSelected(id=vt["id_"], name=VoucherType.by_id(vt["id_"]).name) for vt in it["voucher_types"] - ], - accountTypes=[ - AccountTypesSelected(id=at["id_"], name=AccountType.by_id(at["id_"]).name) for at in it["account_types"] - ], + voucherTypes=[VoucherTypesSelected(id=vt["id_"], name=vt["name"]) for vt in it["voucher_types"]], + accountTypes=[AccountTypesSelected(id=at["id_"], name=at["name"]) for at in it["account_types"]], start=LockDate(days=it["start"]["days"], date=it["start"]["date_"]), finish=LockDate(days=it["finish"]["days"], date=it["finish"]["date_"]), index=it["index"], ) # Data format - if len(li.voucher_types) != 0 and voucher_type not in li.voucher_types: + if len(li.voucher_types) != 0 and voucher_type not in [vt.id_ for vt in li.voucher_types]: continue - if len(li.account_types) != 0 and len(set(account_types) & set(li.account_types)) == 0: + if len(li.account_types) != 0 and len(set(account_types) & set([at.id_ for at in li.account_types])) == 0: continue if li.start.days is not None: diff --git a/brewman/brewman/routers/employee_benefit.py b/brewman/brewman/routers/employee_benefit.py index 58f227e0..44438b5f 100644 --- a/brewman/brewman/routers/employee_benefit.py +++ b/brewman/brewman/routers/employee_benefit.py @@ -61,10 +61,16 @@ def save_route( def save(data: schema_in.EmployeeBenefitIn, date_: date, user: UserToken, db: Session) -> Voucher: - account_types = db.execute( - select(distinct(AccountBase.type)).where(AccountBase.id.in_([dj.employee.id_ for dj in data.employee_benefits])) + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + AccountBase.id.in_([dj.employee.id_ for dj in data.employee_benefits]) + ) + ) + .scalars() + .all() ) - allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db) + allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_).id, account_types, db) if not allowed: raise HTTPException( status_code=status.HTTP_423_LOCKED, @@ -174,12 +180,16 @@ def update_route( def update_voucher(id_: uuid.UUID, data: schema_in.EmployeeBenefitIn, user: UserToken, db: Session) -> Voucher: voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one() - account_types = db.execute( - select(distinct(AccountBase.type)).where( - AccountBase.id.in_( - [dj.employee.id_ for dj in data.employee_benefits] + [vj.account_id for vj in voucher.journals] + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + AccountBase.id.in_( + [dj.employee.id_ for dj in data.employee_benefits] + [vj.account_id for vj in voucher.journals] + ) ) ) + .scalars() + .all() ) allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db) if not allowed: diff --git a/brewman/brewman/routers/incentive.py b/brewman/brewman/routers/incentive.py index c9d57e80..f28f9836 100644 --- a/brewman/brewman/routers/incentive.py +++ b/brewman/brewman/routers/incentive.py @@ -61,10 +61,14 @@ def save_route( def save(data: schema_in.IncentiveIn, user: UserToken, db: Session) -> Voucher: - account_types = db.execute( - select(distinct(AccountBase.type)).where(AccountBase.id.in_([dj.employee_id for dj in data.incentives])) + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where(AccountBase.id.in_([dj.employee_id for dj in data.incentives])) + ) + .scalars() + .all() ) - allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db) + allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_).id, account_types, db) if not allowed: raise HTTPException( status_code=status.HTTP_423_LOCKED, @@ -137,10 +141,16 @@ def update_route( def update_voucher(id_: uuid.UUID, data: schema_in.IncentiveIn, user: UserToken, db: Session) -> Voucher: voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one() - account_types = db.execute( - select(distinct(AccountBase.type)).where( - AccountBase.id.in_([dj.employee_id for dj in data.incentives] + [vj.account_id for vj in voucher.journals]) + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + AccountBase.id.in_( + [dj.employee_id for dj in data.incentives] + [vj.account_id for vj in voucher.journals] + ) + ) ) + .scalars() + .all() ) allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db) if not allowed: diff --git a/brewman/brewman/routers/issue.py b/brewman/brewman/routers/issue.py index cd6b20d7..26be2bfd 100644 --- a/brewman/brewman/routers/issue.py +++ b/brewman/brewman/routers/issue.py @@ -63,8 +63,10 @@ def save_route( def save(data: schema_in.IssueIn, user: UserToken, db: Session) -> (Voucher, Optional[bool]): product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories])) - account_types = db.execute(select(distinct(AccountBase.type)).where(AccountBase.id.in_(product_accounts))) - allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db) + account_types = ( + db.execute(select(distinct(AccountBase.type)).where(AccountBase.id.in_(product_accounts))).scalars().all() + ) + allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_).id, account_types, db) if not allowed: raise HTTPException( status_code=status.HTTP_423_LOCKED, @@ -189,13 +191,17 @@ def update_route( def update_voucher(id_: uuid.UUID, data: schema_in.IssueIn, user: UserToken, db: Session) -> (Voucher, Optional[bool]): voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one() product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories])) - account_types = db.execute( - select(distinct(AccountBase.type)).where( - or_( - AccountBase.id.in_([vj.account_id for vj in voucher.journals]), - AccountBase.id.in_(product_accounts), + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + or_( + AccountBase.id.in_([vj.account_id for vj in voucher.journals]), + AccountBase.id.in_(product_accounts), + ) ) ) + .scalars() + .all() ) allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db) if not allowed: diff --git a/brewman/brewman/routers/journal.py b/brewman/brewman/routers/journal.py index d3cfe70a..ba67894d 100644 --- a/brewman/brewman/routers/journal.py +++ b/brewman/brewman/routers/journal.py @@ -54,10 +54,14 @@ def save_route( def save(data: schema_in.JournalIn, user: UserToken, db: Session) -> Voucher: - account_types = db.execute( - select(distinct(AccountBase.type)).where(AccountBase.id.in_([dj.account.id_ for dj in data.journals])) + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where(AccountBase.id.in_([dj.account.id_ for dj in data.journals])) + ) + .scalars() + .all() ) - allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db) + allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_).id, account_types, db) if not allowed: raise HTTPException( status_code=status.HTTP_423_LOCKED, @@ -114,10 +118,16 @@ def update_route( def update_voucher(id_: uuid.UUID, data: schema_in.JournalIn, user: UserToken, db: Session) -> Voucher: voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one() - account_types = db.execute( - select(distinct(AccountBase.type)).where( - AccountBase.id.in_([dj.account.id_ for dj in data.journals] + [vj.account_id for vj in voucher.journals]) + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + AccountBase.id.in_( + [dj.account.id_ for dj in data.journals] + [vj.account_id for vj in voucher.journals] + ) + ) ) + .scalars() + .all() ) allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db) if not allowed: diff --git a/brewman/brewman/routers/purchase.py b/brewman/brewman/routers/purchase.py index a8d9a432..c43fcff2 100644 --- a/brewman/brewman/routers/purchase.py +++ b/brewman/brewman/routers/purchase.py @@ -62,15 +62,19 @@ def save_route( def save(data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher: product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories])) - account_types = db.execute( - select(distinct(AccountBase.type)).where( - or_( - AccountBase.id == data.vendor.id_, - AccountBase.id.in_(product_accounts), + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + or_( + AccountBase.id == data.vendor.id_, + AccountBase.id.in_(product_accounts), + ) ) ) + .scalars() + .all() ) - allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db) + allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_).id, account_types, db) if not allowed: raise HTTPException( status_code=status.HTTP_423_LOCKED, @@ -170,13 +174,17 @@ def update_route( def update_voucher(id_: uuid.UUID, data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher: voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one() product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories])) - account_types = db.execute( - select(distinct(AccountBase.type)).where( - or_( - AccountBase.id.in_([data.vendor.id_] + [vj.account_id for vj in voucher.journals]), - AccountBase.id.in_(product_accounts), + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + or_( + AccountBase.id.in_([data.vendor.id_] + [vj.account_id for vj in voucher.journals]), + AccountBase.id.in_(product_accounts), + ) ) ) + .scalars() + .all() ) allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db) if not allowed: diff --git a/brewman/brewman/routers/purchase_return.py b/brewman/brewman/routers/purchase_return.py index 6f488e02..5dc22627 100644 --- a/brewman/brewman/routers/purchase_return.py +++ b/brewman/brewman/routers/purchase_return.py @@ -62,15 +62,19 @@ def save_route( def save(data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher: product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories])) - account_types = db.execute( - select(distinct(AccountBase.type)).where( - or_( - AccountBase.id == data.vendor.id_, - AccountBase.id.in_(product_accounts), + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + or_( + AccountBase.id == data.vendor.id_, + AccountBase.id.in_(product_accounts), + ) ) ) + .scalars() + .all() ) - allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db) + allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_).id, account_types, db) if not allowed: raise HTTPException( status_code=status.HTTP_423_LOCKED, @@ -177,13 +181,17 @@ def update_route( def update_voucher(id_: uuid.UUID, data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher: voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one() product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories])) - account_types = db.execute( - select(distinct(AccountBase.type)).where( - or_( - AccountBase.id.in_([data.vendor.id_] + [vj.account_id for vj in voucher.journals]), - AccountBase.id.in_(product_accounts), + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + or_( + AccountBase.id.in_([data.vendor.id_] + [vj.account_id for vj in voucher.journals]), + AccountBase.id.in_(product_accounts), + ) ) ) + .scalars() + .all() ) allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db) if not allowed: diff --git a/brewman/brewman/routers/voucher.py b/brewman/brewman/routers/voucher.py index 00ef1914..716fc09e 100644 --- a/brewman/brewman/routers/voucher.py +++ b/brewman/brewman/routers/voucher.py @@ -41,8 +41,14 @@ def post_voucher( try: with SessionFuture() as db: voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one() - account_types = db.execute( - select(distinct(AccountBase.type)).where(AccountBase.id.in_([vj.account_id for vj in voucher.journals])) + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where( + AccountBase.id.in_([vj.account_id for vj in voucher.journals]) + ) + ) + .scalars() + .all() ) allowed, message = get_lock_info([voucher.date], voucher.type, account_types, db) if not allowed: @@ -91,8 +97,12 @@ def delete_voucher( voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one() images = db.execute(select(DbImage).where(DbImage.resource_id == voucher.id)).scalars().all() check_delete_permissions(voucher, user) - account_types = db.execute( - select(distinct(AccountBase.type)).where(AccountBase.id.in_([vj.account_id for vj in voucher.journals])) + account_types = ( + db.execute( + select(distinct(AccountBase.type)).where(AccountBase.id.in_([vj.account_id for vj in voucher.journals])) + ) + .scalars() + .all() ) allowed, message = get_lock_info([voucher.date], voucher.type, account_types, db) if not allowed: diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile index 999c72f0..7604eeac 100644 --- a/docker/app/Dockerfile +++ b/docker/app/Dockerfile @@ -7,9 +7,8 @@ RUN npm install --unsafe-perm && /app/overlord/node_modules/.bin/ng build FROM python:latest LABEL maintainer="Amritanshu " -COPY --from=builder /app/brewman /app -COPY --from=builder /app/frontend /app/frontend -WORKDIR /app + +ADD https://git.tanshu.com/tanshu/brewman/raw/tag/latest/brewman/pyproject.toml /app/pyproject.toml # Install Poetry RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | POETRY_HOME=/opt/poetry python && \ @@ -17,10 +16,15 @@ RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/inst ln -s /opt/poetry/bin/poetry && \ poetry config virtualenvs.create false +WORKDIR /app + # Allow installing dev dependencies to run tests ARG INSTALL_DEV=false RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi" +COPY --from=builder /app/brewman /app +COPY --from=builder /app/frontend /app/frontend + ENV PYTHONPATH=/app EXPOSE 80 VOLUME /frontend @@ -30,4 +34,4 @@ RUN chmod 777 /app/docker-entrypoint.sh \ && ln -s /app/docker-entrypoint.sh / ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["python", "-m", "brewman"] +CMD ["poetry", "run", "python", "-m", "brewman"] diff --git a/version_bump.sh b/version_bump.sh index cca9ba64..6202d1c9 100755 --- a/version_bump.sh +++ b/version_bump.sh @@ -2,7 +2,7 @@ parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P ) cd "$parent_path" || exit -if [ 1 -ne "$#" ] +if [ 1 -eq "$#" ] then echo "Version bump to $1" sed --in-place --regexp-extended 's/"([0-9].[0-9].[0-9])"/"'"$1"'"/g' brewman/brewman/__version__.py