@@ -1112,12 +1112,14 @@ def get(self, request, *args, **kwargs):
1112
1112
kitchen_list [client_id ] = kitchen_item
1113
1113
1114
1114
component_lines , meal_lines = kcr_make_lines (kitchen_list , delivery_date )
1115
+ preparation_lines = kcr_get_preparation_lines (kitchen_list )
1115
1116
if component_lines :
1116
1117
# we have orders on that date
1117
1118
num_pages = kcr_make_pages ( # kitchen count as PDF
1118
1119
delivery_date ,
1119
1120
component_lines ,
1120
1121
meal_lines , # summary
1122
+ preparation_lines ,
1121
1123
) # detail
1122
1124
num_labels = kcr_make_labels ( # meal labels as PDF
1123
1125
delivery_date ,
@@ -1190,7 +1192,7 @@ def meal_line(kititm):
1190
1192
A MealLine object
1191
1193
"""
1192
1194
return MealLine (
1193
- client = kititm .lastname + ", " + kititm .firstname [ 0 : 2 ] + "." ,
1195
+ client = format_client_name ( kititm .firstname , kititm .lastname ) ,
1194
1196
rqty = (str (kititm .meal_qty ) if kititm .meal_size == SIZE_CHOICES_REGULAR else "" ),
1195
1197
lqty = (str (kititm .meal_qty ) if kititm .meal_size == SIZE_CHOICES_LARGE else "" ),
1196
1198
ingr_clash = "" ,
@@ -1371,7 +1373,30 @@ def kcr_make_lines(kitchen_list, kcr_date):
1371
1373
return (component_lines_sorted , meal_lines )
1372
1374
1373
1375
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 ):
1375
1400
"""Generate the kitchen count report pages as a PDF file.
1376
1401
1377
1402
Uses ReportLab see http://www.reportlab.com/documentation/faq/
@@ -1442,6 +1467,39 @@ def myLaterPages(canvas, doc):
1442
1467
drawHeader (canvas , doc )
1443
1468
canvas .restoreState ()
1444
1469
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
+
1445
1503
def go ():
1446
1504
"""Generate the pages.
1447
1505
@@ -1590,6 +1648,9 @@ def go():
1590
1648
story .append (RLSpacer (1 , 1 * rl_inch ))
1591
1649
# end Detail section
1592
1650
1651
+ story .append (get_food_preperation_table ())
1652
+ story .append (RLSpacer (1 , 1 * rl_inch ))
1653
+
1593
1654
# build full document
1594
1655
doc .build (story , onFirstPage = myFirstPage , onLaterPages = myLaterPages )
1595
1656
return doc .page
0 commit comments