Skip to content

Commit 2739220

Browse files
committed
Add food preparation table in kitchen count (#93)
1 parent e0c24b3 commit 2739220

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

souschef/delivery/views.py

+63-2
Original file line numberDiff line numberDiff line change
@@ -1112,12 +1112,14 @@ def get(self, request, *args, **kwargs):
11121112
kitchen_list[client_id] = kitchen_item
11131113

11141114
component_lines, meal_lines = kcr_make_lines(kitchen_list, delivery_date)
1115+
preparation_lines = kcr_get_preparation_lines(kitchen_list)
11151116
if component_lines:
11161117
# we have orders on that date
11171118
num_pages = kcr_make_pages( # kitchen count as PDF
11181119
delivery_date,
11191120
component_lines,
11201121
meal_lines, # summary
1122+
preparation_lines,
11211123
) # detail
11221124
num_labels = kcr_make_labels( # meal labels as PDF
11231125
delivery_date,
@@ -1190,7 +1192,7 @@ def meal_line(kititm):
11901192
A MealLine object
11911193
"""
11921194
return MealLine(
1193-
client=kititm.lastname + ", " + kititm.firstname[0:2] + ".",
1195+
client=format_client_name(kititm.firstname, kititm.lastname),
11941196
rqty=(str(kititm.meal_qty) if kititm.meal_size == SIZE_CHOICES_REGULAR else ""),
11951197
lqty=(str(kititm.meal_qty) if kititm.meal_size == SIZE_CHOICES_LARGE else ""),
11961198
ingr_clash="",
@@ -1371,7 +1373,30 @@ def kcr_make_lines(kitchen_list, kcr_date):
13711373
return (component_lines_sorted, meal_lines)
13721374

13731375

1374-
def kcr_make_pages(kcr_date, component_lines, meal_lines):
1376+
def format_client_name(firstname, lastname):
1377+
return f"{lastname}, {firstname[:2]}."
1378+
1379+
1380+
def kcr_get_preparation_lines(kitchen_list):
1381+
items_per_preparation = collections.defaultdict(list)
1382+
# Group KitchenItem per preparation method
1383+
for item in kitchen_list.values():
1384+
for prep in item.preparation:
1385+
items_per_preparation[prep].append(item)
1386+
# Return [(preparation_method, [formatted_client_name, ...]), ...]
1387+
return [
1388+
(
1389+
prep,
1390+
sorted(
1391+
format_client_name(item.firstname, item.lastname)
1392+
for item in items_per_preparation[prep]
1393+
),
1394+
)
1395+
for prep in sorted(items_per_preparation.keys())
1396+
]
1397+
1398+
1399+
def kcr_make_pages(kcr_date, component_lines, meal_lines, preperation_lines):
13751400
"""Generate the kitchen count report pages as a PDF file.
13761401
13771402
Uses ReportLab see http://www.reportlab.com/documentation/faq/
@@ -1442,6 +1467,39 @@ def myLaterPages(canvas, doc):
14421467
drawHeader(canvas, doc)
14431468
canvas.restoreState()
14441469

1470+
def get_food_preperation_table():
1471+
rows = []
1472+
line = 0
1473+
tab_style = RLTableStyle([("VALIGN", (0, 0), (-1, -1), "TOP")])
1474+
rows.append(
1475+
[
1476+
RLParagraph("Food Preparation", styles["NormalLeft"]),
1477+
RLParagraph("Quantity", styles["NormalRight"]),
1478+
"",
1479+
RLParagraph("Clients", styles["NormalLeft"]),
1480+
]
1481+
)
1482+
tab_style.add("LINEABOVE", (0, line), (-1, line), 1, rl_colors.black)
1483+
tab_style.add("LINEBELOW", (0, line), (-1, line), 1, rl_colors.black)
1484+
tab_style.add("LINEBEFORE", (0, line), (0, line), 1, rl_colors.black)
1485+
tab_style.add("LINEAFTER", (-1, line), (-1, line), 1, rl_colors.black)
1486+
line += 1
1487+
1488+
for prepline in preperation_lines:
1489+
rows.append(
1490+
[
1491+
RLParagraph(prepline[0], styles["LargeBoldLeft"]),
1492+
RLParagraph(str(len(prepline[1])), styles["NormalRightBold"]),
1493+
"",
1494+
RLParagraph(
1495+
";   ".join(prepline[1]), styles["NormalLeft"]
1496+
),
1497+
]
1498+
)
1499+
tab = RLTable(rows, colWidths=(150, 50, 10, 310), repeatRows=1)
1500+
tab.setStyle(tab_style)
1501+
return tab
1502+
14451503
def go():
14461504
"""Generate the pages.
14471505
@@ -1590,6 +1648,9 @@ def go():
15901648
story.append(RLSpacer(1, 1 * rl_inch))
15911649
# end Detail section
15921650

1651+
story.append(get_food_preperation_table())
1652+
story.append(RLSpacer(1, 1 * rl_inch))
1653+
15931654
# build full document
15941655
doc.build(story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)
15951656
return doc.page

0 commit comments

Comments
 (0)