Renamed void_reason to reason so that we can store the employee name in case of Staff and NC reason in case of NC bills.
Settling NC and Staff bills now asks for Staff name / NC reason
This commit is contained in:
@ -114,7 +114,7 @@ class Voucher(Base):
|
||||
)
|
||||
customer_id = Column("customer_id", GUID(), ForeignKey("customers.id"))
|
||||
narration = Column("narration", Unicode(1000), nullable=False)
|
||||
void_reason = Column("void_reason", Unicode(255))
|
||||
reason = Column("reason", Unicode(255))
|
||||
_voucher_type = Column("voucher_type", Integer, nullable=False)
|
||||
user_id = Column("user_id", GUID(), ForeignKey("users.id"), nullable=False)
|
||||
|
||||
@ -170,7 +170,6 @@ class Voucher(Base):
|
||||
self.food_table_id = food_table_id
|
||||
self.customer_id = customer_id
|
||||
self.narration = ""
|
||||
self.void_reason = None
|
||||
self.voucher_type = voucher_type
|
||||
self.user_id = user_id
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ def check_permissions(item, voucher_type, permissions):
|
||||
|
||||
if item.voucher_type == VoucherType.VOID:
|
||||
raise ValidationFailure(
|
||||
"This Bill is already void.\nReason: {0}".format(item.void_reason)
|
||||
"This Bill is already void.\nReason: {0}".format(item.reason)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ from decimal import Decimal
|
||||
import transaction
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import SettleOption, Voucher, Settlement, Overview
|
||||
from barker.models import SettleOption, Voucher, Settlement, Overview, VoucherType
|
||||
from barker.models.validation_exception import ValidationError
|
||||
|
||||
|
||||
@ -19,20 +19,30 @@ from barker.models.validation_exception import ValidationError
|
||||
def receive_payment(request):
|
||||
update_table = request.GET["u"]
|
||||
json = request.json_body
|
||||
for item in json:
|
||||
amounts = [
|
||||
j
|
||||
for j in json["amounts"]
|
||||
if j["amount"] != 0
|
||||
and j["id"] not in [SettleOption.AMOUNT(), SettleOption.ROUND_OFF()]
|
||||
]
|
||||
for item in amounts:
|
||||
item["amount"] = round(Decimal(item["amount"]), 0)
|
||||
id_ = uuid.UUID(request.matchdict["id"])
|
||||
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
||||
|
||||
if item.voucher_type in [VoucherType.NO_CHARGE, VoucherType.STAFF]:
|
||||
item.reason = json["name"].strip().title()
|
||||
|
||||
total_amount = item.amount
|
||||
json.append({"id": SettleOption.AMOUNT(), "amount": -total_amount})
|
||||
amounts.append({"id": SettleOption.AMOUNT(), "amount": -total_amount})
|
||||
round_off = round(total_amount) - total_amount
|
||||
if round_off != 0:
|
||||
json.append({"id": SettleOption.ROUND_OFF(), "amount": -round_off})
|
||||
if sum([i["amount"] for i in json]) != 0:
|
||||
amounts.append({"id": SettleOption.ROUND_OFF(), "amount": -round_off})
|
||||
|
||||
if sum([i["amount"] for i in amounts]) != 0:
|
||||
raise ValidationError("Payment received is not equal to bill amount")
|
||||
|
||||
for i in (j for j in json if j["amount"] != 0):
|
||||
for i in amounts:
|
||||
amount = i["amount"]
|
||||
settlement_type_id = i["id"]
|
||||
old = [s for s in item.settlements if s.settled == settlement_type_id]
|
||||
@ -43,7 +53,7 @@ def receive_payment(request):
|
||||
item.settlements.append(s)
|
||||
request.dbsession.add(s)
|
||||
|
||||
allowed = [a["id"] for a in json if a["amount"] != 0]
|
||||
allowed = [a["id"] for a in amounts]
|
||||
for i in (s for s in item.settlements if s.settled not in allowed):
|
||||
item.settlements.remove(i)
|
||||
request.dbsession.delete(i)
|
||||
@ -54,5 +64,3 @@ def receive_payment(request):
|
||||
).delete()
|
||||
transaction.commit()
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ def voucher_info(item):
|
||||
"customer": {"id": item.customer_id, "name": item.customer.name} if item.customer is not None else {},
|
||||
"settlements": [],
|
||||
"narration": item.narration,
|
||||
"voidReason": item.void_reason,
|
||||
"reason": item.reason,
|
||||
"voucherType": item.voucher_type.name,
|
||||
"kotId": item.kot_id,
|
||||
"kots": [
|
||||
|
||||
@ -27,7 +27,7 @@ def split_voucher(request):
|
||||
update_table = request.GET["u"] == "true"
|
||||
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
||||
item.void = True
|
||||
item.void_reason = "Bill Split"
|
||||
item.reason = "Bill Split"
|
||||
do_void_settlements(item, request.dbsession)
|
||||
if update_table:
|
||||
request.dbsession.query(Overview).filter(
|
||||
|
||||
@ -22,7 +22,7 @@ def void_voucher(request):
|
||||
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
||||
|
||||
item.void = True
|
||||
item.void_reason = reason
|
||||
item.reason = reason
|
||||
item.voucher_type = VoucherType.VOID
|
||||
|
||||
do_void_settlements(item, request.dbsession)
|
||||
|
||||
Reference in New Issue
Block a user