Ported:
Table Merge/Move and Kot Merge/Move
This commit is contained in:
@ -26,7 +26,7 @@ from .routers.reports import (
|
|||||||
sale_report,
|
sale_report,
|
||||||
tax_report
|
tax_report
|
||||||
)
|
)
|
||||||
from .routers.voucher import show, save, update, receive_payment, void
|
from .routers.voucher import show, save, update, receive_payment, void, merge_move
|
||||||
|
|
||||||
from .db.base_class import Base
|
from .db.base_class import Base
|
||||||
from .core.config import settings
|
from .core.config import settings
|
||||||
@ -74,6 +74,7 @@ app.include_router(save.router, prefix="/api/voucher", tags=["voucher"])
|
|||||||
app.include_router(update.router, prefix="/api/voucher", tags=["voucher"])
|
app.include_router(update.router, prefix="/api/voucher", tags=["voucher"])
|
||||||
app.include_router(receive_payment.router, prefix="/api/voucher", tags=["voucher"])
|
app.include_router(receive_payment.router, prefix="/api/voucher", tags=["voucher"])
|
||||||
app.include_router(void.router, prefix="/api/voucher", tags=["voucher"])
|
app.include_router(void.router, prefix="/api/voucher", tags=["voucher"])
|
||||||
|
app.include_router(merge_move.router, prefix="/api", tags=["voucher"])
|
||||||
|
|
||||||
# app.include_router(issue_grid.router, prefix="/api/issue-grid", tags=["vouchers"])
|
# 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(batch.router, prefix="/api/batch", tags=["vouchers"])
|
||||||
|
|||||||
@ -1,127 +1,136 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import transaction
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pyramid.view import view_config
|
from typing import List
|
||||||
|
|
||||||
|
from fastapi import APIRouter, HTTPException, status, Depends, Security
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from barker.models import Kot, Voucher, Overview
|
from ...schemas.auth import UserToken
|
||||||
from barker.views.voucher import get_bill_id, do_update_table
|
import barker.schemas.merge_move as schemas
|
||||||
|
from ...core.security import get_current_active_user as get_user
|
||||||
|
from ...db.session import SessionLocal
|
||||||
@view_config(
|
from ...models import Voucher, Kot, Overview, Settlement
|
||||||
request_method="POST",
|
from ...routers.voucher import (
|
||||||
route_name="v1_move_kot",
|
do_update_settlements,
|
||||||
renderer="json",
|
get_bill_id,
|
||||||
request_param="merge",
|
do_update_table,
|
||||||
permission="Merge Kots",
|
|
||||||
trans=True,
|
|
||||||
)
|
)
|
||||||
def merge_kot(request):
|
|
||||||
json = request.json_body
|
|
||||||
kot_id = uuid.UUID(json["kot"]["id"])
|
|
||||||
new_voucher_id = uuid.UUID(json["newVoucher"]["id"])
|
|
||||||
|
|
||||||
request.dbsession.query(Kot).filter(Kot.id == kot_id).update({Kot.voucher_id: new_voucher_id})
|
router = APIRouter()
|
||||||
transaction.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
# Dependency
|
||||||
request_method="POST",
|
def get_db():
|
||||||
route_name="v1_move_kot",
|
try:
|
||||||
renderer="json",
|
db = SessionLocal()
|
||||||
request_param="move",
|
yield db
|
||||||
permission="Move Kot to New Table",
|
finally:
|
||||||
trans=True,
|
db.close()
|
||||||
)
|
|
||||||
def move_kot(request):
|
|
||||||
json = request.json_body
|
|
||||||
now = datetime.now()
|
|
||||||
kot_id = uuid.UUID(json["kot"]["id"])
|
|
||||||
table_id = uuid.UUID(json["table"]["id"])
|
|
||||||
|
|
||||||
kot = request.dbsession.query(Kot).filter(Kot.id == kot_id).first()
|
|
||||||
bill_id = get_bill_id(kot.voucher.voucher_type, request.dbsession)
|
|
||||||
kot_id = request.dbsession.query(func.coalesce(func.max(Voucher.kot_id), 0) + 1).scalar()
|
|
||||||
|
|
||||||
item = Voucher(
|
|
||||||
now,
|
|
||||||
kot.voucher.pax,
|
|
||||||
bill_id,
|
|
||||||
kot_id,
|
|
||||||
table_id,
|
|
||||||
kot.voucher.customer_id,
|
|
||||||
kot.voucher.voucher_type,
|
|
||||||
uuid.UUID(request.authenticated_userid),
|
|
||||||
)
|
|
||||||
request.dbsession.add(item)
|
|
||||||
item.kots.append(kot)
|
|
||||||
do_update_table(item, None, request.dbsession)
|
|
||||||
request.dbsession.add(item.status)
|
|
||||||
transaction.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
@router.post("/move-kot/merge")
|
||||||
request_method="POST",
|
def merge_kot(
|
||||||
route_name="v1_move_table",
|
data: schemas.MergeKot, db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["merge-kots"]),
|
||||||
request_param="move",
|
):
|
||||||
renderer="json",
|
try:
|
||||||
permission="Move Table",
|
db.query(Kot).filter(Kot.id == data.kot_id).update({Kot.voucher_id: data.new_voucher_id})
|
||||||
trans=True,
|
update_vouchers([data.voucher_id, data.new_voucher_id], db)
|
||||||
)
|
db.commit()
|
||||||
def move_table(request):
|
except SQLAlchemyError as e:
|
||||||
id_ = uuid.UUID(request.json_body["voucher"]["id"])
|
db.rollback()
|
||||||
table_id = uuid.UUID(request.json_body["table"]["id"])
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||||
request.dbsession.query(Overview).filter(Overview.voucher_id == id_).update({Overview.food_table_id: table_id})
|
)
|
||||||
|
except Exception:
|
||||||
request.dbsession.query(Voucher).filter(Voucher.id == id_).update({Voucher.food_table_id: table_id})
|
db.rollback()
|
||||||
|
raise
|
||||||
transaction.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
@router.post("/move-kot/move")
|
||||||
request_method="POST",
|
def move_kot(
|
||||||
route_name="v1_move_table",
|
data: schemas.MoveKot,
|
||||||
request_param="merge",
|
db: Session = Depends(get_db),
|
||||||
renderer="json",
|
user: UserToken = Security(get_user, scopes=["move-kot-to-new-table"]),
|
||||||
permission="Merge Tables",
|
):
|
||||||
trans=True,
|
try:
|
||||||
)
|
now = datetime.now()
|
||||||
def merge_table(request):
|
table_id = data.table_id
|
||||||
json = request.json_body
|
|
||||||
|
|
||||||
id_ = uuid.UUID(json["oldVoucher"]["id"])
|
kot = db.query(Kot).filter(Kot.id == data.kot_id).first()
|
||||||
# table_id = uuid.UUID(json["table"]["id"])
|
bill_id = get_bill_id(kot.voucher.voucher_type, db)
|
||||||
new_voucher_id = uuid.UUID(json["newVoucher"]["id"])
|
kot_id = db.query(func.coalesce(func.max(Voucher.kot_id), 0) + 1).scalar()
|
||||||
|
|
||||||
request.dbsession.query(Kot).filter(Kot.voucher_id == id_).update({Kot.voucher_id: new_voucher_id})
|
item = Voucher(
|
||||||
request.dbsession.query(Voucher).filter(Voucher.id == id_).delete()
|
now,
|
||||||
transaction.commit()
|
kot.voucher.pax,
|
||||||
return True
|
bill_id,
|
||||||
|
kot_id,
|
||||||
|
table_id,
|
||||||
|
kot.voucher.customer_id if kot.voucher.customer is not None else None,
|
||||||
|
kot.voucher.voucher_type,
|
||||||
|
user.id_,
|
||||||
|
)
|
||||||
|
db.add(item)
|
||||||
|
item.kots.append(kot)
|
||||||
|
do_update_table(item, None, db)
|
||||||
|
update_vouchers([data.voucher_id, item.id], db)
|
||||||
|
db.commit()
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
db.rollback()
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
db.rollback()
|
||||||
|
raise
|
||||||
|
|
||||||
# VoucherBI.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null);
|
|
||||||
# throw new NotImplementedException();
|
@router.post("/move-table/move")
|
||||||
# var newTable = _session.QueryOver<FoodTable>().Where(x => x.Name == tableName).SingleOrDefault();
|
def move_table(
|
||||||
# var newVoucher = _session.Get<Voucher>(newTable.VoucherID);
|
data: schemas.MoveTable, db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["move-table"]),
|
||||||
# var oldVoucher = _session.Get<Voucher>(voucherID);
|
):
|
||||||
# for (var i = oldVoucher.Kots.Count - 1; i >= 0; i--)
|
try:
|
||||||
# {
|
db.query(Overview).filter(Overview.voucher_id == data.voucher_id).update(
|
||||||
# var kot = oldVoucher.Kots[i];
|
{Overview.food_table_id: data.table_id}
|
||||||
# oldVoucher.Kots.Remove(kot);
|
)
|
||||||
# kot.Voucher = newVoucher;
|
db.query(Voucher).filter(Voucher.id == data.voucher_id).update({Voucher.food_table_id: data.table_id})
|
||||||
# newVoucher.Kots.Add(kot);
|
db.commit()
|
||||||
# _session.Update(kot);
|
except SQLAlchemyError as e:
|
||||||
# }
|
db.rollback()
|
||||||
# _session.Update(newVoucher);
|
raise HTTPException(
|
||||||
#
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||||
#
|
)
|
||||||
# foreach (var item in oldVoucher.Settlements)
|
except Exception:
|
||||||
# {
|
db.rollback()
|
||||||
# _session.Delete(item);
|
raise
|
||||||
# }
|
|
||||||
# _session.Delete(oldVoucher);
|
|
||||||
# return newVoucher.VoucherID;
|
@router.post("/move-table/merge")
|
||||||
|
def merge_table(
|
||||||
|
data: schemas.MergeTable,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
user: UserToken = Security(get_user, scopes=["merge-tables"]),
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
db.query(Kot).filter(Kot.voucher_id == data.voucher_id).update({Kot.voucher_id: data.new_voucher_id})
|
||||||
|
db.query(Overview).filter(Overview.voucher_id == data.voucher_id).delete()
|
||||||
|
db.query(Settlement).filter(Settlement.voucher_id == data.voucher_id).delete()
|
||||||
|
db.query(Voucher).filter(Voucher.id == data.voucher_id).delete()
|
||||||
|
update_vouchers([data.new_voucher_id], db)
|
||||||
|
db.commit()
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
db.rollback()
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
db.rollback()
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def update_vouchers(vouchers: List[uuid.UUID], db: Session):
|
||||||
|
for v in vouchers:
|
||||||
|
voucher: Voucher = db.query(Voucher).filter(Voucher.id == v).first()
|
||||||
|
do_update_settlements(voucher, [], db)
|
||||||
|
|||||||
@ -26,7 +26,7 @@ def get_db():
|
|||||||
def from_id(
|
def from_id(
|
||||||
id_: str, db: Session = Depends(get_db), user: UserToken = Security(get_user),
|
id_: str, db: Session = Depends(get_db), user: UserToken = Security(get_user),
|
||||||
):
|
):
|
||||||
item = db.query(Voucher).filter(Voucher.id == id_).first()
|
item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first()
|
||||||
return voucher_info(item)
|
return voucher_info(item)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
45
barker/schemas/merge_move.py
Normal file
45
barker/schemas/merge_move.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from barker.schemas import to_camel
|
||||||
|
|
||||||
|
|
||||||
|
class MergeKot(BaseModel):
|
||||||
|
voucher_id: uuid.UUID
|
||||||
|
kot_id: uuid.UUID
|
||||||
|
table_id: uuid.UUID
|
||||||
|
new_voucher_id: uuid.UUID
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
alias_generator = to_camel
|
||||||
|
fields = {"id_": "id"}
|
||||||
|
|
||||||
|
|
||||||
|
class MoveKot(BaseModel):
|
||||||
|
voucher_id: uuid.UUID
|
||||||
|
kot_id: uuid.UUID
|
||||||
|
table_id: uuid.UUID
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
alias_generator = to_camel
|
||||||
|
fields = {"id_": "id"}
|
||||||
|
|
||||||
|
|
||||||
|
class MergeTable(BaseModel):
|
||||||
|
voucher_id: uuid.UUID
|
||||||
|
table_id: uuid.UUID
|
||||||
|
new_voucher_id: uuid.UUID
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
alias_generator = to_camel
|
||||||
|
fields = {"id_": "id"}
|
||||||
|
|
||||||
|
|
||||||
|
class MoveTable(BaseModel):
|
||||||
|
voucher_id: uuid.UUID
|
||||||
|
table_id: uuid.UUID
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
alias_generator = to_camel
|
||||||
|
fields = {"id_": "id"}
|
||||||
@ -133,7 +133,7 @@ export class BillsComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moveKot(kot: Kot) {
|
moveKot(kot: Kot) {
|
||||||
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') === -1);
|
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') !== -1);
|
||||||
this.dialog.open(TablesDialogComponent, {
|
this.dialog.open(TablesDialogComponent, {
|
||||||
// width: '750px',
|
// width: '750px',
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@ -100,45 +100,41 @@ export class VoucherService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moveTable(id: string, table: Table): Observable<boolean> {
|
moveTable(id: string, table: Table): Observable<boolean> {
|
||||||
const options = {params: new HttpParams().set('move', '')};
|
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveTable}/move`, {
|
||||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveTable, {
|
voucherId: id,
|
||||||
voucher: {id: id},
|
tableId: table.id
|
||||||
table: {id: table.id}
|
}).pipe(
|
||||||
}, options).pipe(
|
|
||||||
catchError(this.log.handleError(serviceName, 'moveTable'))
|
catchError(this.log.handleError(serviceName, 'moveTable'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeTable(id: string, table: Table): Observable<boolean> {
|
mergeTable(id: string, table: Table): Observable<boolean> {
|
||||||
const options = {params: new HttpParams().set('merge', '')};
|
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveTable}/merge`, {
|
||||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveTable, {
|
voucherId: id,
|
||||||
voucher: {id: id},
|
tableId: table.id,
|
||||||
table: {id: table.id},
|
newVoucherId: table.voucherId
|
||||||
newVoucher: {id: table.voucherId}
|
}).pipe(
|
||||||
}, options).pipe(
|
|
||||||
catchError(this.log.handleError(serviceName, 'mergeTable'))
|
catchError(this.log.handleError(serviceName, 'mergeTable'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
moveKotToNewTable(id: string, kotId: string, table: Table): Observable<boolean> {
|
moveKotToNewTable(id: string, kotId: string, table: Table): Observable<boolean> {
|
||||||
const options = {params: new HttpParams().set('move', '')};
|
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveKot}/move`, {
|
||||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveKot, {
|
voucherId: id,
|
||||||
voucher: {id: id},
|
kotId: kotId,
|
||||||
kot: {id: kotId},
|
tableId: table.id
|
||||||
table: {id: table.id}
|
}).pipe(
|
||||||
}, options).pipe(
|
|
||||||
catchError(this.log.handleError(serviceName, 'moveKotToNewTable'))
|
catchError(this.log.handleError(serviceName, 'moveKotToNewTable'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeKotWithOldBill(id: string, kotId: string, table: Table): Observable<boolean> {
|
mergeKotWithOldBill(id: string, kotId: string, table: Table): Observable<boolean> {
|
||||||
const options = {params: new HttpParams().set('merge', '')};
|
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveKot}/merge`, {
|
||||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveKot, {
|
voucherId: id,
|
||||||
voucher: {id: id},
|
kotId: kotId,
|
||||||
kot: {id: kotId},
|
tableId: table.id,
|
||||||
table: {id: table.id},
|
newVoucherId: table.voucherId
|
||||||
newVoucher: {id: table.voucherId}
|
}).pipe(
|
||||||
}, options).pipe(
|
|
||||||
catchError(this.log.handleError(serviceName, 'mergeKotWithOldBill'))
|
catchError(this.log.handleError(serviceName, 'mergeKotWithOldBill'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -265,7 +265,7 @@ export class SalesHomeComponent implements OnInit {
|
|||||||
if (!this.moveTableAllowed()) {
|
if (!this.moveTableAllowed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') === -1);
|
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') !== -1);
|
||||||
this.dialog.open(TablesDialogComponent, {
|
this.dialog.open(TablesDialogComponent, {
|
||||||
// width: '750px',
|
// width: '750px',
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
Reference in New Issue
Block a user