2017-03-14 12:56:57 +00:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
import transaction
|
2019-08-17 19:35:59 +00:00
|
|
|
from datetime import datetime
|
2017-03-14 12:56:57 +00:00
|
|
|
from pyramid.view import view_config
|
2019-08-17 19:35:59 +00:00
|
|
|
from sqlalchemy import func
|
2017-03-14 12:56:57 +00:00
|
|
|
|
2019-06-13 19:02:34 +00:00
|
|
|
from barker.models import Kot, Voucher, Overview
|
2019-08-17 19:35:59 +00:00
|
|
|
from barker.views.voucher import get_bill_id, do_update_table
|
2017-03-14 12:56:57 +00:00
|
|
|
|
|
|
|
|
2019-08-10 08:51:40 +00:00
|
|
|
@view_config(
|
|
|
|
request_method="POST",
|
2019-08-17 19:35:59 +00:00
|
|
|
route_name="v1_move_kot",
|
2019-08-10 08:51:40 +00:00
|
|
|
renderer="json",
|
2019-08-17 19:35:59 +00:00
|
|
|
request_param="merge",
|
2019-08-10 08:51:40 +00:00
|
|
|
permission="Merge Kots",
|
|
|
|
trans=True,
|
|
|
|
)
|
2017-03-14 12:56:57 +00:00
|
|
|
def merge_kot(request):
|
|
|
|
json = request.json_body
|
2019-08-17 19:35:59 +00:00
|
|
|
kot_id = uuid.UUID(json["kot"]["id"])
|
|
|
|
new_voucher_id = uuid.UUID(json["newVoucher"]["id"])
|
2017-03-14 12:56:57 +00:00
|
|
|
|
2020-06-14 13:13:10 +00:00
|
|
|
request.dbsession.query(Kot).filter(Kot.id == kot_id).update({Kot.voucher_id: new_voucher_id})
|
2017-03-14 12:56:57 +00:00
|
|
|
transaction.commit()
|
2019-08-17 19:35:59 +00:00
|
|
|
return True
|
2017-03-14 12:56:57 +00:00
|
|
|
|
|
|
|
|
2019-08-10 08:51:40 +00:00
|
|
|
@view_config(
|
|
|
|
request_method="POST",
|
2019-08-17 19:35:59 +00:00
|
|
|
route_name="v1_move_kot",
|
2019-08-10 08:51:40 +00:00
|
|
|
renderer="json",
|
2019-08-17 19:35:59 +00:00
|
|
|
request_param="move",
|
|
|
|
permission="Move Kot to New Table",
|
2019-08-10 08:51:40 +00:00
|
|
|
trans=True,
|
|
|
|
)
|
2017-03-14 12:56:57 +00:00
|
|
|
def move_kot(request):
|
|
|
|
json = request.json_body
|
2019-08-17 19:35:59 +00:00
|
|
|
now = datetime.now()
|
|
|
|
kot_id = uuid.UUID(json["kot"]["id"])
|
|
|
|
table_id = uuid.UUID(json["table"]["id"])
|
2017-03-14 12:56:57 +00:00
|
|
|
|
|
|
|
kot = request.dbsession.query(Kot).filter(Kot.id == kot_id).first()
|
2019-08-17 19:35:59 +00:00
|
|
|
bill_id = get_bill_id(kot.voucher.voucher_type, request.dbsession)
|
2020-06-14 13:13:10 +00:00
|
|
|
kot_id = request.dbsession.query(func.coalesce(func.max(Voucher.kot_id), 0) + 1).scalar()
|
2017-03-14 12:56:57 +00:00
|
|
|
|
2019-08-10 08:51:40 +00:00
|
|
|
item = Voucher(
|
2019-08-17 19:35:59 +00:00
|
|
|
now,
|
2019-08-10 08:51:40 +00:00
|
|
|
kot.voucher.pax,
|
2019-08-17 19:35:59 +00:00
|
|
|
bill_id,
|
|
|
|
kot_id,
|
|
|
|
table_id,
|
2019-08-10 08:51:40 +00:00
|
|
|
kot.voucher.customer_id,
|
|
|
|
kot.voucher.voucher_type,
|
2020-06-14 13:13:10 +00:00
|
|
|
uuid.UUID(request.authenticated_userid),
|
2019-08-10 08:51:40 +00:00
|
|
|
)
|
2017-03-14 12:56:57 +00:00
|
|
|
request.dbsession.add(item)
|
|
|
|
item.kots.append(kot)
|
2019-08-17 19:35:59 +00:00
|
|
|
do_update_table(item, None, request.dbsession)
|
2017-03-14 12:56:57 +00:00
|
|
|
request.dbsession.add(item.status)
|
|
|
|
transaction.commit()
|
2019-08-17 19:35:59 +00:00
|
|
|
return True
|
2017-03-14 12:56:57 +00:00
|
|
|
|
|
|
|
|
2019-08-10 08:51:40 +00:00
|
|
|
@view_config(
|
|
|
|
request_method="POST",
|
2019-08-17 19:35:59 +00:00
|
|
|
route_name="v1_move_table",
|
|
|
|
request_param="move",
|
2019-08-10 08:51:40 +00:00
|
|
|
renderer="json",
|
|
|
|
permission="Move Table",
|
|
|
|
trans=True,
|
|
|
|
)
|
2017-03-14 12:56:57 +00:00
|
|
|
def move_table(request):
|
2019-08-17 19:35:59 +00:00
|
|
|
id_ = uuid.UUID(request.json_body["voucher"]["id"])
|
2019-08-10 14:13:35 +00:00
|
|
|
table_id = uuid.UUID(request.json_body["table"]["id"])
|
2017-03-14 12:56:57 +00:00
|
|
|
|
2020-06-14 13:13:10 +00:00
|
|
|
request.dbsession.query(Overview).filter(Overview.voucher_id == id_).update({Overview.food_table_id: table_id})
|
2017-03-14 12:56:57 +00:00
|
|
|
|
2020-06-14 13:13:10 +00:00
|
|
|
request.dbsession.query(Voucher).filter(Voucher.id == id_).update({Voucher.food_table_id: table_id})
|
2017-03-14 12:56:57 +00:00
|
|
|
|
|
|
|
transaction.commit()
|
2019-08-10 08:51:40 +00:00
|
|
|
return True
|
2017-03-14 12:56:57 +00:00
|
|
|
|
|
|
|
|
2019-08-10 08:51:40 +00:00
|
|
|
@view_config(
|
|
|
|
request_method="POST",
|
2019-08-17 19:35:59 +00:00
|
|
|
route_name="v1_move_table",
|
|
|
|
request_param="merge",
|
2019-08-10 08:51:40 +00:00
|
|
|
renderer="json",
|
|
|
|
permission="Merge Tables",
|
|
|
|
trans=True,
|
|
|
|
)
|
2017-03-14 12:56:57 +00:00
|
|
|
def merge_table(request):
|
|
|
|
json = request.json_body
|
|
|
|
|
2019-08-17 19:35:59 +00:00
|
|
|
id_ = uuid.UUID(json["oldVoucher"]["id"])
|
|
|
|
# table_id = uuid.UUID(json["table"]["id"])
|
|
|
|
new_voucher_id = uuid.UUID(json["newVoucher"]["id"])
|
|
|
|
|
2020-06-14 13:13:10 +00:00
|
|
|
request.dbsession.query(Kot).filter(Kot.voucher_id == id_).update({Kot.voucher_id: new_voucher_id})
|
2019-08-17 19:35:59 +00:00
|
|
|
request.dbsession.query(Voucher).filter(Voucher.id == id_).delete()
|
2017-03-14 12:56:57 +00:00
|
|
|
transaction.commit()
|
2019-08-17 19:35:59 +00:00
|
|
|
return True
|
2017-03-14 12:56:57 +00:00
|
|
|
|
|
|
|
# VoucherBI.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null);
|
|
|
|
# throw new NotImplementedException();
|
|
|
|
# var newTable = _session.QueryOver<FoodTable>().Where(x => x.Name == tableName).SingleOrDefault();
|
|
|
|
# var newVoucher = _session.Get<Voucher>(newTable.VoucherID);
|
|
|
|
# var oldVoucher = _session.Get<Voucher>(voucherID);
|
|
|
|
# for (var i = oldVoucher.Kots.Count - 1; i >= 0; i--)
|
|
|
|
# {
|
|
|
|
# var kot = oldVoucher.Kots[i];
|
|
|
|
# oldVoucher.Kots.Remove(kot);
|
|
|
|
# kot.Voucher = newVoucher;
|
|
|
|
# newVoucher.Kots.Add(kot);
|
|
|
|
# _session.Update(kot);
|
|
|
|
# }
|
|
|
|
# _session.Update(newVoucher);
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# foreach (var item in oldVoucher.Settlements)
|
|
|
|
# {
|
|
|
|
# _session.Delete(item);
|
|
|
|
# }
|
|
|
|
# _session.Delete(oldVoucher);
|
|
|
|
# return newVoucher.VoucherID;
|