Section
This commit is contained in:
@ -6,28 +6,28 @@ import zope.sqlalchemy
|
||||
# import or define all models here to ensure they are attached to the
|
||||
# Base.metadata prior to any initialization routines
|
||||
from .voucher import (
|
||||
GuestBook,
|
||||
Inventory,
|
||||
InventoryModifier,
|
||||
Kot,
|
||||
Overview,
|
||||
Reprint,
|
||||
Settlement,
|
||||
Voucher,
|
||||
GuestBook,
|
||||
Overview,
|
||||
VoucherType
|
||||
)
|
||||
from .master import (
|
||||
Customer,
|
||||
DbSetting,
|
||||
Device,
|
||||
FoodTable,
|
||||
Location,
|
||||
MachineLocation,
|
||||
Modifier,
|
||||
Printer,
|
||||
PrintLocation,
|
||||
Product,
|
||||
MenuCategory,
|
||||
Modifier,
|
||||
ModifierCategory,
|
||||
Printer,
|
||||
Product,
|
||||
Section,
|
||||
SectionPrinter,
|
||||
SaleCategory,
|
||||
SettleOption,
|
||||
Tax
|
||||
|
||||
@ -10,7 +10,8 @@ from sqlalchemy import (
|
||||
Integer,
|
||||
case,
|
||||
JSON,
|
||||
Table)
|
||||
Table,
|
||||
)
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.orm import relationship
|
||||
from .meta import Base
|
||||
@ -48,7 +49,9 @@ class FoodTable(Base):
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), nullable=False, unique=True)
|
||||
seats = Column("seats", Numeric, nullable=False)
|
||||
section = Column("section", Unicode(255), nullable=False)
|
||||
section_id = Column("section_id", GUID(), ForeignKey("sections.id"), nullable=False)
|
||||
|
||||
section = relationship("Section", foreign_keys=section_id)
|
||||
|
||||
is_active = Column("is_active", Boolean, nullable=False)
|
||||
sort_order = Column("sort_order", Numeric, nullable=False)
|
||||
@ -58,11 +61,17 @@ class FoodTable(Base):
|
||||
return self.name
|
||||
|
||||
def __init__(
|
||||
self, name=None, seats=None, section=None, is_active=None, sort_order=0, id=None
|
||||
self,
|
||||
name=None,
|
||||
seats=None,
|
||||
section_id=None,
|
||||
is_active=None,
|
||||
sort_order=0,
|
||||
id=None,
|
||||
):
|
||||
self.name = name
|
||||
self.seats = seats
|
||||
self.section = section
|
||||
self.section_id = section_id
|
||||
self.is_active = is_active
|
||||
self.sort_order = sort_order
|
||||
self.id = id
|
||||
@ -95,13 +104,7 @@ class MenuCategory(Base):
|
||||
sort_order = Column("sort_order", Numeric, nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
discount_limit,
|
||||
is_active,
|
||||
sort_order,
|
||||
is_fixture=False,
|
||||
id=None,
|
||||
self, name, discount_limit, is_active, sort_order, is_fixture=False, id=None
|
||||
):
|
||||
self.name = name
|
||||
self.discount_limit = discount_limit
|
||||
@ -149,7 +152,12 @@ class Product(Base):
|
||||
|
||||
menu_category = relationship("MenuCategory", backref="products")
|
||||
sale_category = relationship("SaleCategory", backref="products")
|
||||
modifier_categories = relationship("ModifierCategory", secondary="modifier_categories_products", order_by="ModifierCategory.sort_order", backref="products")
|
||||
modifier_categories = relationship(
|
||||
"ModifierCategory",
|
||||
secondary="modifier_categories_products",
|
||||
order_by="ModifierCategory.sort_order",
|
||||
backref="products",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -199,11 +207,17 @@ class Product(Base):
|
||||
|
||||
|
||||
modifier_categories_products = Table(
|
||||
'modifier_categories_products', Base.metadata,
|
||||
Column('id', GUID(), primary_key=True, default=uuid.uuid4),
|
||||
Column('product_id', GUID(), ForeignKey('products.id'), nullable=False),
|
||||
Column('modifier_categories_id', GUID(), ForeignKey('modifier_categories.id'), nullable=False),
|
||||
UniqueConstraint('product_id', 'modifier_categories_id')
|
||||
"modifier_categories_products",
|
||||
Base.metadata,
|
||||
Column("id", GUID(), primary_key=True, default=uuid.uuid4),
|
||||
Column("product_id", GUID(), ForeignKey("products.id"), nullable=False),
|
||||
Column(
|
||||
"modifier_categories_id",
|
||||
GUID(),
|
||||
ForeignKey("modifier_categories.id"),
|
||||
nullable=False,
|
||||
),
|
||||
UniqueConstraint("product_id", "modifier_categories_id"),
|
||||
)
|
||||
|
||||
|
||||
@ -232,12 +246,22 @@ class Modifier(Base):
|
||||
show_in_bill = Column("show_in_bill", Boolean, nullable=False)
|
||||
price = Column("price", Numeric, nullable=False)
|
||||
modifier_category_id = Column(
|
||||
"modifier_category_id", GUID(), ForeignKey("modifier_categories.id"), nullable=False
|
||||
"modifier_category_id",
|
||||
GUID(),
|
||||
ForeignKey("modifier_categories.id"),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
modifier_category = relationship("ModifierCategory", backref="modifiers")
|
||||
|
||||
def __init__(self, name=None, show_in_bill=None, price=None, modifier_category_id=None, id=None):
|
||||
def __init__(
|
||||
self,
|
||||
name=None,
|
||||
show_in_bill=None,
|
||||
price=None,
|
||||
modifier_category_id=None,
|
||||
id=None,
|
||||
):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.show_in_bill = show_in_bill
|
||||
@ -258,31 +282,29 @@ class DbSetting(Base):
|
||||
self.data = data
|
||||
|
||||
|
||||
class Location(Base):
|
||||
__tablename__ = "locations"
|
||||
class Section(Base):
|
||||
__tablename__ = "sections"
|
||||
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||
|
||||
def __init__(self, id=None, name=None):
|
||||
def __init__(self, name=None, id=None):
|
||||
self.id = id
|
||||
self.name = name
|
||||
|
||||
|
||||
class MachineLocation(Base):
|
||||
__tablename__ = "machine_locations"
|
||||
class Device(Base):
|
||||
__tablename__ = "devices"
|
||||
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
machine_name = Column("machine_name", Unicode(255), unique=True, nullable=False)
|
||||
location_id = Column(
|
||||
"location_id", GUID(), ForeignKey("locations.id"), nullable=False
|
||||
)
|
||||
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||
section_id = Column("section_id", GUID(), ForeignKey("sections.id"), nullable=False)
|
||||
|
||||
location = relationship("Location", backref="machines")
|
||||
section = relationship("Section", foreign_keys=section_id)
|
||||
|
||||
def __init__(self, machine_name=None, location_id=None, id=None):
|
||||
self.machine_name = machine_name
|
||||
self.location_id = location_id
|
||||
def __init__(self, name=None, section_id=None, id=None):
|
||||
self.name = name
|
||||
self.section_id = section_id
|
||||
self.id = id
|
||||
|
||||
|
||||
@ -301,27 +323,25 @@ class Printer(Base):
|
||||
self.cut_code = cut_code
|
||||
|
||||
|
||||
class PrintLocation(Base):
|
||||
__tablename__ = "print_locations"
|
||||
__table_args__ = (UniqueConstraint("menu_category_id", "location_id"),)
|
||||
class SectionPrinter(Base):
|
||||
__tablename__ = "section_printers"
|
||||
__table_args__ = (UniqueConstraint("menu_category_id", "section_id"),)
|
||||
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
menu_category_id = Column(
|
||||
"menu_category_id", GUID(), ForeignKey("menu_categories.id")
|
||||
)
|
||||
location_id = Column(
|
||||
"location_id", GUID(), ForeignKey("locations.id"), nullable=False
|
||||
)
|
||||
section_id = Column("section_id", GUID(), ForeignKey("sections.id"), nullable=False)
|
||||
printer_id = Column("printer_id", GUID(), ForeignKey("printers.id"), nullable=False)
|
||||
copies = Column("copies", Numeric, nullable=False)
|
||||
|
||||
menu_category = relationship("MenuCategory", backref="print_locations")
|
||||
location = relationship("Location", backref="print_locations")
|
||||
printer = relationship("Printer", backref="print_locations")
|
||||
menu_category = relationship("MenuCategory", backref="section_printers")
|
||||
section = relationship("Section", backref="section_printers")
|
||||
printer = relationship("Printer", backref="section_printers")
|
||||
|
||||
def __init__(self, menu_category_id, location_id, printer_id, copies):
|
||||
def __init__(self, menu_category_id, section_id, printer_id, copies):
|
||||
self.menu_category_id = menu_category_id
|
||||
self.location_id = location_id
|
||||
self.section_id = section_id
|
||||
self.printer_id = printer_id
|
||||
self.copies = copies
|
||||
|
||||
|
||||
@ -73,6 +73,23 @@ def includeme(config):
|
||||
config.add_route("v1_modifiers_id", "/v1/modifiers/{id}")
|
||||
config.add_route("v1_modifiers_list", "/v1/modifiers")
|
||||
|
||||
config.add_route("sections_new", "/sections/new")
|
||||
config.add_route("sections_id", "/sections/{id}")
|
||||
config.add_route("sections_list", "/sections")
|
||||
config.add_route("v1_sections_new", "/v1/sections/new")
|
||||
config.add_route("v1_sections_id", "/v1/sections/{id}")
|
||||
config.add_route("v1_sections_list", "/v1/sections")
|
||||
|
||||
config.add_route("section_printers", "/section-printers/{section_id}")
|
||||
config.add_route("v1_section_printers", "/v1/section-printers/{section_id}")
|
||||
|
||||
config.add_route("devices_new", "/devices/new")
|
||||
config.add_route("devices_id", "/devices/{id}")
|
||||
config.add_route("devices_list", "/devices")
|
||||
config.add_route("v1_devices_new", "/v1/devices/new")
|
||||
config.add_route("v1_devices_id", "/v1/devices/{id}")
|
||||
config.add_route("v1_devices_list", "/v1/devices")
|
||||
|
||||
config.add_route("v1_bills_new", "/v1/bills/new")
|
||||
config.add_route("v1_bills_id", "/v1/bills/{id}")
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ from barker.models import (
|
||||
get_session_factory,
|
||||
get_tm_session,
|
||||
SettleOption,
|
||||
Role)
|
||||
Role, Section)
|
||||
|
||||
|
||||
def usage(argv):
|
||||
@ -78,7 +78,8 @@ def main(argv=sys.argv):
|
||||
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('Printers', uuid.UUID('5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c')),
|
||||
Permission('Sections', uuid.UUID('c973f32c-a37b-496a-8dc5-60d2e4c39e97'))]
|
||||
|
||||
for permission in permissions:
|
||||
dbsession.add(permission)
|
||||
@ -110,8 +111,13 @@ def main(argv=sys.argv):
|
||||
admin.roles.append(roles[0])
|
||||
dbsession.add(admin)
|
||||
|
||||
main_section = Section("Main")
|
||||
dbsession.add(main_section)
|
||||
|
||||
for name in range(1, 20):
|
||||
dbsession.add(FoodTable(str(name), 0, "", True))
|
||||
ft = FoodTable(str(name), 0, main_section.id, True)
|
||||
ft.section = main_section
|
||||
dbsession.add(ft)
|
||||
|
||||
options = [
|
||||
SettleOption('Unsettled', False, 1, True, 1),
|
||||
|
||||
@ -19,33 +19,33 @@ from barker.models import (
|
||||
Client,
|
||||
Customer,
|
||||
DbSetting,
|
||||
Device,
|
||||
FoodTable,
|
||||
GuestBook,
|
||||
Inventory,
|
||||
InventoryModifier,
|
||||
Kot,
|
||||
Location,
|
||||
LoginHistory,
|
||||
MachineLocation,
|
||||
MenuCategory,
|
||||
Modifier,
|
||||
ModifierCategory,
|
||||
Overview,
|
||||
Permission,
|
||||
PrintLocation,
|
||||
Printer,
|
||||
Product,
|
||||
MenuCategory,
|
||||
ModifierCategory,
|
||||
SaleCategory,
|
||||
Reprint,
|
||||
Role,
|
||||
role_permissions,
|
||||
SaleCategory,
|
||||
Section,
|
||||
SectionPrinter,
|
||||
SettleOption,
|
||||
Settlement,
|
||||
Tax,
|
||||
User,
|
||||
user_roles,
|
||||
Voucher,
|
||||
GuestBook,
|
||||
Overview,
|
||||
VoucherType,
|
||||
VoucherType
|
||||
)
|
||||
|
||||
|
||||
|
||||
130
barker/views/device.py
Normal file
130
barker/views/device.py
Normal file
@ -0,0 +1,130 @@
|
||||
import uuid
|
||||
|
||||
import transaction
|
||||
from pyramid.response import Response
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Device
|
||||
from barker.models.validation_exception import ValidationError
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="POST",
|
||||
route_name="v1_devices_new",
|
||||
renderer="json",
|
||||
permission="Products",
|
||||
trans=True,
|
||||
)
|
||||
def save(request):
|
||||
json = request.json_body
|
||||
name = json.get("name", "").strip()
|
||||
if name == "":
|
||||
raise ValidationError("Name cannot be blank")
|
||||
section = json.get("section", None)
|
||||
if section is None:
|
||||
raise ValidationError("please choose a section")
|
||||
section_id = uuid.UUID(section["id"])
|
||||
item = Device(name, section_id)
|
||||
request.dbsession.add(item)
|
||||
transaction.commit()
|
||||
return device_info(item.id, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="PUT",
|
||||
route_name="v1_devices_id",
|
||||
renderer="json",
|
||||
permission="Products",
|
||||
trans=True,
|
||||
)
|
||||
def update(request):
|
||||
json = request.json_body
|
||||
item = (
|
||||
request.dbsession.query(Device)
|
||||
.filter(Device.id == uuid.UUID(request.matchdict["id"]))
|
||||
.first()
|
||||
)
|
||||
if item.is_fixture:
|
||||
raise ValidationError(
|
||||
"{0} is a fixture and cannot be edited or deleted.".format(item.full_name)
|
||||
)
|
||||
item.name = json["name"].strip()
|
||||
item.section_id = uuid.UUID(json["section"]["id"])
|
||||
transaction.commit()
|
||||
return device_info(item.id, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="DELETE",
|
||||
route_name="v1_devices_id",
|
||||
renderer="json",
|
||||
permission="Products",
|
||||
trans=True,
|
||||
)
|
||||
def delete(request):
|
||||
item = (
|
||||
request.dbsession.query(Device)
|
||||
.filter(Device.id == uuid.UUID(request.matchdict["id"]))
|
||||
.first()
|
||||
)
|
||||
if item is None:
|
||||
response = Response("Device not Found")
|
||||
response.status_int = 500
|
||||
return response
|
||||
else:
|
||||
response = Response("Device deletion not implemented")
|
||||
response.status_int = 500
|
||||
return response
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_devices_new",
|
||||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_blank(request):
|
||||
return device_info(None, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_devices_id",
|
||||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_id(request):
|
||||
return device_info(uuid.UUID(request.matchdict["id"]), request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_devices_list",
|
||||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_list(request):
|
||||
list_ = (
|
||||
request.dbsession.query(Device)
|
||||
.order_by(Device.name)
|
||||
.all()
|
||||
)
|
||||
devices = []
|
||||
for item in list_:
|
||||
devices.append(device_info(item, request.dbsession))
|
||||
return devices
|
||||
|
||||
|
||||
def device_info(item, dbsession):
|
||||
if item is None:
|
||||
return {
|
||||
"name": "",
|
||||
"section": {}
|
||||
}
|
||||
if type(item) is uuid.UUID:
|
||||
item = dbsession.query(Device).filter(Device.id == item).first()
|
||||
return {
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"section": {"id": item.section_id, "name": item.section.name}
|
||||
}
|
||||
@ -1,9 +1,6 @@
|
||||
import re
|
||||
import uuid
|
||||
|
||||
import transaction
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import FoodTable, Overview
|
||||
from barker.models.validation_exception import ValidationError
|
||||
|
||||
@ -27,9 +24,12 @@ def save(request):
|
||||
raise ValidationError("Seats must be an integer >= 0")
|
||||
except ValueError:
|
||||
raise ValidationError("Seats must be an integer >= 0")
|
||||
section = json.get("section", "").strip()
|
||||
section = json.get("section", None)
|
||||
if section is None:
|
||||
raise ValidationError("please choose a section")
|
||||
section_id = uuid.UUID(section["id"])
|
||||
is_active = json.get("isActive", True)
|
||||
item = FoodTable(name, seats, section, is_active)
|
||||
item = FoodTable(name, seats, section_id, is_active)
|
||||
request.dbsession.add(item)
|
||||
transaction.commit()
|
||||
return food_table_info(item.id, request.dbsession)
|
||||
@ -58,7 +58,7 @@ def update(request):
|
||||
raise ValidationError("Seats must be an integer >= 0")
|
||||
except ValueError:
|
||||
raise ValidationError("Seats must be an integer >= 0")
|
||||
item.section = json.get("section", "").strip()
|
||||
item.section_id = uuid.UUID(json["section"]["id"])
|
||||
item.is_active = json.get("isActive", True)
|
||||
transaction.commit()
|
||||
return food_table_info(item.id, request.dbsession)
|
||||
@ -138,7 +138,7 @@ def show_list(request):
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"seats": item.seats,
|
||||
"section": item.section,
|
||||
"section": {"id": item.section_id, "name": item.section.name},
|
||||
"isActive": item.is_active,
|
||||
"sortOrder": item.sort_order,
|
||||
"status": "" if item.status is None else item.status.status,
|
||||
@ -165,20 +165,14 @@ def sort_order(request):
|
||||
|
||||
def food_table_info(item, dbsession):
|
||||
if item is None:
|
||||
return {
|
||||
"name": "",
|
||||
"seats": 0,
|
||||
"section": "",
|
||||
"isActive": True,
|
||||
"sortOrder": 0
|
||||
}
|
||||
return {"name": "", "seats": 0, "section": {}, "isActive": True, "sortOrder": 0}
|
||||
if type(item) == uuid.UUID:
|
||||
item = dbsession.query(FoodTable).filter(FoodTable.id == item).first()
|
||||
return {
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"seats":item.seats,
|
||||
"section": item.section,
|
||||
"seats": item.seats,
|
||||
"section": {"id": item.section_id, "name":item.section.name},
|
||||
"isActive": item.is_active,
|
||||
"status": "" if item.status is None else item.status.status,
|
||||
"sortOrder": item.sort_order,
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Location
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='location_list', renderer='json', permission='Everyone')
|
||||
def show_list(request):
|
||||
list = request.dbsession.query(Location).order_by(Location.name).all()
|
||||
locations = []
|
||||
for item in list:
|
||||
locations.append(item.name)
|
||||
return locations
|
||||
@ -1,78 +0,0 @@
|
||||
import uuid
|
||||
|
||||
import transaction
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Location, MachineLocation
|
||||
|
||||
|
||||
@view_config(request_method='PUT', route_name='machine_location', renderer='json', permission='Everyone', trans=True)
|
||||
def save(request):
|
||||
json = request.json_body
|
||||
item = MachineLocation(json['Machine'])
|
||||
item.location = request.dbsession.query(Location).filter(Location.name == json['Location']).first()
|
||||
request.dbsession.add(item)
|
||||
transaction.commit()
|
||||
item = request.dbsession.query(MachineLocation).filter(MachineLocation.id == item.id).first()
|
||||
return machine_location_info(item)
|
||||
|
||||
|
||||
@view_config(request_method='POST', route_name='machine_location_id', renderer='json', permission='Machines',
|
||||
trans=True)
|
||||
def update(request):
|
||||
id = uuid.UUID(request.matchdict['id'])
|
||||
json = request.json_body
|
||||
item = request.dbsession.query(MachineLocation).filter(MachineLocation.id == id).first()
|
||||
item.machine_name = json['Machine']
|
||||
item.location = request.dbsession.query(Location).filter(Location.name == json['Location']).first()
|
||||
transaction.commit()
|
||||
item = request.dbsession.query(MachineLocation).filter(MachineLocation.id == item.id).first()
|
||||
return machine_location_info(item)
|
||||
|
||||
|
||||
@view_config(request_method='DELETE', route_name='machine_location_id', renderer='json', permission='Machines',
|
||||
trans=True)
|
||||
def delete(request):
|
||||
id = uuid.UUID(request.matchdict['id'])
|
||||
item = request.dbsession.query(MachineLocation).filter(MachineLocation.id == id).first()
|
||||
request.dbsession.delete(item)
|
||||
transaction.commit()
|
||||
return {}
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='machine_location_id', renderer='json', permission='Authenticated')
|
||||
def show_id(request):
|
||||
id = uuid.UUID(request.matchdict['id'])
|
||||
item = request.dbsession.query(MachineLocation).filter(MachineLocation.id == id).first()
|
||||
return machine_location_info(item)
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='machine_location', renderer='json', request_param='n',
|
||||
permission='Everyone')
|
||||
def show_name(request):
|
||||
name = request.GET['n']
|
||||
item = request.dbsession.query(MachineLocation).filter(MachineLocation.machine_name == name).first()
|
||||
return machine_location_info(item)
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='machine_location_list', renderer='json', permission='Authenticated')
|
||||
def show_list(request):
|
||||
list = request.dbsession.query(MachineLocation).order_by(MachineLocation.machine_name).all()
|
||||
machine_locations = []
|
||||
for item in list:
|
||||
machine_locations.append({
|
||||
'MachineLocationID': item.id,
|
||||
'Machine': item.machine_name,
|
||||
'Location': item.location.name
|
||||
})
|
||||
return machine_locations
|
||||
|
||||
|
||||
def machine_location_info(item):
|
||||
if item is None:
|
||||
return {}
|
||||
return {
|
||||
'MachineLocationID': item.id,
|
||||
'Machine': item.machine_name,
|
||||
'Location': item.location.name
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
import uuid
|
||||
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Location, PrintLocation
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='print_location_id', renderer='json', permission='Authenticated')
|
||||
def show(request):
|
||||
id = request.matchdict['id']
|
||||
item = request.dbsession.query(PrintLocation).join(PrintLocation.location).filter(
|
||||
Location.name == id,
|
||||
PrintLocation.menu_category_id == None
|
||||
).first()
|
||||
return print_location_info(item)
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='print_location_id', renderer='json', request_param='pg',
|
||||
permission='Authenticated')
|
||||
def show_pg(request):
|
||||
id = request.matchdict['id']
|
||||
pg = uuid.UUID(request.GET['pg'])
|
||||
item = request.dbsession.query(PrintLocation).join(PrintLocation.location).filter(
|
||||
Location.name == id,
|
||||
PrintLocation.menu_category_id == pg
|
||||
).first()
|
||||
if item is None:
|
||||
item = request.dbsession.query(
|
||||
PrintLocation
|
||||
).join(PrintLocation.location).filter(
|
||||
Location.name == id,
|
||||
PrintLocation.menu_category_id == None
|
||||
).first()
|
||||
|
||||
return print_location_info(item)
|
||||
|
||||
|
||||
def print_location_info(item):
|
||||
return {
|
||||
'id': item.id,
|
||||
'menuCategory': None if item.menu_category is None else {'id': item.menu_category_id},
|
||||
'location': item.location.name,
|
||||
'printer': item.printer.name,
|
||||
'copies': item.copies,
|
||||
'cutCode': item.printer.cut_code
|
||||
}
|
||||
@ -50,7 +50,6 @@ def update(request):
|
||||
raise ValidationError("Address cannot be blank")
|
||||
item.cut_code = json.get("cutCode", "")
|
||||
transaction.commit()
|
||||
item = request.dbsession.query(Printer).filter(Printer.id == item.id).first()
|
||||
return printer_info(item.id, request.dbsession)
|
||||
|
||||
|
||||
|
||||
111
barker/views/section.py
Normal file
111
barker/views/section.py
Normal file
@ -0,0 +1,111 @@
|
||||
import uuid
|
||||
import transaction
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Section
|
||||
from barker.models.validation_exception import ValidationError
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="POST",
|
||||
route_name="v1_sections_new",
|
||||
renderer="json",
|
||||
permission="Sections",
|
||||
trans=True,
|
||||
)
|
||||
def save(request):
|
||||
json = request.json_body
|
||||
name = json.get("name", "").strip()
|
||||
if name == "":
|
||||
raise ValidationError("Name cannot be blank")
|
||||
item = Section(name)
|
||||
request.dbsession.add(item)
|
||||
transaction.commit()
|
||||
return section_info(item.id, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="PUT",
|
||||
route_name="v1_sections_id",
|
||||
renderer="json",
|
||||
permission="Sections",
|
||||
trans=True,
|
||||
)
|
||||
def update(request):
|
||||
json = request.json_body
|
||||
item = (
|
||||
request.dbsession.query(Section)
|
||||
.filter(Section.id == uuid.UUID(request.matchdict["id"]))
|
||||
.first()
|
||||
)
|
||||
item.name = json.get("name", "").strip()
|
||||
if item.name == "":
|
||||
raise ValidationError("Name cannot be blank")
|
||||
transaction.commit()
|
||||
return section_info(item.id, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="DELETE",
|
||||
route_name="v1_sections_id",
|
||||
renderer="json",
|
||||
permission="Sections",
|
||||
trans=True,
|
||||
)
|
||||
def delete(request):
|
||||
item = (
|
||||
request.dbsession.query(Section)
|
||||
.filter(Section.id == uuid.UUID(request.matchdict["id"]))
|
||||
.first()
|
||||
)
|
||||
if item.is_fixture:
|
||||
raise ValidationError(
|
||||
"{0} is a fixture and cannot be edited or deleted.".format(item.full_name)
|
||||
)
|
||||
request.dbsession.delete(item)
|
||||
transaction.commit()
|
||||
return section_info(None, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_sections_new",
|
||||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_blank(request):
|
||||
return section_info(None, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_sections_id",
|
||||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_id(request):
|
||||
return section_info(uuid.UUID(request.matchdict["id"]), request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_sections_list",
|
||||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_list(request):
|
||||
return [{
|
||||
"id": item.id,
|
||||
"name": item.name
|
||||
} for item in request.dbsession.query(Section).order_by(Section.name).all()]
|
||||
|
||||
|
||||
def section_info(item, dbsession):
|
||||
if item is None:
|
||||
return {"name": ""}
|
||||
if type(item) is uuid.UUID:
|
||||
item = dbsession.query(Section).filter(Section.id == item).first()
|
||||
return {
|
||||
"id": item.id,
|
||||
"name": item.name
|
||||
}
|
||||
155
barker/views/section_printer.py
Normal file
155
barker/views/section_printer.py
Normal file
@ -0,0 +1,155 @@
|
||||
import uuid
|
||||
|
||||
import transaction
|
||||
from pyramid.view import view_config
|
||||
from sqlalchemy import and_
|
||||
from sqlalchemy.dialects.postgresql import insert as pg_insert
|
||||
from zope.sqlalchemy import mark_changed
|
||||
|
||||
from barker.models import SectionPrinter, MenuCategory
|
||||
from barker.models.validation_exception import ValidationError
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="POST",
|
||||
route_name="v1_section_printers",
|
||||
renderer="json",
|
||||
permission="Products",
|
||||
trans=True,
|
||||
)
|
||||
def save(request):
|
||||
json = request.json_body
|
||||
section_id = uuid.UUID(request.matchdict["section_id"])
|
||||
current = []
|
||||
for mcs in json:
|
||||
menu_category = mcs.get("menuCategory", None)
|
||||
menu_category_id = (
|
||||
uuid.UUID(menu_category["id"]) if menu_category is not None else None
|
||||
)
|
||||
printer = mcs.get("printer", None)
|
||||
printer_id = uuid.UUID(printer["id"]) if printer is not None else None
|
||||
if menu_category_id is None and printer_id is None:
|
||||
raise ValidationError("Please choose a default printer")
|
||||
try:
|
||||
copies = int(mcs.get("copies", 0))
|
||||
if copies < 1:
|
||||
raise ValidationError("Copies must be an integer >= 1")
|
||||
except ValueError:
|
||||
raise ValidationError("Copies must be an integer >= 1")
|
||||
stmt = (
|
||||
pg_insert(SectionPrinter.__table__)
|
||||
.values(
|
||||
id=uuid.uuid4(),
|
||||
menu_category_id=menu_category_id,
|
||||
section_id=section_id,
|
||||
printer_id=printer_id,
|
||||
copies=copies,
|
||||
)
|
||||
.on_conflict_do_update(
|
||||
constraint=["menu_category_id", "section_id"],
|
||||
set_=dict(printerid=printer_id, copies=copies),
|
||||
)
|
||||
)
|
||||
request.dbsession.execute(stmt)
|
||||
current.append(menu_category_id)
|
||||
SectionPrinter.__table__.delete(
|
||||
and_(
|
||||
SectionPrinter.section_id == section_id,
|
||||
~SectionPrinter.menu_category_id.in_(current),
|
||||
)
|
||||
)
|
||||
mark_changed(request.dbsession)
|
||||
transaction.commit()
|
||||
|
||||
return report(section_id, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="DELETE",
|
||||
route_name="v1_section_printers",
|
||||
renderer="json",
|
||||
permission="Products",
|
||||
trans=True,
|
||||
)
|
||||
def delete(request):
|
||||
section_id = uuid.UUID(request.matchdict["section_id"])
|
||||
SectionPrinter.__table__.delete(SectionPrinter.section_id == section_id)
|
||||
mark_changed(request.dbsession)
|
||||
transaction.commit()
|
||||
return report(section_id, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_section_printers",
|
||||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_id(request):
|
||||
section_id = uuid.UUID(request.matchdict["section_id"])
|
||||
return report(section_id, request.dbsession)
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_section_printers",
|
||||
renderer="json",
|
||||
request_param="s",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_details(request):
|
||||
section_id = uuid.UUID(request.GET["s"])
|
||||
menu_category_id = request.GET.get("m", None)
|
||||
if menu_category_id is not None:
|
||||
menu_category_id = uuid.UUID(menu_category_id)
|
||||
item = (
|
||||
request.dbsession.query(SectionPrinter)
|
||||
.filter(
|
||||
SectionPrinter.section_id == section_id,
|
||||
SectionPrinter.menu_category_id == menu_category_id,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
return section_printer_info(item, request.dbsession)
|
||||
|
||||
|
||||
def report(section_id, dbsession):
|
||||
menu_categories = (
|
||||
dbsession.query(MenuCategory.id)
|
||||
.filter(MenuCategory.is_active == True)
|
||||
.order_by(MenuCategory.sort_order)
|
||||
.all()
|
||||
)
|
||||
list_ = []
|
||||
for item in [None] + menu_categories:
|
||||
mc = (
|
||||
dbsession.query(SectionPrinter)
|
||||
.filter(
|
||||
SectionPrinter.section_id == section_id,
|
||||
SectionPrinter.menu_category_id == id,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
list_.append(
|
||||
{
|
||||
"menuCategory": {"id": item},
|
||||
"printer": {} if mc is None else {"id": mc.printer_id},
|
||||
"copies": 0 if mc is None else mc.copies,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def section_printer_info(item, dbsession):
|
||||
if item is None:
|
||||
return {"menuCategory": {}, "section": {}, "printer": {}, "copies": 0}
|
||||
if type(item) is uuid.UUID:
|
||||
item = dbsession.query(SectionPrinter).filter(SectionPrinter.id == item).first()
|
||||
return {
|
||||
"id": item.id,
|
||||
"menuCategory": None
|
||||
if item.menu_category is None
|
||||
else {"id": item.menu_category.id, "name": item.menu_category.name},
|
||||
"section": {"id": item.section.id, "name": item.section.name},
|
||||
"printer": {"id": item.printer.id, "name": item.printer.name},
|
||||
"copies": item.copies,
|
||||
}
|
||||
Reference in New Issue
Block a user