Skip to content

Commit

Permalink
Add food preparation table in kitchen count (santropolroulant#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumep committed Feb 25, 2024
1 parent f73572c commit 781d23f
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions souschef/delivery/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,14 @@ def get(self, request, *args, **kwargs):
kitchen_list[client_id] = kitchen_item

component_lines, meal_lines = kcr_make_lines(kitchen_list, delivery_date)
preparation_lines = kcr_get_preparation_lines(kitchen_list)
if component_lines:
# we have orders on that date
num_pages = kcr_make_pages( # kitchen count as PDF
delivery_date,
component_lines,
meal_lines, # summary
preparation_lines,
) # detail
num_labels = kcr_make_labels( # meal labels as PDF
delivery_date,
Expand Down Expand Up @@ -1190,7 +1192,7 @@ def meal_line(kititm):
A MealLine object
"""
return MealLine(
client=kititm.lastname + ", " + kititm.firstname[0:2] + ".",
client=format_client_name(kititm.firstname, kititm.lastname),
rqty=(str(kititm.meal_qty) if kititm.meal_size == SIZE_CHOICES_REGULAR else ""),
lqty=(str(kititm.meal_qty) if kititm.meal_size == SIZE_CHOICES_LARGE else ""),
ingr_clash="",
Expand Down Expand Up @@ -1371,7 +1373,30 @@ def kcr_make_lines(kitchen_list, kcr_date):
return (component_lines_sorted, meal_lines)


def kcr_make_pages(kcr_date, component_lines, meal_lines):
def format_client_name(firstname, lastname):
return f"{lastname}, {firstname[:2]}."


def kcr_get_preparation_lines(kitchen_list):
items_per_preparation = collections.defaultdict(list)
# Group KitchenItem per preparation method
for item in kitchen_list.values():
for prep in item.preparation:
items_per_preparation[prep].append(item)
# Return [(preparation_method, [formatted_client_name, ...]), ...]
return [
(
prep,
sorted(
format_client_name(item.firstname, item.lastname)
for item in items_per_preparation[prep]
),
)
for prep in sorted(items_per_preparation.keys())
]


def kcr_make_pages(kcr_date, component_lines, meal_lines, preperation_lines):
"""Generate the kitchen count report pages as a PDF file.
Uses ReportLab see http://www.reportlab.com/documentation/faq/
Expand Down Expand Up @@ -1442,6 +1467,39 @@ def myLaterPages(canvas, doc):
drawHeader(canvas, doc)
canvas.restoreState()

def get_food_preperation_table():
rows = []
line = 0
tab_style = RLTableStyle([("VALIGN", (0, 0), (-1, -1), "TOP")])
rows.append(
[
RLParagraph("Food Preparation", styles["NormalLeft"]),
RLParagraph("Quantity", styles["NormalRight"]),
"",
RLParagraph("Clients", styles["NormalLeft"]),
]
)
tab_style.add("LINEABOVE", (0, line), (-1, line), 1, rl_colors.black)
tab_style.add("LINEBELOW", (0, line), (-1, line), 1, rl_colors.black)
tab_style.add("LINEBEFORE", (0, line), (0, line), 1, rl_colors.black)
tab_style.add("LINEAFTER", (-1, line), (-1, line), 1, rl_colors.black)
line += 1

for prepline in preperation_lines:
rows.append(
[
RLParagraph(prepline[0], styles["LargeBoldLeft"]),
RLParagraph(str(len(prepline[1])), styles["NormalRightBold"]),
"",
RLParagraph(
";   ".join(prepline[1]), styles["NormalLeft"]
),
]
)
tab = RLTable(rows, colWidths=(150, 50, 10, 310), repeatRows=1)
tab.setStyle(tab_style)
return tab

def go():
"""Generate the pages.
Expand Down Expand Up @@ -1590,6 +1648,9 @@ def go():
story.append(RLSpacer(1, 1 * rl_inch))
# end Detail section

story.append(get_food_preperation_table())
story.append(RLSpacer(1, 1 * rl_inch))

# build full document
doc.build(story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)
return doc.page
Expand Down

0 comments on commit 781d23f

Please sign in to comment.