Added the final missing Voids or Reprints report aslo.
Ready for beta 1. Removed voucher.is_void in favour voucher_type == void
This commit is contained in:
@ -114,7 +114,6 @@ class Voucher(Base):
|
||||
)
|
||||
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))
|
||||
_voucher_type = Column("voucher_type", Integer, nullable=False)
|
||||
user_id = Column("user_id", GUID(), ForeignKey("users.id"), nullable=False)
|
||||
@ -171,7 +170,6 @@ class Voucher(Base):
|
||||
self.food_table_id = food_table_id
|
||||
self.customer_id = customer_id
|
||||
self.narration = ""
|
||||
self.is_void = False
|
||||
self.void_reason = None
|
||||
self.voucher_type = voucher_type
|
||||
self.user_id = user_id
|
||||
|
||||
@ -366,6 +366,7 @@ def includeme(config):
|
||||
config.add_route("v1_bill_settlement_report", "/v1/bill-settlement-report")
|
||||
config.add_route("v1_beer_consumption_report", "/v1/beer-consumption-report")
|
||||
config.add_route("v1_discount_report", "/v1/discount-report")
|
||||
config.add_route("v1_voids_reprints_report", "/v1/voids-reprints-report")
|
||||
# Done till here
|
||||
|
||||
config.add_route("customer", "/Customer.json")
|
||||
@ -387,8 +388,6 @@ def includeme(config):
|
||||
config.add_route("v1_bills_new", "/v1/bills/new")
|
||||
config.add_route("v1_bills_id", "/v1/bills/{id}")
|
||||
|
||||
config.add_route("quantity_sold", "/QuantitySold.json")
|
||||
|
||||
config.add_route("reprint", "/Reprint.json")
|
||||
config.add_route("reprint_report", "/ReprintReport.json")
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ from datetime import datetime, timedelta
|
||||
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Settlement, SettleOption, Voucher
|
||||
from barker.models import Settlement, SettleOption, Voucher, VoucherType
|
||||
from barker.models.validation_exception import ValidationError
|
||||
from barker.views.reports import get_start_date, get_finish_date
|
||||
|
||||
@ -34,7 +34,7 @@ def bill_details(request):
|
||||
|
||||
report = []
|
||||
for item in vouchers:
|
||||
if item.is_void:
|
||||
if item.voucher_type == VoucherType.VOID:
|
||||
amount = (
|
||||
next(
|
||||
s.amount
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
import datetime
|
||||
|
||||
from pyramid.httpexceptions import HTTPForbidden
|
||||
from pyramid.view import view_config
|
||||
from sqlalchemy import func
|
||||
|
||||
from barker.models import Inventory, Kot, Product, MenuCategory, Settlement, SettleOption, Voucher
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='quantity_sold', renderer='json', permission='Sales Detail',
|
||||
request_param=('s', 'f'))
|
||||
def quantity_sold(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")
|
||||
|
||||
sold = q(start_date, finish_date, [
|
||||
SettleOption.CASH(),
|
||||
SettleOption.CREDIT_CARD(),
|
||||
SettleOption.BILL_TO_COMPANY(),
|
||||
SettleOption.STAFF()
|
||||
], request.dbsession)
|
||||
|
||||
nc = q(start_date, finish_date, [
|
||||
SettleOption.NO_CHARGE()
|
||||
], request.dbsession)
|
||||
|
||||
output = [{
|
||||
'ProductID': str(i[0]),
|
||||
'Name': i[1],
|
||||
'IsHappyHour': i[2],
|
||||
'Sale': i[3]
|
||||
} for i in sold]
|
||||
for id, name, hh, qty in nc:
|
||||
i = next((x for x in output if x['ProductID'] == str(id) and x['IsHappyHour'] == hh), None)
|
||||
if i is None:
|
||||
output.append({'ProductID': str(id), 'Name': name, 'IsHappyHour': hh, 'NC': qty})
|
||||
else:
|
||||
i['NC'] = qty
|
||||
return output
|
||||
|
||||
|
||||
def q(start_date, finish_date, options, dbsession):
|
||||
return dbsession.query(
|
||||
Product.id, Product.full_name, Inventory.is_happy_hour, func.sum(Inventory.quantity)
|
||||
).join(Voucher.kots).join(Kot.inventories).join(Inventory.product).join(Product.menu_category).filter(
|
||||
Voucher.date >= start_date,
|
||||
Voucher.date <= finish_date,
|
||||
Voucher.is_void == False,
|
||||
Voucher.settlements.any(Settlement.settled.in_(options))
|
||||
).group_by(
|
||||
Product.id, Product.full_name, Inventory.is_happy_hour, MenuCategory.name, MenuCategory.group_type
|
||||
).order_by(
|
||||
MenuCategory.group_type, MenuCategory.name, Product.full_name, Inventory.is_happy_hour
|
||||
).all()
|
||||
@ -1,62 +0,0 @@
|
||||
import datetime
|
||||
|
||||
from pyramid.httpexceptions import HTTPForbidden
|
||||
from pyramid.view import view_config
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
from barker.models import Reprint, Settlement, SettleOption, Voucher
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='reprint_report', renderer='json',
|
||||
permission='Void or Reprinted Bill Report', request_param=('s', 'f'))
|
||||
def reprint_report(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")
|
||||
|
||||
# TODO: Should be left outer join in case some bill is missing the settlements
|
||||
voids = []
|
||||
void_q = 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.is_void == True
|
||||
).order_by(
|
||||
Voucher.voucher_type
|
||||
).order_by(
|
||||
Voucher.bill_id
|
||||
).all()
|
||||
|
||||
for item in void_q:
|
||||
voids.append({
|
||||
'Date': item.date.strftime('%d-%b-%Y %H:%M:%S'),
|
||||
'BillID': item.full_bill_id,
|
||||
'Settlement': "Void: {0}".format(item.void_reason),
|
||||
'Amount': round(next(
|
||||
s.amount for s in item.settlements if s.settled == SettleOption.AMOUNT()
|
||||
) * -1, 2)
|
||||
})
|
||||
|
||||
reprints = []
|
||||
reprint_q = request.dbsession.query(Reprint).filter(
|
||||
Reprint.date >= start_date,
|
||||
Reprint.date <= finish_date
|
||||
).all()
|
||||
|
||||
for item in reprint_q:
|
||||
reprints.append({
|
||||
'Date': item.date.strftime('%d-%b-%Y %H:%M:%S'),
|
||||
'BillID': item.voucher.full_bill_id,
|
||||
'Settlement': "Reprinted by {0}".format(item.user.name),
|
||||
'Amount': round(next(
|
||||
s.amount for s in item.voucher.settlements if s.settled == SettleOption.AMOUNT()
|
||||
) * -1, 2)
|
||||
})
|
||||
|
||||
return voids + reprints
|
||||
65
barker/views/reports/voids_reprints_report.py
Normal file
65
barker/views/reports/voids_reprints_report.py
Normal file
@ -0,0 +1,65 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Settlement, SettleOption, Voucher, VoucherType, Reprint
|
||||
from barker.models.validation_exception import ValidationError
|
||||
from barker.views.reports import get_start_date, get_finish_date
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_voids_reprints_report",
|
||||
renderer="json",
|
||||
permission="Void or Reprinted Bill Report",
|
||||
)
|
||||
def voids_reprints_report_view(request):
|
||||
start_date = get_start_date(request.GET.get("s", None))
|
||||
finish_date = get_finish_date(request.GET.get("f", None))
|
||||
|
||||
if (
|
||||
datetime.today() - start_date.replace(hour=0)
|
||||
).days > 5 and "Accounts Audit" not in request.effective_principals:
|
||||
raise ValidationError("Accounts Audit")
|
||||
|
||||
return {
|
||||
"startDate": start_date.date().strftime("%d-%b-%Y"),
|
||||
"finishDate": (finish_date - timedelta(days=1)).date().strftime("%d-%b-%Y"),
|
||||
"amounts": voids_reprints_report(start_date, finish_date, request.dbsession),
|
||||
}
|
||||
|
||||
|
||||
def voids_reprints_report(start_date, finish_date, dbsession):
|
||||
vouchers = (
|
||||
dbsession.query(Voucher, Settlement.amount * -1)
|
||||
.join(Voucher.settlements)
|
||||
.filter(Voucher.date >= start_date, Voucher.date <= finish_date, Voucher.voucher_type == VoucherType.VOID.value, Settlement.settled == SettleOption.AMOUNT())
|
||||
.order_by(Voucher.date)
|
||||
.all()
|
||||
)
|
||||
print(str(vouchers))
|
||||
report = []
|
||||
for item, amount in vouchers:
|
||||
report.append(
|
||||
{
|
||||
"date": item.date.strftime("%d-%b-%Y %H:%M:%S"),
|
||||
"billId": item.full_bill_id,
|
||||
"settlement": f"Void: {item.void_reason}",
|
||||
"amount": round(amount, 2),
|
||||
}
|
||||
)
|
||||
reprints = dbsession.query(Reprint).filter(
|
||||
Reprint.date >= start_date,
|
||||
Reprint.date <= finish_date
|
||||
).all()
|
||||
|
||||
for item in reprints:
|
||||
report.append({
|
||||
'date': item.date.strftime('%d-%b-%Y %H:%M:%S'),
|
||||
'billId': item.voucher.full_bill_id,
|
||||
'settlement': f"Reprinted by {item.user.name}",
|
||||
'Amount': round(next(
|
||||
s.amount for s in item.voucher.settlements if s.settled == SettleOption.AMOUNT()
|
||||
) * -1, 2)
|
||||
})
|
||||
return report
|
||||
@ -58,7 +58,7 @@ def check_permissions(item, voucher_type, permissions):
|
||||
if item.voucher_type != VoucherType.KOT and voucher_type == VoucherType.KOT:
|
||||
raise ValidationFailure("This Bill is already printed\nCannot add a Kot to it.")
|
||||
|
||||
if item.is_void:
|
||||
if item.voucher_type == VoucherType.VOID:
|
||||
raise ValidationFailure(
|
||||
"This Bill is already void.\nReason: {0}".format(item.void_reason)
|
||||
)
|
||||
|
||||
@ -98,7 +98,6 @@ def voucher_info(item):
|
||||
"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,
|
||||
"voucherType": item.voucher_type.name,
|
||||
"kotId": item.kot_id,
|
||||
|
||||
Reference in New Issue
Block a user