Cashier checkout should now work
This commit is contained in:
@ -24,7 +24,7 @@ class Customer(Base):
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
company = Column("company", Unicode(255), nullable=False)
|
||||
name = Column("name", Unicode(255), nullable=False)
|
||||
phone = Column("phone", Unicode(255), nullable=False, unique=True)
|
||||
phone = Column("phone", Unicode(255), nullable=True, unique=True)
|
||||
address = Column("address", Unicode(255), nullable=False)
|
||||
|
||||
@property
|
||||
|
||||
@ -13,7 +13,6 @@ from sqlalchemy import (
|
||||
Numeric,
|
||||
ForeignKey,
|
||||
UniqueConstraint,
|
||||
func,
|
||||
case,
|
||||
)
|
||||
from sqlalchemy.orm import relationship, backref, synonym
|
||||
@ -26,6 +25,7 @@ class VoucherType(Enum):
|
||||
REGULAR_BILL = 1
|
||||
NO_CHARGE = 2
|
||||
STAFF = 4
|
||||
VOID = 5
|
||||
|
||||
|
||||
class GuestBook(Base):
|
||||
@ -186,6 +186,8 @@ class Voucher(Base):
|
||||
return "ST-" + str(self.bill_id)
|
||||
if self.voucher_type == VoucherType.REGULAR_BILL:
|
||||
return str(self.bill_id // 10000) + "-" + str(self.bill_id % 10000)
|
||||
if self.voucher_type == VoucherType.VOID:
|
||||
return "K-" + str(self.kot_id)
|
||||
else:
|
||||
raise Exception
|
||||
|
||||
|
||||
@ -353,6 +353,10 @@ def includeme(config):
|
||||
config.add_route("v1_move_table", "/v1/move-table")
|
||||
config.add_route("v1_move_kot", "/v1/move-kot")
|
||||
|
||||
config.add_route("v1_active_cashiers", "/v1/active-cashiers")
|
||||
config.add_route("v1_checkout_id", "/v1/checkout/{id}")
|
||||
config.add_route("v1_checkout_blank", "/v1/checkout")
|
||||
|
||||
# Done till here
|
||||
|
||||
config.add_route("customer", "/Customer.json")
|
||||
@ -393,8 +397,6 @@ def includeme(config):
|
||||
config.add_route("api_lock_info", "/api/LockInfo")
|
||||
config.add_route("api_maintenance", "/api/Maintenance")
|
||||
|
||||
config.add_route("active_cashiers", "/Cashiers.json")
|
||||
config.add_route("checkout", "/Checkout/{id}.json")
|
||||
# config.add_route('customer_id', '/Customer/{id}.json')
|
||||
|
||||
config.add_route("beer_consumption", "/BeerConsumption.json")
|
||||
|
||||
@ -11,7 +11,6 @@ from barker.models import (
|
||||
DbSetting,
|
||||
Permission,
|
||||
User,
|
||||
FoodTable,
|
||||
get_engine,
|
||||
get_session_factory,
|
||||
get_tm_session,
|
||||
@ -45,123 +44,27 @@ def main(argv=sys.argv):
|
||||
with transaction.manager:
|
||||
dbsession = get_tm_session(session_factory, transaction.manager)
|
||||
|
||||
permissions = [
|
||||
Permission(
|
||||
"Accounts Audit", uuid.UUID("f30fd1fb-df09-46f5-8c5d-181fd46f38de")
|
||||
),
|
||||
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(
|
||||
"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(
|
||||
"Edit Printed Product",
|
||||
uuid.UUID("959713be-d753-4e14-8ecd-e27f33587499"),
|
||||
),
|
||||
Permission("Guest Book", uuid.UUID("7669dfc9-cc75-4e48-b267-145c8832a83c")),
|
||||
Permission("Machines", uuid.UUID("f12b573f-edcb-490d-91c3-fa76f6502ffd")),
|
||||
Permission("Merge Kots", uuid.UUID("bed774e9-4857-43b0-a4af-40230c9eb5db")),
|
||||
Permission(
|
||||
"Merge Tables", uuid.UUID("dfc493fb-ac14-4602-8596-f93f47b617de")
|
||||
),
|
||||
Permission("Modifiers", uuid.UUID("9dc82529-1e86-41b4-a152-eaea9f775fea")),
|
||||
Permission(
|
||||
"Move Kot to New Table",
|
||||
uuid.UUID("5ed5796a-ca99-437f-8f67-483b1ade81ed"),
|
||||
),
|
||||
Permission("Move Table", uuid.UUID("cfdb69c9-d37a-40af-bef2-e29c04602543")),
|
||||
Permission("NC Product", uuid.UUID("54263587-773e-4cbb-b1e4-4e814141158e")),
|
||||
Permission("Open Bill", uuid.UUID("5811d233-a1ae-4d32-af52-cebbf46d274a")),
|
||||
Permission("Owner", uuid.UUID("6d109b66-8452-42aa-bbe9-d4cef440b7a1")),
|
||||
Permission("Print Bill", uuid.UUID("92242eae-bd38-4223-829b-2f981933b7f2")),
|
||||
Permission("Print Kot", uuid.UUID("0eef56fb-7741-49fd-8b84-5069cccae767")),
|
||||
Permission("Products", uuid.UUID("f1f892ed-34aa-4c50-be12-dbaf48be7d4c")),
|
||||
Permission("Roles", uuid.UUID("d39f86f6-14e4-4fc3-b07e-01e2501a6f65")),
|
||||
Permission("Sales", uuid.UUID("92ba45c4-2d34-4cbd-b5b8-d9164c3595d5")),
|
||||
Permission(
|
||||
"Sales Analysis", uuid.UUID("0c1acb7c-9116-46e2-a3be-9d632e811330")
|
||||
),
|
||||
Permission(
|
||||
"Sales Detail", uuid.UUID("e6476396-ef83-4c47-bc20-9f3b936813f9")
|
||||
),
|
||||
Permission(
|
||||
"Settle Bill", uuid.UUID("9f7b658a-25bc-4a53-8560-2dde1c7a188a")
|
||||
),
|
||||
Permission("Split Bill", uuid.UUID("0a8cfaf4-624e-478f-be65-c3b6392078c7")),
|
||||
Permission("Tables", uuid.UUID("ac4512e8-efdd-429e-a7ae-a34d18782663")),
|
||||
Permission(
|
||||
"Tax Analysis", uuid.UUID("bab36396-53dd-44ea-ab3c-426efa7830c8")
|
||||
),
|
||||
Permission("Taxes", uuid.UUID("5c8fcdde-460d-4047-810f-e34fb899fadc")),
|
||||
Permission("Users", uuid.UUID("243447b8-b403-47e6-8b3d-8e76f4df44a9")),
|
||||
Permission("Void Bill", uuid.UUID("e3c76262-adc0-4936-8b4d-217c6292298b")),
|
||||
Permission(
|
||||
"Void or Reprinted Bill Report",
|
||||
uuid.UUID("30c8e743-c710-42d7-843a-0b75543b3516"),
|
||||
),
|
||||
Permission("Printers", uuid.UUID("5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c")),
|
||||
Permission("Sections", uuid.UUID("c973f32c-a37b-496a-8dc5-60d2e4c39e97")),
|
||||
]
|
||||
|
||||
for permission in permissions:
|
||||
dbsession.add(permission)
|
||||
|
||||
roles = [
|
||||
Role("Owner", uuid.UUID("06ec0ddb-949c-4357-aefb-65e5e55a9ae7")),
|
||||
Role("Accountant", uuid.UUID("57d4538c-257a-4bf4-9a42-342992cb6af3")),
|
||||
Role("Bar Captain", uuid.UUID("5a8ebb05-4817-45a5-866f-e523c30bfa25")),
|
||||
Role("Captain", uuid.UUID("8db7001f-0964-4607-84f5-b6f4d9183fef")),
|
||||
Role("Cashier", uuid.UUID("f1f0b112-1404-4b55-b121-f07ee6e08d12")),
|
||||
Role("Controller", uuid.UUID("d9a5a478-1fe4-4847-84da-63cfba1a094a")),
|
||||
Role("Manager", uuid.UUID("90ea7b14-9057-4bfd-a7cf-0ee7a3bb2463")),
|
||||
Role("Senior Captain", uuid.UUID("d9b1b433-1ed5-4109-8ab2-cbd48ff010cd")),
|
||||
Role("Server", uuid.UUID("6b378b71-f091-4485-a589-8db94ff1d6a4")),
|
||||
]
|
||||
|
||||
roles[0].permissions = permissions
|
||||
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[7].permissions = list(permissions[i] for i in [9, 12, 13, 15, 16])
|
||||
roles[8].permissions = list(permissions[i] for i in [21, 24])
|
||||
|
||||
for role in roles:
|
||||
dbsession.add(role)
|
||||
|
||||
admin = User("Admin", "123456", False)
|
||||
admin.roles.append(roles[0])
|
||||
dbsession.add(admin)
|
||||
prod = True
|
||||
if prod:
|
||||
dbsession.add(Permission("Guest Book", uuid.UUID("7669dfc9-cc75-4e48-b267-145c8832a83c")))
|
||||
dbsession.add(Permission("Printers", uuid.UUID("5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c")))
|
||||
dbsession.add(Permission("Sections", uuid.UUID("c973f32c-a37b-496a-8dc5-60d2e4c39e97")))
|
||||
else:
|
||||
add_permissions(dbsession)
|
||||
|
||||
main_section = Section(
|
||||
"Main", uuid.UUID("3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df")
|
||||
)
|
||||
dbsession.add(main_section)
|
||||
mcs = [
|
||||
ModifierCategory(
|
||||
"Old Modifiers",
|
||||
0,
|
||||
0,
|
||||
True,
|
||||
0,
|
||||
uuid.UUID("e046ad33-dc65-4c78-8833-c3d3538d44c0"),
|
||||
),
|
||||
ModifierCategory(
|
||||
"Bar Instructions",
|
||||
0,
|
||||
@ -249,3 +152,116 @@ def main(argv=sys.argv):
|
||||
{"Text": "Call: 0172-4026666, 8054923853, 8054923856"},
|
||||
)
|
||||
)
|
||||
|
||||
def add_permissions(dbsession):
|
||||
permissions = [
|
||||
Permission(
|
||||
"Accounts Audit", uuid.UUID("f30fd1fb-df09-46f5-8c5d-181fd46f38de")
|
||||
),
|
||||
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(
|
||||
"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(
|
||||
"Edit Printed Product",
|
||||
uuid.UUID("959713be-d753-4e14-8ecd-e27f33587499"),
|
||||
),
|
||||
Permission("Guest Book", uuid.UUID("7669dfc9-cc75-4e48-b267-145c8832a83c")),
|
||||
Permission("Machines", uuid.UUID("f12b573f-edcb-490d-91c3-fa76f6502ffd")),
|
||||
Permission("Merge Kots", uuid.UUID("bed774e9-4857-43b0-a4af-40230c9eb5db")),
|
||||
Permission(
|
||||
"Merge Tables", uuid.UUID("dfc493fb-ac14-4602-8596-f93f47b617de")
|
||||
),
|
||||
Permission("Modifiers", uuid.UUID("9dc82529-1e86-41b4-a152-eaea9f775fea")),
|
||||
Permission(
|
||||
"Move Kot to New Table",
|
||||
uuid.UUID("5ed5796a-ca99-437f-8f67-483b1ade81ed"),
|
||||
),
|
||||
Permission("Move Table", uuid.UUID("cfdb69c9-d37a-40af-bef2-e29c04602543")),
|
||||
Permission("NC Product", uuid.UUID("54263587-773e-4cbb-b1e4-4e814141158e")),
|
||||
Permission("Open Bill", uuid.UUID("5811d233-a1ae-4d32-af52-cebbf46d274a")),
|
||||
Permission("Owner", uuid.UUID("6d109b66-8452-42aa-bbe9-d4cef440b7a1")),
|
||||
Permission("Print Bill", uuid.UUID("92242eae-bd38-4223-829b-2f981933b7f2")),
|
||||
Permission("Print Kot", uuid.UUID("0eef56fb-7741-49fd-8b84-5069cccae767")),
|
||||
Permission("Products", uuid.UUID("f1f892ed-34aa-4c50-be12-dbaf48be7d4c")),
|
||||
Permission("Roles", uuid.UUID("d39f86f6-14e4-4fc3-b07e-01e2501a6f65")),
|
||||
Permission("Sales", uuid.UUID("92ba45c4-2d34-4cbd-b5b8-d9164c3595d5")),
|
||||
Permission(
|
||||
"Sales Analysis", uuid.UUID("0c1acb7c-9116-46e2-a3be-9d632e811330")
|
||||
),
|
||||
Permission(
|
||||
"Sales Detail", uuid.UUID("e6476396-ef83-4c47-bc20-9f3b936813f9")
|
||||
),
|
||||
Permission(
|
||||
"Settle Bill", uuid.UUID("9f7b658a-25bc-4a53-8560-2dde1c7a188a")
|
||||
),
|
||||
Permission("Split Bill", uuid.UUID("0a8cfaf4-624e-478f-be65-c3b6392078c7")),
|
||||
Permission("Tables", uuid.UUID("ac4512e8-efdd-429e-a7ae-a34d18782663")),
|
||||
Permission(
|
||||
"Tax Analysis", uuid.UUID("bab36396-53dd-44ea-ab3c-426efa7830c8")
|
||||
),
|
||||
Permission("Taxes", uuid.UUID("5c8fcdde-460d-4047-810f-e34fb899fadc")),
|
||||
Permission("Users", uuid.UUID("243447b8-b403-47e6-8b3d-8e76f4df44a9")),
|
||||
Permission("Void Bill", uuid.UUID("e3c76262-adc0-4936-8b4d-217c6292298b")),
|
||||
Permission(
|
||||
"Void or Reprinted Bill Report",
|
||||
uuid.UUID("30c8e743-c710-42d7-843a-0b75543b3516"),
|
||||
),
|
||||
Permission("Printers", uuid.UUID("5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c")),
|
||||
Permission("Sections", uuid.UUID("c973f32c-a37b-496a-8dc5-60d2e4c39e97")),
|
||||
]
|
||||
|
||||
for permission in permissions:
|
||||
dbsession.add(permission)
|
||||
|
||||
roles = [
|
||||
Role("Owner", uuid.UUID("06ec0ddb-949c-4357-aefb-65e5e55a9ae7")),
|
||||
Role("Accountant", uuid.UUID("57d4538c-257a-4bf4-9a42-342992cb6af3")),
|
||||
Role("Bar Captain", uuid.UUID("5a8ebb05-4817-45a5-866f-e523c30bfa25")),
|
||||
Role("Captain", uuid.UUID("8db7001f-0964-4607-84f5-b6f4d9183fef")),
|
||||
Role("Cashier", uuid.UUID("f1f0b112-1404-4b55-b121-f07ee6e08d12")),
|
||||
Role("Controller", uuid.UUID("d9a5a478-1fe4-4847-84da-63cfba1a094a")),
|
||||
Role("Manager", uuid.UUID("90ea7b14-9057-4bfd-a7cf-0ee7a3bb2463")),
|
||||
Role("Senior Captain", uuid.UUID("d9b1b433-1ed5-4109-8ab2-cbd48ff010cd")),
|
||||
Role("Server", uuid.UUID("6b378b71-f091-4485-a589-8db94ff1d6a4")),
|
||||
]
|
||||
|
||||
roles[0].permissions = permissions
|
||||
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[7].permissions = list(permissions[i] for i in [9, 12, 13, 15, 16])
|
||||
roles[8].permissions = list(permissions[i] for i in [21, 24])
|
||||
|
||||
for role in roles:
|
||||
dbsession.add(role)
|
||||
|
||||
admin = User("Admin", "123456", False)
|
||||
admin.roles.append(roles[0])
|
||||
dbsession.add(admin)
|
||||
|
||||
@ -1,78 +1,112 @@
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
from barker.models import Voucher, User, Settlement
|
||||
from barker.models.master import SettleOption
|
||||
from datetime import datetime, timedelta
|
||||
from barker.models import Voucher, User, Settlement, VoucherType
|
||||
from pyramid.view import view_config
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
__author__ = 'tanshu'
|
||||
__author__ = "tanshu"
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='active_cashiers', renderer='json', permission='Cashier Checkout',
|
||||
request_param=('s', 'f'))
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_active_cashiers",
|
||||
renderer="json",
|
||||
permission="Cashier Checkout"
|
||||
)
|
||||
def active_cashiers(request):
|
||||
start_date = datetime.datetime.strptime(request.GET['s'], '%d-%b-%Y %H:%M')
|
||||
finish_date = datetime.datetime.strptime(request.GET['f'], '%d-%b-%Y %H:%M')
|
||||
start_date = request.GET.get("s", None)
|
||||
if not start_date:
|
||||
start_date = datetime.today().replace(hour=7, minute=0)
|
||||
else:
|
||||
start_date = datetime.strptime(start_date, "%d-%b-%Y").replace(hour=7, minute=0)
|
||||
|
||||
user_ids = request.dbsession.query(Voucher.user_id).filter(
|
||||
Voucher.date >= start_date,
|
||||
Voucher.date <= finish_date
|
||||
).distinct()
|
||||
finish_date = request.GET.get("f", None)
|
||||
if not finish_date:
|
||||
finish_date = datetime.today().replace(hour=7, minute=0) + timedelta(days=1)
|
||||
else:
|
||||
finish_date = datetime.strptime(finish_date, "%d-%b-%Y").replace(hour=7, minute=0) + timedelta(days=1)
|
||||
|
||||
users = request.dbsession.query(
|
||||
User
|
||||
).filter(
|
||||
User.id.in_(user_ids)
|
||||
).order_by(
|
||||
User.name
|
||||
).all()
|
||||
user_ids = (
|
||||
request.dbsession.query(Voucher.user_id)
|
||||
.filter(Voucher.date >= start_date, Voucher.date <= finish_date)
|
||||
.distinct()
|
||||
)
|
||||
|
||||
return [{'UserID': u.id, 'Name': u.name} for u in users]
|
||||
users = (
|
||||
request.dbsession.query(User)
|
||||
.filter(User.id.in_(user_ids))
|
||||
.order_by(User.name)
|
||||
.all()
|
||||
)
|
||||
|
||||
return [{"id": u.id, "name": u.name} for u in users]
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='checkout', renderer='json', permission='Cashier Checkout',
|
||||
request_param=('s', 'f'))
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_checkout_blank",
|
||||
renderer="json",
|
||||
permission="Cashier Checkout"
|
||||
)
|
||||
def blank_out(request):
|
||||
return {
|
||||
"startDate": datetime.today().strftime("%d-%b-%Y"),
|
||||
"finishDate": datetime.today().strftime("%d-%b-%Y"),
|
||||
"user": {"id": ''},
|
||||
"amounts": [],
|
||||
"info": []
|
||||
}
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_checkout_id",
|
||||
renderer="json",
|
||||
permission="Cashier Checkout",
|
||||
request_param=("s", "f"),
|
||||
)
|
||||
def check_me_out(request):
|
||||
id = uuid.UUID(request.matchdict['id'])
|
||||
start_date = datetime.datetime.strptime(request.GET['s'], '%d-%b-%Y %H:%M')
|
||||
finish_date = datetime.datetime.strptime(request.GET['f'], '%d-%b-%Y %H:%M')
|
||||
id_ = uuid.UUID(request.matchdict["id"])
|
||||
start_date = datetime.strptime(request.GET["s"], "%d-%b-%Y").replace(hour=7, minute=0)
|
||||
finish_date = datetime.strptime(request.GET["f"], "%d-%b-%Y").replace(hour=7, minute=0) + timedelta(days=1)
|
||||
|
||||
vouchers = request.dbsession.query(
|
||||
Voucher
|
||||
).options(
|
||||
joinedload(Voucher.settlements, innerjoin=True).joinedload(Settlement.settle_option, innerjoin=True),
|
||||
joinedload(Voucher.customer, innerjoin=True)
|
||||
).filter(
|
||||
Voucher.date >= start_date,
|
||||
Voucher.date <= finish_date,
|
||||
Voucher.user_id == id
|
||||
).order_by(
|
||||
Voucher.voucher_type
|
||||
).order_by(
|
||||
Voucher.bill_id
|
||||
).all()
|
||||
vouchers = (
|
||||
request.dbsession.query(Voucher)
|
||||
.options(
|
||||
joinedload(Voucher.settlements, innerjoin=True).joinedload(
|
||||
Settlement.settle_option, innerjoin=True
|
||||
)
|
||||
)
|
||||
.filter(
|
||||
Voucher.date >= start_date,
|
||||
Voucher.date <= finish_date,
|
||||
Voucher.user_id == id_,
|
||||
)
|
||||
.order_by(Voucher.voucher_type)
|
||||
.order_by(Voucher.bill_id)
|
||||
.all()
|
||||
)
|
||||
|
||||
info = {}
|
||||
amounts = {}
|
||||
for item in vouchers:
|
||||
if item.is_void:
|
||||
if SettleOption.VOID() not in info:
|
||||
info[SettleOption.VOID()] = []
|
||||
amount = next(s.amount * -1 for s in item.settlements if s.settled == SettleOption.AMOUNT())
|
||||
info[SettleOption.VOID()].append({
|
||||
'Date': item.date.strftime('%d-%b-%Y %H:%M:%S'),
|
||||
'BillID': item.full_bill_id,
|
||||
'Customer': item.customer.name,
|
||||
'Amount': amount
|
||||
})
|
||||
else:
|
||||
for so in (so for so in item.settlements if so.settle_option.show_in_choices):
|
||||
if so.settled not in info:
|
||||
info[so.settled] = []
|
||||
info[so.settled].append({
|
||||
'Date': item.date.strftime('%d-%b-%Y %H:%M:%S'),
|
||||
'BillID': item.full_bill_id,
|
||||
'Customer': item.customer.name,
|
||||
'Amount': so.amount
|
||||
})
|
||||
return info
|
||||
for so in (so for so in item.settlements if so.settle_option.show_in_choices):
|
||||
if so.settled not in info:
|
||||
info[so.settled] = []
|
||||
amounts[so.settle_option.name] = 0
|
||||
info[so.settled].append(
|
||||
{
|
||||
"date": item.date.strftime("%d-%b-%Y %H:%M:%S"),
|
||||
"billId": item.full_bill_id,
|
||||
"customer": item.customer.name if item.customer is not None else "",
|
||||
"amount": so.amount,
|
||||
}
|
||||
)
|
||||
amounts[so.settle_option.name] += so.amount
|
||||
return {
|
||||
"startDate": start_date.strftime("%d-%b-%Y"),
|
||||
"finishDate": finish_date.strftime("%d-%b-%Y"),
|
||||
"user": {"id": id_},
|
||||
"amounts": [{'name': key, 'amount': value} for key, value in amounts.items()], "info": info
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import uuid
|
||||
import transaction
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Voucher, SettleOption, Settlement, Overview
|
||||
from barker.models import Voucher, SettleOption, Settlement, Overview, VoucherType
|
||||
|
||||
|
||||
@view_config(
|
||||
@ -23,6 +23,7 @@ def void_voucher(request):
|
||||
|
||||
item.void = True
|
||||
item.void_reason = reason
|
||||
item.voucher_type = VoucherType.VOID
|
||||
|
||||
do_void_settlements(item, request.dbsession)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user