Save Bill Works
This commit is contained in:
@ -4,27 +4,40 @@ import uuid
|
||||
from decimal import Decimal
|
||||
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy import Column, Integer, Boolean, Unicode, DateTime, Numeric, ForeignKey, UniqueConstraint, func, case
|
||||
from sqlalchemy.orm import relationship, synonym, backref
|
||||
from sqlalchemy import (
|
||||
Column,
|
||||
Integer,
|
||||
Boolean,
|
||||
Unicode,
|
||||
DateTime,
|
||||
Numeric,
|
||||
ForeignKey,
|
||||
UniqueConstraint,
|
||||
func,
|
||||
case,
|
||||
)
|
||||
from sqlalchemy.orm import relationship, backref
|
||||
from barker.models.guidtype import GUID
|
||||
from .meta import Base
|
||||
|
||||
|
||||
class VoucherType(IntEnum):
|
||||
KOT = 0
|
||||
REGULAR_BILL = 1
|
||||
NO_CHARGE = 2
|
||||
TAKE_AWAY = 3
|
||||
STAFF = 4
|
||||
|
||||
|
||||
class GuestBook(Base):
|
||||
__tablename__ = 'guest_book'
|
||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
customer_id = Column('customer_id', GUID(), ForeignKey('customers.id'), nullable=False)
|
||||
pax = Column('pax', Numeric, nullable=False)
|
||||
date = Column('creation_date', DateTime(timezone=True), nullable=False)
|
||||
__tablename__ = "guest_book"
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
customer_id = Column(
|
||||
"customer_id", GUID(), ForeignKey("customers.id"), nullable=False
|
||||
)
|
||||
pax = Column("pax", Numeric, nullable=False)
|
||||
date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
||||
|
||||
customer = relationship('Customer')
|
||||
customer = relationship("Customer")
|
||||
|
||||
def __init__(self, customer_id=None, pax=None, id_=None):
|
||||
self.customer_id = customer_id
|
||||
@ -34,16 +47,20 @@ class GuestBook(Base):
|
||||
|
||||
|
||||
class Overview(Base):
|
||||
__tablename__ = 'overview'
|
||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column('voucher_id', GUID(), ForeignKey('vouchers.id'), unique=True)
|
||||
food_table_id = Column('food_table_id', GUID(), ForeignKey('food_tables.id'), unique=True)
|
||||
guest_book_id = Column('guest_book_id', GUID(), ForeignKey('guest_book.id'), unique=True)
|
||||
status = Column('status', Unicode(255), nullable=False)
|
||||
__tablename__ = "overview"
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column("voucher_id", GUID(), ForeignKey("vouchers.id"), unique=True)
|
||||
food_table_id = Column(
|
||||
"food_table_id", GUID(), ForeignKey("food_tables.id"), unique=True
|
||||
)
|
||||
guest_book_id = Column(
|
||||
"guest_book_id", GUID(), ForeignKey("guest_book.id"), unique=True
|
||||
)
|
||||
status = Column("status", Unicode(255), nullable=False)
|
||||
|
||||
voucher = relationship('Voucher', backref=backref('status', uselist=False))
|
||||
food_table = relationship('FoodTable', backref=backref('status', uselist=False))
|
||||
guest = relationship('GuestBook', backref=backref('status', uselist=False))
|
||||
voucher = relationship("Voucher", backref=backref("status", uselist=False))
|
||||
food_table = relationship("FoodTable", backref=backref("status", uselist=False))
|
||||
guest = relationship("GuestBook", backref=backref("status", uselist=False))
|
||||
|
||||
def __init__(self, voucher_id, food_table_id, guest_book_id, status):
|
||||
self.voucher_id = voucher_id
|
||||
@ -53,16 +70,20 @@ class Overview(Base):
|
||||
|
||||
|
||||
class InventoryModifier(Base):
|
||||
__tablename__ = 'inventory_modifiers'
|
||||
__table_args__ = (UniqueConstraint('inventory_id', 'modifier_id'),)
|
||||
__tablename__ = "inventory_modifiers"
|
||||
__table_args__ = (UniqueConstraint("inventory_id", "modifier_id"),)
|
||||
|
||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
inventory_id = Column('inventory_id', GUID(), ForeignKey('inventories.id'), nullable=False)
|
||||
modifier_id = Column('modifier_id', GUID(), ForeignKey('modifiers.id'), nullable=False)
|
||||
price = Column('price', Numeric, nullable=False)
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
inventory_id = Column(
|
||||
"inventory_id", GUID(), ForeignKey("inventories.id"), nullable=False
|
||||
)
|
||||
modifier_id = Column(
|
||||
"modifier_id", GUID(), ForeignKey("modifiers.id"), nullable=False
|
||||
)
|
||||
price = Column("price", Numeric, nullable=False)
|
||||
|
||||
inventory = relationship('Inventory', backref='modifiers')
|
||||
modifier = relationship('Modifier')
|
||||
inventory = relationship("Inventory", backref="modifiers")
|
||||
modifier = relationship("Modifier")
|
||||
|
||||
def __init__(self, inventory_id, modifier_id, price):
|
||||
self.inventory_id = inventory_id
|
||||
@ -71,48 +92,74 @@ class InventoryModifier(Base):
|
||||
|
||||
|
||||
class Voucher(Base):
|
||||
__tablename__ = 'vouchers'
|
||||
__table_args__ = (UniqueConstraint('bill_id', 'voucher_type'),)
|
||||
__tablename__ = "vouchers"
|
||||
__table_args__ = (UniqueConstraint("bill_id", "voucher_type"),)
|
||||
|
||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
date = Column('date', DateTime, nullable=False, index=True)
|
||||
pax = Column('pax', Numeric, nullable=False)
|
||||
bill_id = Column('bill_id', Numeric)
|
||||
kot_id = Column('kot_id', Numeric, nullable=False, unique=True)
|
||||
creation_date = Column('creation_date', DateTime(timezone=True), nullable=False)
|
||||
last_edit_date = Column('last_edit_date', DateTime(timezone=True), nullable=False)
|
||||
food_table_id = Column('food_table_id', GUID(), ForeignKey('food_tables.id'), nullable=False)
|
||||
customer_id = Column('customer_id', GUID(), ForeignKey('customers.id'), nullable=False)
|
||||
narration = Column('narration', Unicode(1000), nullable=False)
|
||||
is_void = Column('is_void', Boolean, nullable=False)
|
||||
void_reason = Column('void_reason', Unicode(255))
|
||||
is_printed = Column('is_printed', Boolean, nullable=False)
|
||||
voucher_type = Column('voucher_type', Integer, nullable=False)
|
||||
user_id = Column('user_id', GUID(), ForeignKey('users.id'), nullable=False)
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
date = Column("date", DateTime, nullable=False, index=True)
|
||||
pax = Column("pax", Numeric, nullable=False)
|
||||
bill_id = Column("bill_id", Numeric)
|
||||
kot_id = Column("kot_id", Numeric, nullable=False, unique=True)
|
||||
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
||||
last_edit_date = Column("last_edit_date", DateTime(timezone=True), nullable=False)
|
||||
food_table_id = Column(
|
||||
"food_table_id", GUID(), ForeignKey("food_tables.id"), nullable=False
|
||||
)
|
||||
customer_id = Column("customer_id", GUID(), ForeignKey("customers.id"))
|
||||
narration = Column("narration", Unicode(1000), nullable=False)
|
||||
is_void = Column("is_void", Boolean, nullable=False)
|
||||
void_reason = Column("void_reason", Unicode(255))
|
||||
is_printed = Column("is_printed", Boolean, nullable=False)
|
||||
voucher_type = Column("voucher_type", Integer, nullable=False)
|
||||
user_id = Column("user_id", GUID(), ForeignKey("users.id"), nullable=False)
|
||||
|
||||
user = relationship('User', backref='vouchers')
|
||||
food_table = relationship('FoodTable', backref='vouchers')
|
||||
customer = relationship('Customer', backref='vouchers')
|
||||
user = relationship("User", backref="vouchers")
|
||||
food_table = relationship("FoodTable", backref="vouchers")
|
||||
customer = relationship("Customer", backref="vouchers")
|
||||
|
||||
kots = relationship('Kot', backref='voucher', cascade="delete, delete-orphan", cascade_backrefs=False)
|
||||
settlements = relationship('Settlement', backref='voucher', cascade="delete, delete-orphan", cascade_backrefs=False)
|
||||
reprints = relationship('Reprint', backref='voucher', cascade="delete, delete-orphan", cascade_backrefs=False)
|
||||
kots = relationship(
|
||||
"Kot",
|
||||
backref="voucher",
|
||||
cascade="delete, delete-orphan",
|
||||
cascade_backrefs=False,
|
||||
)
|
||||
settlements = relationship(
|
||||
"Settlement",
|
||||
backref="voucher",
|
||||
cascade="delete, delete-orphan",
|
||||
cascade_backrefs=False,
|
||||
)
|
||||
reprints = relationship(
|
||||
"Reprint",
|
||||
backref="voucher",
|
||||
cascade="delete, delete-orphan",
|
||||
cascade_backrefs=False,
|
||||
)
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
def __init__(self, pax, food_table_id, customer_id, is_printed, voucher_type, user_id, dbsession):
|
||||
def __init__(
|
||||
self,
|
||||
pax,
|
||||
food_table_id,
|
||||
customer_id,
|
||||
is_printed,
|
||||
voucher_type,
|
||||
user_id,
|
||||
dbsession,
|
||||
):
|
||||
now = datetime.now()
|
||||
self.date = now
|
||||
self.pax = pax
|
||||
if is_printed:
|
||||
type = [1, 3] if voucher_type in [1, 3] else [voucher_type]
|
||||
self.bill_id = dbsession.query(
|
||||
func.coalesce(func.max(Voucher.bill_id), 0) + 1
|
||||
).filter(
|
||||
Voucher.voucher_type.in_(type)
|
||||
).scalar()
|
||||
self.bill_id = (
|
||||
dbsession.query(func.coalesce(func.max(Voucher.bill_id), 0) + 1)
|
||||
.filter(Voucher.voucher_type.in_(type))
|
||||
.scalar()
|
||||
)
|
||||
self.kot_id = dbsession.query(
|
||||
func.coalesce(func.max(Voucher.kot_id), 0) + 1
|
||||
).scalar()
|
||||
@ -121,7 +168,7 @@ class Voucher(Base):
|
||||
self.last_edit_date = now
|
||||
self.food_table_id = food_table_id
|
||||
self.customer_id = customer_id
|
||||
self.narration = ''
|
||||
self.narration = ""
|
||||
self.is_void = False
|
||||
self.void_reason = None
|
||||
self.is_printed = is_printed
|
||||
@ -131,31 +178,46 @@ class Voucher(Base):
|
||||
@property
|
||||
def full_bill_id(self):
|
||||
if self.bill_id is None:
|
||||
return 'K-' + str(self.kot_id)
|
||||
return "K-" + str(self.kot_id)
|
||||
if self.voucher_type == VoucherType.NO_CHARGE.value:
|
||||
return "NC-" + str(self.bill_id)
|
||||
if self.voucher_type == VoucherType.STAFF.value:
|
||||
return "ST-" + str(self.bill_id)
|
||||
if self.voucher_type in [VoucherType.TAKE_AWAY.value, VoucherType.REGULAR_BILL.value]:
|
||||
if self.voucher_type in [
|
||||
VoucherType.TAKE_AWAY.value,
|
||||
VoucherType.REGULAR_BILL.value,
|
||||
]:
|
||||
return str(self.bill_id // 10000) + "-" + str(self.bill_id % 10000)
|
||||
else:
|
||||
raise Exception
|
||||
|
||||
|
||||
class Kot(Base):
|
||||
__tablename__ = 'kots'
|
||||
__tablename__ = "kots"
|
||||
|
||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column('voucher_id', GUID(), ForeignKey('vouchers.id'), nullable=False, index=True)
|
||||
code = Column('code', Numeric, nullable=False, unique=True)
|
||||
food_table_id = Column('food_table_id', GUID(), ForeignKey('food_tables.id'), nullable=False)
|
||||
date = Column('date', DateTime, nullable=False, index=True)
|
||||
user_id = Column('user_id', GUID(), ForeignKey('users.id'), nullable=False)
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column(
|
||||
"voucher_id", GUID(), ForeignKey("vouchers.id"), nullable=False, index=True
|
||||
)
|
||||
code = Column("code", Numeric, nullable=False, unique=True)
|
||||
food_table_id = Column(
|
||||
"food_table_id", GUID(), ForeignKey("food_tables.id"), nullable=False
|
||||
)
|
||||
date = Column("date", DateTime, nullable=False, index=True)
|
||||
user_id = Column("user_id", GUID(), ForeignKey("users.id"), nullable=False)
|
||||
|
||||
user = relationship('User', backref='kots')
|
||||
food_table = relationship('FoodTable', backref='kots')
|
||||
user = relationship("User", backref="kots")
|
||||
food_table = relationship("FoodTable", backref="kots")
|
||||
|
||||
def __init__(self, voucher_id=None, food_table_id=None, date=None, user_id=None, id=None, dbsession=None):
|
||||
def __init__(
|
||||
self,
|
||||
voucher_id=None,
|
||||
food_table_id=None,
|
||||
date=None,
|
||||
user_id=None,
|
||||
id=None,
|
||||
dbsession=None,
|
||||
):
|
||||
self.id = id
|
||||
self.voucher_id = voucher_id
|
||||
self.code = dbsession.query(func.coalesce(func.max(Kot.code), 0) + 1).scalar()
|
||||
@ -165,15 +227,17 @@ class Kot(Base):
|
||||
|
||||
|
||||
class Settlement(Base):
|
||||
__tablename__ = 'settlements'
|
||||
__table_args__ = (UniqueConstraint('voucher_id', 'settled'),)
|
||||
__tablename__ = "settlements"
|
||||
__table_args__ = (UniqueConstraint("voucher_id", "settled"),)
|
||||
|
||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column('voucher_id', GUID(), ForeignKey('vouchers.id'), nullable=False, index=True)
|
||||
settled = Column('settled', ForeignKey('settle_options.id'), nullable=False)
|
||||
amount = Column('amount', Numeric, nullable=False)
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
voucher_id = Column(
|
||||
"voucher_id", GUID(), ForeignKey("vouchers.id"), nullable=False, index=True
|
||||
)
|
||||
settled = Column("settled", ForeignKey("settle_options.id"), nullable=False)
|
||||
amount = Column("amount", Numeric, nullable=False)
|
||||
|
||||
settle_option = relationship('SettleOption')
|
||||
settle_option = relationship("SettleOption")
|
||||
|
||||
def __init__(self, voucher_id=None, settled=None, amount=None, id=None):
|
||||
self.id = id
|
||||
@ -183,14 +247,16 @@ class Settlement(Base):
|
||||
|
||||
|
||||
class Reprint(Base):
|
||||
__tablename__ = 'reprints'
|
||||
__tablename__ = "reprints"
|
||||
|
||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
date = Column('date', DateTime, nullable=False, index=True)
|
||||
voucher_id = Column('voucher_id', GUID(), ForeignKey('vouchers.id'), nullable=False, index=True)
|
||||
user_id = Column('user_id', GUID(), ForeignKey('users.id'), nullable=False)
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
date = Column("date", DateTime, nullable=False, index=True)
|
||||
voucher_id = Column(
|
||||
"voucher_id", GUID(), ForeignKey("vouchers.id"), nullable=False, index=True
|
||||
)
|
||||
user_id = Column("user_id", GUID(), ForeignKey("users.id"), nullable=False)
|
||||
|
||||
user = relationship('User', backref='reprints')
|
||||
user = relationship("User", backref="reprints")
|
||||
|
||||
def __init__(self, voucher_id=None, user_id=None, id=None):
|
||||
self.id = id
|
||||
@ -200,26 +266,38 @@ class Reprint(Base):
|
||||
|
||||
|
||||
class Inventory(Base):
|
||||
__tablename__ = 'inventories'
|
||||
__table_args__ = (UniqueConstraint('kot_id', 'product_id', 'is_happy_hour', 'price'),)
|
||||
__tablename__ = "inventories"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("kot_id", "product_id", "is_happy_hour", "price"),
|
||||
)
|
||||
|
||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
kot_id = Column('kot_id', GUID(), ForeignKey('kots.id'), nullable=False, index=True)
|
||||
product_id = Column('product_id', GUID(), ForeignKey('products.id'), nullable=False)
|
||||
quantity = Column('quantity', Numeric)
|
||||
price = Column('price', Numeric)
|
||||
is_happy_hour = Column('is_happy_hour', Boolean, nullable=False)
|
||||
tax_rate = Column('tax_rate', Numeric)
|
||||
tax_id = Column('tax_id', GUID(), ForeignKey('taxes.id'), nullable=False)
|
||||
discount = Column('discount', Numeric)
|
||||
sort_order = Column('sort_order', Numeric, nullable=False)
|
||||
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||
kot_id = Column("kot_id", GUID(), ForeignKey("kots.id"), nullable=False, index=True)
|
||||
product_id = Column("product_id", GUID(), ForeignKey("products.id"), nullable=False)
|
||||
quantity = Column("quantity", Numeric)
|
||||
price = Column("price", Numeric)
|
||||
is_happy_hour = Column("is_happy_hour", Boolean, nullable=False)
|
||||
tax_rate = Column("tax_rate", Numeric)
|
||||
tax_id = Column("tax_id", GUID(), ForeignKey("taxes.id"), nullable=False)
|
||||
discount = Column("discount", Numeric)
|
||||
sort_order = Column("sort_order", Numeric, nullable=False)
|
||||
|
||||
kot = relationship('Kot', backref='inventories')
|
||||
tax = relationship('Tax', foreign_keys=tax_id)
|
||||
product = relationship('Product', backref='inventories')
|
||||
kot = relationship("Kot", backref="inventories")
|
||||
tax = relationship("Tax", foreign_keys=tax_id)
|
||||
product = relationship("Product", backref="inventories")
|
||||
|
||||
def __init__(self, kot_id, product_id, quantity, price, discount, is_hh, tax_id, tax_rate,
|
||||
sort_order):
|
||||
def __init__(
|
||||
self,
|
||||
kot_id,
|
||||
product_id,
|
||||
quantity,
|
||||
price,
|
||||
discount,
|
||||
is_hh,
|
||||
tax_id,
|
||||
tax_rate,
|
||||
sort_order,
|
||||
):
|
||||
self.kot_id = kot_id
|
||||
self.product_id = product_id
|
||||
self.quantity = quantity
|
||||
@ -236,27 +314,20 @@ class Inventory(Base):
|
||||
|
||||
@effective_price.expression
|
||||
def effective_price(cls):
|
||||
return case(
|
||||
[(cls.is_happy_hour == True, 0)],
|
||||
else_=cls.price
|
||||
)
|
||||
return case([(cls.is_happy_hour == True, 0)], else_=cls.price)
|
||||
|
||||
@hybrid_property
|
||||
def net(self):
|
||||
return self.effective_price * self.quantity * (1 - self.discount)
|
||||
|
||||
@hybrid_property
|
||||
def st_amount(self):
|
||||
return self.net_taxable * self.service_tax_rate
|
||||
|
||||
@hybrid_property
|
||||
def vat_amount(self):
|
||||
return self.net_taxable * self.vat_rate
|
||||
def tax_amount(self):
|
||||
return self.net_taxable * self.tax_rate
|
||||
|
||||
@hybrid_property
|
||||
def amount(self):
|
||||
return Decimal(self.net * (1 + self.service_tax_rate + self.vat_rate))
|
||||
return Decimal(self.net * (1 + self.tax_rate))
|
||||
|
||||
@amount.expression
|
||||
def amount(cls):
|
||||
return cls.net * (1 + cls.service_tax_rate + cls.vat_rate)
|
||||
return cls.net * (1 + cls.tax_rate)
|
||||
|
||||
@ -390,8 +390,7 @@ def includeme(config):
|
||||
|
||||
config.add_route("sa_sale", "/SaleAnalysis/Sale.json")
|
||||
config.add_route("sa_settlements", "/SaleAnalysis/Settlements.json")
|
||||
config.add_route("sa_st", "/SaleAnalysis/ServiceTax.json")
|
||||
config.add_route("sa_vat", "/SaleAnalysis/Vat.json")
|
||||
config.add_route("sa_tax", "/SaleAnalysis/Tax.json")
|
||||
|
||||
config.add_route("voucher_reprint", "/ReprintVoucher/{id}.json")
|
||||
config.add_route("voucher_settle", "/Settle/{id}.json")
|
||||
|
||||
@ -122,41 +122,51 @@ def show_blank(request):
|
||||
request_method="GET",
|
||||
route_name="v1_tables_list",
|
||||
renderer="json",
|
||||
request_param="r",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_list(request):
|
||||
active = request.GET.get("a", None)
|
||||
list_ = request.dbsession.query(FoodTable)
|
||||
if active is not None:
|
||||
active = active == "true"
|
||||
list_ = list_.filter(FoodTable.is_active == active)
|
||||
list_ = list_.order_by(FoodTable.sort_order).all()
|
||||
def show_running(request):
|
||||
list_ = request.dbsession.query(FoodTable).filter(FoodTable.is_active == True).order_by(FoodTable.sort_order).all()
|
||||
|
||||
food_tables = []
|
||||
for item in list_:
|
||||
ft = {
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"seats": item.seats,
|
||||
"section": {"id": item.section_id, "name": item.section.name},
|
||||
"isActive": item.is_active,
|
||||
"sortOrder": item.sort_order
|
||||
}
|
||||
if item.status is None:
|
||||
ft["status"] = ""
|
||||
else:
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"seats": item.seats,
|
||||
"section": {"id": item.section_id, "name": item.section.name},
|
||||
"isActive": item.is_active,
|
||||
"sortOrder": item.sort_order
|
||||
}
|
||||
if item.status is not None:
|
||||
ft["status"] = item.status.status
|
||||
if item.status.voucher is not None:
|
||||
ft["voucherId"] = item.status.voucher_id
|
||||
ft["pax"] = item.status.voucher.pax
|
||||
ft["date"] = item.status.voucher.date.strftime("%d-%b-%Y %H:%M")
|
||||
ft["amount"] = 12345
|
||||
ft["voucherId"] = item.status.voucher_id
|
||||
ft["pax"] = item.status.voucher.pax
|
||||
ft["date"] = item.status.voucher.date.strftime("%d-%b-%Y %H:%M")
|
||||
ft["amount"] = 12345
|
||||
if item.status.guest is not None:
|
||||
ft["name"] = item.status.guest.customer.name
|
||||
ft["guest"] = item.status.guest.customer.name
|
||||
food_tables.append(ft)
|
||||
return food_tables
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_tables_list",
|
||||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_list(request):
|
||||
return [{
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"seats": item.seats,
|
||||
"section": {"id": item.section_id, "name": item.section.name},
|
||||
"isActive": item.is_active,
|
||||
"sortOrder": item.sort_order
|
||||
} for item in request.dbsession.query(FoodTable).order_by(FoodTable.sort_order).all()]
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="POST",
|
||||
route_name="v1_tables_list",
|
||||
|
||||
@ -194,12 +194,14 @@ def show_list_sale(request):
|
||||
products = []
|
||||
for item in list_:
|
||||
if item.has_happy_hour:
|
||||
p = product_info(item, request.dbsession)
|
||||
p["hasHappyHour"] = False
|
||||
products.append(p)
|
||||
i = product_info(item, request.dbsession)
|
||||
i["hasHappyHour"] = False
|
||||
i["name"] = "H + H " + i["name"]
|
||||
i["price"] = 0
|
||||
products.append(i)
|
||||
products.append(product_info(item, request.dbsession))
|
||||
else:
|
||||
products.append(product_info(item, request.dbsession))
|
||||
return products
|
||||
|
||||
|
||||
@ -246,7 +248,11 @@ def product_info(item, dbsession):
|
||||
"name": item.name,
|
||||
"units": item.units,
|
||||
"menuCategory": {"id": item.menu_category_id, "name": item.menu_category.name},
|
||||
"saleCategory": {"id": item.sale_category_id, "name": item.sale_category.name},
|
||||
"saleCategory": {
|
||||
"id": item.sale_category_id,
|
||||
"name": item.sale_category.name,
|
||||
"tax": {"id": item.sale_category.tax_id, "name": item.sale_category.name},
|
||||
},
|
||||
"price": item.price,
|
||||
"hasHappyHour": item.has_happy_hour,
|
||||
"isNotAvailable": item.is_not_available,
|
||||
|
||||
@ -72,40 +72,9 @@ def get_settlements(request):
|
||||
return info + [{'GroupType': 'Total', 'Amount': total}]
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='sa_st', renderer='json', permission=('Tax Analysis', 'Sales Analysis'),
|
||||
@view_config(request_method='GET', route_name='sa_tax', renderer='json', permission=('Tax Analysis', 'Sales Analysis'),
|
||||
request_param=('s', 'f'))
|
||||
def get_st(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')
|
||||
|
||||
if (datetime.date.today() - start_date.date()).days > 5 and 'Accounts Audit' not in request.effective_principals:
|
||||
raise HTTPForbidden("Accounts Audit")
|
||||
|
||||
amounts = request.dbsession.query(
|
||||
Inventory.service_tax_rate,
|
||||
func.coalesce(func.sum(Inventory.net_taxable), 0),
|
||||
func.coalesce(func.sum(Inventory.st_amount), 0)
|
||||
).join(Voucher.kots).join(Kot.inventories).filter(
|
||||
Voucher.date >= start_date,
|
||||
Voucher.date <= finish_date,
|
||||
Voucher.is_void == False,
|
||||
Voucher.settlements.any(~Settlement.settled.in_([1, 4, 7, 8, 9, 10]))
|
||||
).group_by(
|
||||
Inventory.service_tax_rate
|
||||
).order_by(
|
||||
Inventory.service_tax_rate
|
||||
).all()
|
||||
return [{
|
||||
'Name': "Service Tax - {0:.2%}".format(i[0]),
|
||||
'TaxRate': i[0],
|
||||
'NetSale': i[1],
|
||||
'TaxAmount': i[2]
|
||||
} for i in amounts]
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='sa_vat', renderer='json', permission=('Tax Analysis', 'Sales Analysis'),
|
||||
request_param=('s', 'f'))
|
||||
def get_vat(request):
|
||||
def get_tax(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')
|
||||
|
||||
@ -114,20 +83,20 @@ def get_vat(request):
|
||||
|
||||
amounts = request.dbsession.query(
|
||||
Tax.name,
|
||||
Inventory.vat_rate,
|
||||
Inventory.tax_rate,
|
||||
func.coalesce(func.sum(Inventory.net_taxable), 0),
|
||||
func.coalesce(func.sum(Inventory.vat_amount), 0)
|
||||
).join(Voucher.kots).join(Kot.inventories).join(Inventory.vat).filter(
|
||||
func.coalesce(func.sum(Inventory.tax_amount), 0)
|
||||
).join(Voucher.kots).join(Kot.inventories).join(Inventory.tax).filter(
|
||||
Voucher.date >= start_date,
|
||||
Voucher.date <= finish_date,
|
||||
Voucher.is_void == False,
|
||||
Voucher.settlements.any(~Settlement.settled.in_([1, 4, 7, 8, 9, 10]))
|
||||
).group_by(
|
||||
Tax.name,
|
||||
Inventory.vat_rate
|
||||
Inventory.tax_rate
|
||||
).order_by(
|
||||
Tax.name,
|
||||
Inventory.vat_rate
|
||||
Inventory.tax_rate
|
||||
).all()
|
||||
return [{
|
||||
'Name': "{0} - {1:.2%}".format(i[0], i[1]),
|
||||
|
||||
@ -22,13 +22,13 @@
|
||||
from barker.models import VoucherType, Settlement, SettleOption
|
||||
|
||||
|
||||
def get_st_vat(st, vat, voucher_type):
|
||||
def get_tax(tax, voucher_type):
|
||||
if voucher_type == VoucherType.STAFF.value:
|
||||
return 0, 0
|
||||
return 0
|
||||
elif voucher_type == VoucherType.NO_CHARGE.value:
|
||||
return 0, 0
|
||||
return 0
|
||||
else: # voucher_type in [REGULAR_BILL, TAKE_AWAY]:
|
||||
return st, vat
|
||||
return tax
|
||||
|
||||
|
||||
def get_settlements(voucher, dbsession):
|
||||
|
||||
@ -4,27 +4,46 @@ import transaction
|
||||
from pyramid.httpexceptions import HTTPForbidden
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Overview, Voucher, Kot, Inventory, InventoryModifier
|
||||
from barker.views.voucher import get_st_vat, get_settlements
|
||||
from barker.models import (
|
||||
Overview,
|
||||
Voucher,
|
||||
Kot,
|
||||
Inventory,
|
||||
InventoryModifier,
|
||||
VoucherType,
|
||||
Product,
|
||||
)
|
||||
from barker.views.voucher import get_tax, get_settlements
|
||||
from barker.views.voucher.show import voucher_info
|
||||
|
||||
|
||||
@view_config(request_method="PUT", route_name="v1_vouchers_new", renderer="json", trans=True)
|
||||
@view_config(
|
||||
request_method="POST", route_name="v1_vouchers_new", renderer="json", trans=True
|
||||
)
|
||||
def save(request):
|
||||
update_table = request.GET["u"]
|
||||
update_table = request.GET["u"] == "true"
|
||||
voucher_type = VoucherType[request.GET["p"]]
|
||||
guest_book_id = request.GET.get("g", None)
|
||||
if guest_book_id is not None:
|
||||
guest_book_id = uuid.UUID(guest_book_id)
|
||||
json = request.json_body
|
||||
|
||||
if not json["Printed"] and "Print Kot" not in request.effective_principals:
|
||||
if not json["isPrinted"] and "Print Kot" not in request.effective_principals:
|
||||
raise HTTPForbidden("You are not allowed to print a kot")
|
||||
|
||||
if json["Printed"] and "Print Bill" not in request.effective_principals:
|
||||
if json["isPrinted"] and "Print Bill" not in request.effective_principals:
|
||||
raise HTTPForbidden("You are not allowed to print bill")
|
||||
|
||||
item = save_voucher(json, request.dbsession)
|
||||
item = save_voucher(
|
||||
json, voucher_type, uuid.UUID(request.authenticated_userid), request.dbsession
|
||||
)
|
||||
if update_table:
|
||||
status = "printed" if item.is_printed else "running"
|
||||
item.status = Overview(
|
||||
voucher_id=None, food_table_id=item.food_table_id, status=status
|
||||
voucher_id=None,
|
||||
food_table_id=item.food_table_id,
|
||||
guest_book_id=guest_book_id,
|
||||
status=status,
|
||||
)
|
||||
request.dbsession.add(item.status)
|
||||
transaction.commit()
|
||||
@ -32,42 +51,42 @@ def save(request):
|
||||
return voucher_info(item)
|
||||
|
||||
|
||||
def save_voucher(json, dbsession):
|
||||
def save_voucher(json, voucher_type, user_id, dbsession):
|
||||
item = Voucher(
|
||||
json["Pax"],
|
||||
json["Table"]["FoodTableID"],
|
||||
json["Customer"]["CustomerID"],
|
||||
json["Printed"],
|
||||
json["VoucherType"],
|
||||
json["User"]["UserID"],
|
||||
json["pax"],
|
||||
json["table"]["id"],
|
||||
json["customer"]["id"] if "id" in json["customer"] else None,
|
||||
json["isPrinted"],
|
||||
voucher_type,
|
||||
user_id,
|
||||
dbsession,
|
||||
)
|
||||
dbsession.add(item)
|
||||
for k in json["Kots"]:
|
||||
for k in json["kots"]:
|
||||
kot = Kot(
|
||||
item.id, item.food_table_id, item.date, item.user_id, dbsession=dbsession
|
||||
)
|
||||
item.kots.append(kot)
|
||||
dbsession.add(kot)
|
||||
for index, i in enumerate(k["Inventories"]):
|
||||
st, vat = get_st_vat(i["ServiceTaxRate"], i["VatRate"], json["VoucherType"])
|
||||
for index, i in enumerate(k["inventories"]):
|
||||
product_id = uuid.UUID(i["product"]["id"])
|
||||
product = dbsession.query(Product).filter(Product.id == product_id).first()
|
||||
tax_rate = get_tax(product.sale_category.tax.rate, voucher_type)
|
||||
inv = Inventory(
|
||||
kot.id,
|
||||
uuid.UUID(i["ProductID"]),
|
||||
i["Quantity"],
|
||||
i["Price"],
|
||||
i["Discount"],
|
||||
i["IsHappyHour"],
|
||||
i["ServiceTaxID"],
|
||||
st,
|
||||
i["VatID"],
|
||||
vat,
|
||||
product_id,
|
||||
i["quantity"],
|
||||
product.price,
|
||||
i["discount"],
|
||||
i["isHappyHour"],
|
||||
product.sale_category.tax_id,
|
||||
tax_rate,
|
||||
index,
|
||||
)
|
||||
kot.inventories.append(inv)
|
||||
dbsession.add(inv)
|
||||
for m in i["Modifiers"]:
|
||||
mod = InventoryModifier(None, uuid.UUID(m["ModifierID"]), 0)
|
||||
for m in i["modifiers"]:
|
||||
mod = InventoryModifier(None, uuid.UUID(m["id"]), 0)
|
||||
inv.modifiers.append(mod)
|
||||
dbsession.add(mod)
|
||||
get_settlements(item, dbsession)
|
||||
|
||||
@ -77,6 +77,8 @@ def show_for_table(request):
|
||||
table = request.dbsession.query(FoodTable).filter(FoodTable.id == table_id).first()
|
||||
if guest_id is not None:
|
||||
guest = request.dbsession.query(GuestBook).filter(GuestBook.id == guest_id).first()
|
||||
else:
|
||||
guest = None
|
||||
return voucher_blank(table, guest)
|
||||
|
||||
|
||||
@ -90,12 +92,12 @@ def voucher_info(item):
|
||||
"lastEditDate": item.last_edit_date.strftime("%d-%b-%Y %H:%M:%S"),
|
||||
"billId": item.bill_id,
|
||||
"table": {"id": item.food_table_id, "name": item.food_table.name},
|
||||
"customer": {"id": item.customer_id, "name": item.customer.name},
|
||||
"customer": {"id": item.customer_id, "name": item.customer.name} if item.customer is not None else {},
|
||||
"settlements": [],
|
||||
"narration": item.narration,
|
||||
"void": item.is_void,
|
||||
"voidReason": item.void_reason,
|
||||
"printed": item.is_printed,
|
||||
"isPrinted": item.is_printed,
|
||||
"voucherType": item.voucher_type,
|
||||
"kotId": item.kot_id,
|
||||
"kots": [
|
||||
@ -153,7 +155,8 @@ def voucher_blank(table, guest):
|
||||
return {
|
||||
"pax": table.seats if guest is None else guest.pax,
|
||||
"table": {"id": table.id, "name": table.name},
|
||||
"customer": {"id": guest.customer_id, "name": guest.customer.name},
|
||||
"customer": {"id": guest.customer_id, "name": guest.customer.name} if guest is not None else {},
|
||||
"isPrinted": False,
|
||||
"kots": []
|
||||
}
|
||||
|
||||
|
||||
@ -9,16 +9,16 @@ from sqlalchemy import func
|
||||
|
||||
from barker.exceptions import ValidationFailure
|
||||
from barker.models import Voucher, Kot, Inventory, InventoryModifier, Overview
|
||||
from barker.views.voucher import get_st_vat, get_settlements
|
||||
from barker.views.voucher import get_tax, get_settlements
|
||||
from barker.views.voucher.show import voucher_info
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="POST", route_name="v1_vouchers_id", renderer="json", trans=True
|
||||
request_method="PUT", route_name="v1_vouchers_id", renderer="json", trans=True
|
||||
)
|
||||
def update(request):
|
||||
now = datetime.now()
|
||||
update_table = request.GET["u"]
|
||||
update_table = request.GET["u"] == "true"
|
||||
json = request.json_body
|
||||
id = uuid.UUID(request.matchdict["id"])
|
||||
item = request.dbsession.query(Voucher).filter(Voucher.id == id).first()
|
||||
@ -64,9 +64,7 @@ def update(request):
|
||||
item.last_edit_date = now
|
||||
for k in item.kots:
|
||||
for i in k.inventories:
|
||||
i.service_tax_rate, i.vat_rate = get_st_vat(
|
||||
i.service_tax_rate, i.vat_rate, item.voucher_type
|
||||
)
|
||||
i.tax_rate = get_tax(i.tax_rate, item.voucher_type)
|
||||
i.discount = next(
|
||||
Decimal(inv["Discount"])
|
||||
for ko in json["Kots"]
|
||||
@ -86,18 +84,16 @@ def update(request):
|
||||
item.kots.append(kot)
|
||||
request.dbsession.add(kot)
|
||||
for index, i in enumerate(k["Inventories"]):
|
||||
st, vat = get_st_vat(i["ServiceTaxRate"], i["VatRate"], json["VoucherType"])
|
||||
tax_rate = get_tax(i["taxRate"], json["VoucherType"])
|
||||
inv = Inventory(
|
||||
kot.id,
|
||||
uuid.UUID(i["ProductID"]),
|
||||
i["Quantity"],
|
||||
i["Price"],
|
||||
i["Discount"],
|
||||
i["IsHappyHour"],
|
||||
i["ServiceTaxID"],
|
||||
st,
|
||||
i["VatID"],
|
||||
vat,
|
||||
uuid.UUID(i["product"]["id"]),
|
||||
i["quantity"],
|
||||
i["price"],
|
||||
i["discount"],
|
||||
i["isHappyHour"],
|
||||
i["tax"]["id"],
|
||||
tax_rate,
|
||||
index,
|
||||
)
|
||||
kot.inventories.append(inv)
|
||||
|
||||
Reference in New Issue
Block a user