Merged payment and receipt routes and permissions into journal as they were not really needed.
This commit is contained in:
parent
a5fcb2026c
commit
d49be23056
alembic/versions
brewman
@ -7,7 +7,8 @@ Create Date: 2020-05-10 19:52:58.163810
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import table, column
|
||||
from sqlalchemy import table, column, select
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'eed0b382c287'
|
||||
@ -192,11 +193,25 @@ def upgrade():
|
||||
op.drop_constraint('entities_salarydeductions_JournalID_fkey', 'employee_benefit', type_='foreignkey')
|
||||
op.drop_constraint('salary_deductions_VoucherID_fkey', 'employee_benefit', type_='foreignkey')
|
||||
|
||||
permission = table('auth_permissions', column('name', sa.String))
|
||||
permission = table('auth_permissions', column('id', postgresql.UUID()), column('name', sa.String))
|
||||
op.execute(permission.update().where(permission.c.name == op.inline_literal('Service Charge')).values({'name': op.inline_literal('Incentive')}))
|
||||
op.execute(permission.update().where(permission.c.name == op.inline_literal('Salary Deduction')).values({'name': op.inline_literal('Employee Benefit')}))
|
||||
account = table('accounts', column('name', sa.String))
|
||||
op.execute(account.update().where(account.c.name == op.inline_literal('Service Charges')).values({'name': op.inline_literal('Incentives')}))
|
||||
# Remove unneeded Payment and Receipt permissions
|
||||
permission = table('auth_permissions', column('id', postgresql.UUID()), column('name', sa.String))
|
||||
role_permission = table('role_permissions', column('permission_id', postgresql.UUID()), column('role_id', postgresql.UUID()))
|
||||
op.execute(
|
||||
role_permission.delete().where(
|
||||
role_permission.c.permission_id.in_(select([permission.c.id], permission.c.name.in_(['Payment', 'Receipt'])))
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
permission.delete().where(
|
||||
permission.c.name.in_(['Payment', 'Receipt'])
|
||||
)
|
||||
)
|
||||
|
||||
### end Alembic commands ###
|
||||
|
||||
|
||||
|
@ -22,10 +22,8 @@ from .routers import (
|
||||
issue_grid,
|
||||
lock_information,
|
||||
maintenance,
|
||||
payment,
|
||||
product,
|
||||
product_group,
|
||||
receipt,
|
||||
rebase,
|
||||
reset_stock,
|
||||
recipe,
|
||||
@ -125,8 +123,8 @@ app.include_router(unposted.router, prefix="/api/unposted", tags=["reports"])
|
||||
app.include_router(issue_grid.router, prefix="/api/issue-grid", tags=["vouchers"])
|
||||
app.include_router(batch.router, prefix="/api/batch", tags=["vouchers"])
|
||||
app.include_router(journal.router, prefix="/api/journal", tags=["vouchers"])
|
||||
app.include_router(payment.router, prefix="/api/payment", tags=["vouchers"])
|
||||
app.include_router(receipt.router, prefix="/api/receipt", tags=["vouchers"])
|
||||
app.include_router(journal.router, prefix="/api/payment", tags=["vouchers"])
|
||||
app.include_router(journal.router, prefix="/api/receipt", tags=["vouchers"])
|
||||
app.include_router(purchase.router, prefix="/api/purchase", tags=["vouchers"])
|
||||
app.include_router(
|
||||
purchase_return.router, prefix="/api/purchase-return", tags=["vouchers"]
|
||||
|
@ -209,8 +209,18 @@ def get_id(
|
||||
@router.get("", response_model=output.Voucher)
|
||||
def show_blank(
|
||||
request: Request,
|
||||
a: str = None,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["journal"]),
|
||||
):
|
||||
additional_info = {"date": get_date(request.session), "type": "Journal"}
|
||||
if request.scope.get('path') == '/api/payment':
|
||||
type_ = "Payment"
|
||||
elif request.scope.get('path') == '/api/receipt':
|
||||
type_ = "Receipt"
|
||||
else:
|
||||
type_ = "Journal"
|
||||
|
||||
additional_info = {"date": get_date(request.session), "type": type_}
|
||||
if a:
|
||||
additional_info["account"] = a
|
||||
return blank_voucher(additional_info, db)
|
||||
|
@ -1,133 +0,0 @@
|
||||
import traceback
|
||||
import uuid
|
||||
from typing import List
|
||||
from fastapi import (
|
||||
APIRouter,
|
||||
HTTPException,
|
||||
status,
|
||||
Depends,
|
||||
Security,
|
||||
UploadFile,
|
||||
File,
|
||||
Request,
|
||||
)
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .voucher import voucher_info, blank_voucher
|
||||
from ..core.session import set_date, get_date
|
||||
from ..schemas.auth import UserToken
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.voucher import Voucher
|
||||
from brewman.routers.journal import save, save_files, update, update_files
|
||||
import brewman.schemas.voucher as output
|
||||
import brewman.schemas.input as schema_in
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# Dependency
|
||||
def get_db() -> Session:
|
||||
try:
|
||||
db = SessionLocal()
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.post("", response_model=output.Voucher)
|
||||
def save_route(
|
||||
request: Request,
|
||||
data: schema_in.JournalIn = Depends(schema_in.JournalIn.load_form),
|
||||
db: Session = Depends(get_db),
|
||||
i: List[UploadFile] = File(None),
|
||||
t: List[UploadFile] = File(None),
|
||||
user: UserToken = Security(get_user, scopes=["payment"]),
|
||||
):
|
||||
try:
|
||||
i = i or []
|
||||
t = t or []
|
||||
item: Voucher = save(data, user, db)
|
||||
save_files(i + t, db)
|
||||
db.commit()
|
||||
set_date(data.date_.strftime("%d-%b-%Y"), request.session)
|
||||
info = voucher_info(item, db)
|
||||
return info
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=traceback.format_exc(),
|
||||
)
|
||||
|
||||
|
||||
@router.put("/{id_}", response_model=output.Voucher)
|
||||
def update_route(
|
||||
id_: uuid.UUID,
|
||||
request: Request,
|
||||
data: schema_in.JournalIn = Depends(schema_in.JournalIn.load_form),
|
||||
db: Session = Depends(get_db),
|
||||
i: List[UploadFile] = File(None),
|
||||
t: List[UploadFile] = File(None),
|
||||
user: UserToken = Security(get_user, scopes=["payment"]),
|
||||
):
|
||||
try:
|
||||
i = i or []
|
||||
t = t or []
|
||||
item: Voucher = update(id_, data, user, db)
|
||||
update_files(data, i + t, db)
|
||||
db.commit()
|
||||
set_date(data.date_.strftime("%d-%b-%Y"), request.session)
|
||||
return voucher_info(item, db)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=traceback.format_exc(),
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{id_}", response_model=output.Voucher)
|
||||
def get_id(
|
||||
id_: uuid.UUID,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["payment"]),
|
||||
):
|
||||
try:
|
||||
item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first()
|
||||
return voucher_info(item, db)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=traceback.format_exc(),
|
||||
)
|
||||
|
||||
|
||||
@router.get("", response_model=output.Voucher)
|
||||
def show_blank(
|
||||
request: Request,
|
||||
a: str = None,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["payment"]),
|
||||
):
|
||||
additional_info = {"date": get_date(request.session), "type": "Payment"}
|
||||
if a:
|
||||
additional_info["account"] = a
|
||||
return blank_voucher(additional_info, db)
|
@ -1,133 +0,0 @@
|
||||
import traceback
|
||||
import uuid
|
||||
from typing import List
|
||||
from fastapi import (
|
||||
APIRouter,
|
||||
HTTPException,
|
||||
status,
|
||||
Depends,
|
||||
Security,
|
||||
UploadFile,
|
||||
File,
|
||||
Request,
|
||||
)
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .voucher import voucher_info, blank_voucher
|
||||
from ..core.session import set_date, get_date
|
||||
from ..schemas.auth import UserToken
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.voucher import Voucher
|
||||
from brewman.routers.journal import save, save_files, update, update_files
|
||||
import brewman.schemas.voucher as output
|
||||
import brewman.schemas.input as schema_in
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# Dependency
|
||||
def get_db() -> Session:
|
||||
try:
|
||||
db = SessionLocal()
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.post("", response_model=output.Voucher)
|
||||
def save_route(
|
||||
request: Request,
|
||||
data: schema_in.JournalIn = Depends(schema_in.JournalIn.load_form),
|
||||
db: Session = Depends(get_db),
|
||||
i: List[UploadFile] = File(None),
|
||||
t: List[UploadFile] = File(None),
|
||||
user: UserToken = Security(get_user, scopes=["receipt"]),
|
||||
):
|
||||
try:
|
||||
i = i or []
|
||||
t = t or []
|
||||
item: Voucher = save(data, user, db)
|
||||
save_files(i + t, db)
|
||||
db.commit()
|
||||
set_date(data.date_.strftime("%d-%b-%Y"), request.session)
|
||||
info = voucher_info(item, db)
|
||||
return info
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=traceback.format_exc(),
|
||||
)
|
||||
|
||||
|
||||
@router.put("/{id_}", response_model=output.Voucher)
|
||||
def update_route(
|
||||
id_: uuid.UUID,
|
||||
request: Request,
|
||||
data: schema_in.JournalIn = Depends(schema_in.JournalIn.load_form),
|
||||
db: Session = Depends(get_db),
|
||||
i: List[UploadFile] = File(None),
|
||||
t: List[UploadFile] = File(None),
|
||||
user: UserToken = Security(get_user, scopes=["receipt"]),
|
||||
):
|
||||
try:
|
||||
i = i or []
|
||||
t = t or []
|
||||
item: Voucher = update(id_, data, user, db)
|
||||
update_files(data, i + t, db)
|
||||
db.commit()
|
||||
set_date(data.date_.strftime("%d-%b-%Y"), request.session)
|
||||
return voucher_info(item, db)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=traceback.format_exc(),
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{id_}", response_model=output.Voucher)
|
||||
def get_id(
|
||||
id_: uuid.UUID,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["receipt"]),
|
||||
):
|
||||
try:
|
||||
item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first()
|
||||
return voucher_info(item, db)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=traceback.format_exc(),
|
||||
)
|
||||
|
||||
|
||||
@router.get("", response_model=output.Voucher)
|
||||
def show_blank(
|
||||
request: Request,
|
||||
a: str = None,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["receipt"]),
|
||||
):
|
||||
additional_info = {"date": get_date(request.session), "type": "Receipt"}
|
||||
if a:
|
||||
additional_info["account"] = a
|
||||
return blank_voucher(additional_info, db)
|
Loading…
x
Reference in New Issue
Block a user