rename the product group table to either product category or menu category move the group_type field from productgroup to products and name it sales category eg. Food, beverage, etc. also, set the tax for sales category and not individual product Added the printers permission to end of permissions and only for owner, set them right
364 lines
11 KiB
Python
364 lines
11 KiB
Python
import uuid
|
|
|
|
from sqlalchemy import (
|
|
UniqueConstraint,
|
|
Column,
|
|
Unicode,
|
|
Numeric,
|
|
Boolean,
|
|
ForeignKey,
|
|
Integer,
|
|
case,
|
|
JSON,
|
|
)
|
|
from sqlalchemy.ext.hybrid import hybrid_property
|
|
from sqlalchemy.orm import relationship
|
|
from .meta import Base
|
|
from barker.models.guidtype import GUID
|
|
|
|
|
|
class Customer(Base):
|
|
__tablename__ = "customers"
|
|
|
|
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)
|
|
address = Column("address", Unicode(255), nullable=False)
|
|
|
|
@property
|
|
def __name__(self):
|
|
return self.name
|
|
|
|
def __init__(self, company=None, name=None, phone=None, address=None, id=None):
|
|
self.company = company
|
|
self.name = name
|
|
self.phone = phone
|
|
self.address = address
|
|
self.id = id
|
|
|
|
@classmethod
|
|
def cash(cls):
|
|
return uuid.UUID("2c716f4b-0736-429a-ad51-610d7c47cb5e")
|
|
|
|
|
|
class FoodTable(Base):
|
|
__tablename__ = "food_tables"
|
|
|
|
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)
|
|
|
|
is_active = Column("is_active", Boolean, nullable=False)
|
|
sort_order = Column("sort_order", Numeric, nullable=False)
|
|
|
|
@property
|
|
def __name__(self):
|
|
return self.name
|
|
|
|
def __init__(
|
|
self, name=None, seats=None, section=None, is_active=None, sort_order=0, id=None
|
|
):
|
|
self.name = name
|
|
self.seats = seats
|
|
self.section = section
|
|
self.is_active = is_active
|
|
self.sort_order = sort_order
|
|
self.id = id
|
|
|
|
|
|
class Tax(Base):
|
|
__tablename__ = "taxes"
|
|
|
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
|
name = Column("name", Unicode(255), nullable=False, unique=True)
|
|
rate = Column("rate", Numeric, nullable=False)
|
|
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
|
|
|
def __init__(self, name=None, rate=None, is_fixture=False, id=None):
|
|
self.name = name
|
|
self.rate = rate
|
|
self.is_fixture = is_fixture
|
|
self.id = id
|
|
|
|
|
|
class ProductGroup(Base):
|
|
__tablename__ = "product_groups"
|
|
# Peoduct/menu category
|
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
|
name = Column("name", Unicode(255), nullable=False, unique=True)
|
|
discount_limit = Column("discount_limit", Numeric, nullable=False)
|
|
is_modifier_compulsory = Column("is_modifier_compulsory", Boolean, nullable=False)
|
|
group_type = Column("group_type", Unicode(255), nullable=False)
|
|
|
|
is_active = Column("is_active", Boolean, nullable=False)
|
|
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
|
sort_order = Column("sort_order", Numeric, nullable=False)
|
|
|
|
def __init__(
|
|
self,
|
|
name,
|
|
discount_limit,
|
|
is_modifier_compulsory,
|
|
group_type,
|
|
is_active,
|
|
sort_order,
|
|
is_fixture=False,
|
|
id=None,
|
|
):
|
|
self.name = name
|
|
self.discount_limit = discount_limit
|
|
self.is_modifier_compulsory = is_modifier_compulsory
|
|
self.group_type = group_type
|
|
self.is_active = is_active
|
|
self.sort_order = sort_order
|
|
self.is_fixture = is_fixture
|
|
self.id = id
|
|
|
|
|
|
class Product(Base):
|
|
__tablename__ = "products"
|
|
__table_args__ = (UniqueConstraint("name", "units"),)
|
|
# add sales category instead of group_type in productgroups
|
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
|
name = Column("name", Unicode(255), nullable=False)
|
|
units = Column("units", Unicode(255), nullable=False)
|
|
product_group_id = Column(
|
|
"product_group_id", GUID(), ForeignKey("product_groups.id"), nullable=False
|
|
)
|
|
tax_id = Column("tax_id", GUID(), ForeignKey("taxes.id"), nullable=False)
|
|
price = Column("price", Numeric, nullable=False)
|
|
has_happy_hour = Column("has_happy_hour", Boolean, nullable=False)
|
|
is_not_available = Column("is_not_available", Boolean, nullable=False)
|
|
quantity = Column("quantity", Numeric, nullable=False)
|
|
|
|
is_active = Column("is_active", Boolean, nullable=False)
|
|
sort_order = Column("sort_order", Numeric, nullable=False)
|
|
|
|
product_group = relationship("ProductGroup", backref="products")
|
|
tax = relationship("Tax", foreign_keys=tax_id)
|
|
|
|
def __init__(
|
|
self,
|
|
name=None,
|
|
units=None,
|
|
product_group_id=None,
|
|
tax_id=None,
|
|
price=None,
|
|
has_happy_hour=None,
|
|
is_not_available=None,
|
|
quantity=None,
|
|
is_active=None,
|
|
sort_order=0,
|
|
id=None,
|
|
):
|
|
self.name = name
|
|
self.units = units
|
|
self.product_group_id = product_group_id
|
|
self.tax_id = tax_id
|
|
self.price = price
|
|
self.has_happy_hour = has_happy_hour
|
|
self.is_not_available = is_not_available
|
|
self.quantity = quantity
|
|
self.is_active = is_active
|
|
self.sort_order = sort_order
|
|
self.id = id
|
|
|
|
@hybrid_property
|
|
def full_name(self):
|
|
return "{0} ({1})".format(self.name, self.units)
|
|
|
|
@full_name.expression
|
|
def full_name(cls):
|
|
return cls.name + case([(cls.units != "", " (" + cls.units + ")")], else_="")
|
|
|
|
def can_delete(self, advanced_delete):
|
|
if self.is_fixture:
|
|
return (
|
|
False,
|
|
"{0} is a fixture and cannot be edited or deleted.".format(self.name),
|
|
)
|
|
if self.is_active:
|
|
return False, "Product is active"
|
|
if len(self.inventories) > 0 and not advanced_delete:
|
|
return False, "Product has entries"
|
|
return True, ""
|
|
|
|
|
|
class Modifier(Base):
|
|
__tablename__ = "modifiers"
|
|
|
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
|
name = Column("name", Unicode(255), nullable=False, unique=True)
|
|
show_in_bill = Column("show_in_bill", Boolean, nullable=False)
|
|
price = Column("price", Numeric, nullable=False)
|
|
|
|
def __init__(self, name=None, show_in_bill=None, price=None, id=None):
|
|
self.id = id
|
|
self.name = name
|
|
self.show_in_bill = show_in_bill
|
|
self.price = price
|
|
|
|
|
|
class ProductGroupModifier(Base):
|
|
__tablename__ = "product_group_modifiers"
|
|
|
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
|
product_group_id = Column(
|
|
"product_group_id", GUID(), ForeignKey("product_groups.id")
|
|
)
|
|
modifier_id = Column(
|
|
"modifier_id", GUID(), ForeignKey("modifiers.id"), nullable=False
|
|
)
|
|
show_automatically = Column("show_automatically", Boolean, nullable=False)
|
|
|
|
product_group = relationship("ProductGroup", backref="modifiers")
|
|
modifier = relationship("Modifier", backref="product_groups")
|
|
|
|
def __init__(
|
|
self, product_group_id=None, modifier_id=None, show_automatically=None, id=None
|
|
):
|
|
self.id = id
|
|
self.product_group_id = product_group_id
|
|
self.modifier_id = modifier_id
|
|
self.show_automatically = show_automatically
|
|
|
|
|
|
class DbSetting(Base):
|
|
__tablename__ = "settings"
|
|
|
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
|
data = Column("data", JSON)
|
|
|
|
def __init__(self, id=None, name=None, data=None):
|
|
self.id = id
|
|
self.name = name
|
|
self.data = data
|
|
|
|
|
|
class Location(Base):
|
|
__tablename__ = "locations"
|
|
|
|
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):
|
|
self.id = id
|
|
self.name = name
|
|
|
|
|
|
class MachineLocation(Base):
|
|
__tablename__ = "machine_locations"
|
|
|
|
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
|
|
)
|
|
|
|
location = relationship("Location", backref="machines")
|
|
|
|
def __init__(self, machine_name=None, location_id=None, id=None):
|
|
self.machine_name = machine_name
|
|
self.location_id = location_id
|
|
self.id = id
|
|
|
|
|
|
class Printer(Base):
|
|
__tablename__ = "printers"
|
|
|
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
|
address = Column("address", Unicode(255), unique=True, nullable=False)
|
|
cut_code = Column("cut_code", Unicode(255), nullable=False)
|
|
|
|
def __init__(self, name=None, address=None, cut_code=None, id=None):
|
|
self.id = id
|
|
self.name = name
|
|
self.address = address
|
|
self.cut_code = cut_code
|
|
|
|
|
|
class PrintLocation(Base):
|
|
__tablename__ = "print_locations"
|
|
__table_args__ = (UniqueConstraint("product_group_id", "location_id"),)
|
|
|
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
|
product_group_id = Column(
|
|
"product_group_id", GUID(), ForeignKey("product_groups.id")
|
|
)
|
|
location_id = Column(
|
|
"location_id", GUID(), ForeignKey("locations.id"), nullable=False
|
|
)
|
|
printer_id = Column("printer_id", GUID(), ForeignKey("printers.id"), nullable=False)
|
|
copies = Column("copies", Numeric, nullable=False)
|
|
|
|
product_group = relationship("ProductGroup", backref="print_locations")
|
|
location = relationship("Location", backref="print_locations")
|
|
printer = relationship("Printer", backref="print_locations")
|
|
|
|
def __init__(self, product_group_id, location_id, printer_id, copies):
|
|
self.product_group_id = product_group_id
|
|
self.location_id = location_id
|
|
self.printer_id = printer_id
|
|
self.copies = copies
|
|
|
|
|
|
class SettleOption(Base):
|
|
__tablename__ = "settle_options"
|
|
|
|
id = Column("id", Integer, primary_key=True)
|
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
|
show_in_choices = Column("show_in_choices", Boolean, nullable=False)
|
|
group = Column("display_group", Integer, nullable=False)
|
|
is_print = Column("is_print", Boolean, nullable=False)
|
|
|
|
def __init__(self, name, show_in_choices, group, is_print, id):
|
|
self.id = id
|
|
self.name = name
|
|
self.show_in_choices = show_in_choices
|
|
self.group = group
|
|
self.is_print = is_print
|
|
|
|
@classmethod
|
|
def UNSETTLED(cls):
|
|
return 1
|
|
|
|
@classmethod
|
|
def CASH(cls):
|
|
return 2
|
|
|
|
@classmethod
|
|
def CREDIT_CARD(cls):
|
|
return 3
|
|
|
|
@classmethod
|
|
def NO_CHARGE(cls):
|
|
return 4
|
|
|
|
@classmethod
|
|
def BILL_TO_COMPANY(cls):
|
|
return 5
|
|
|
|
@classmethod
|
|
def TIP(cls):
|
|
return 6
|
|
|
|
@classmethod
|
|
def ROUND_OFF(cls):
|
|
return 7
|
|
|
|
@classmethod
|
|
def AMOUNT(cls):
|
|
return 8
|
|
|
|
@classmethod
|
|
def VOID(cls):
|
|
return 9
|
|
|
|
@classmethod
|
|
def STAFF(cls):
|
|
return 10
|