@@ -386,41 +386,44 @@ def purchase_stock_menu(stats):
386
386
'''
387
387
Purchase stock menu
388
388
'''
389
-
390
- # Main function constants.line stats here.
391
389
while True :
392
390
clear_terminal ()
393
-
391
+ # Header
394
392
print (f'{ cyan ("Purchase consumable stock" )} ' )
395
393
print (constants .LINE )
396
394
print (f'Current balance { green (print_current_balance (stats ))} ' )
397
395
print ('You have enough ingrediants to sell '
398
396
+ f'{ gold (get_portions_avaliable (stats ))} hotdogs.\n ' )
399
397
398
+ # Show current ingredients in stock
400
399
print (f'{ cyan ("Current stock:" )} ' )
401
400
print (constants .LINE )
402
401
print (f'{ stats ["bun" ]:<5} x { "Hotdog bun(s)" :<20} '
403
402
+ f'| { stats ["sausage" ]:<5} x Sausage(s)' )
404
403
print (f'{ stats ["onion" ]:<5} x { "Onion(s)" :<20} '
405
404
+ f'| { stats ["sauce" ]:<5} x Special sauce(s)' )
406
405
406
+ # Show price list for ingredients
407
407
print (constants .PURCHASE_STOCK_OPTIONS )
408
408
409
+ # Tip to show.
409
410
print (f"\n { pink ('TIP: ' )} This will purchase the amount of "
410
411
+ "ingredients you \n need for the amount of hotdogs "
411
412
+ "you want to stock. All sales are final" )
412
413
413
414
print_go_back ()
414
415
416
+ # Get user input
415
417
user_choice = input (orange ('\n How many hotdogs would you like to '
416
418
+ 'have in stock? ' ))
417
419
420
+ # Validation checks
418
421
if not validate_input (user_choice , 99999 ):
419
422
continue
420
-
421
423
if int (user_choice ) == 0 :
422
424
break
423
425
426
+ # Setting up variables
424
427
cost = 0
425
428
basket = { # Create empty basket
426
429
"stock" : [],
@@ -431,8 +434,9 @@ def purchase_stock_menu(stats):
431
434
"total_qty_c" : [] # Total cost for item
432
435
}
433
436
437
+ # Calculate how many ingredients need to be purchased and thee
438
+ # costs including total cost.
434
439
for count , key in enumerate (constants .STOCK_OPTIONS ):
435
- # stock = constants.STOCK_OPTIONS[count]
436
440
basket ["stock" ].append (stats [key ])
437
441
basket ["recipe" ].append (stats ['recipe' ][key ])
438
442
basket ["portions" ].append (constants .STOCK_COSTS [key ][1 ])
@@ -461,43 +465,50 @@ def purchase_stock_menu(stats):
461
465
462
466
cost += basket ["total_qty_c" ][count ]
463
467
468
+ # If cost is 0 then no ingredients required to be purchased
469
+ # Show error to user then go back to beginning of loop.
464
470
if cost == 0 :
465
471
print_error_message ("\n You already have this many hotdogs in "
466
472
+ "stock." )
467
473
continue
468
474
475
+ # Displaying checkout to the user
469
476
while True :
470
477
clear_terminal ()
478
+ # Header
471
479
print (f'\n { cyan ("Checkout:" )} ' )
472
480
print (constants .LINE )
473
481
print (f'{ "Item:" :<23} { "Qty:" :<10} { "Portions:" :<12} '
474
482
+ f'{ "Sub total:" :<10} ' )
475
483
print (constants .LINE )
476
484
485
+ # Basket
477
486
for count , key in enumerate (constants .STOCK_COSTS ):
478
487
text = (basket ["portions" ][count ]
479
488
* basket ["total_qty_r" ][count ])
480
-
481
- text = basket ["total_qty_c" ][count ]
489
+ text2 = basket ["total_qty_c" ][count ]
482
490
print (f'{ constants .STOCK_COSTS [key ][0 ]:<23} '
483
491
+ f'{ basket ["total_qty_r" ][count ]:<12} '
484
492
+ f'{ text :<10} '
485
- + f'£{ "{:.2f}" .format (text ):<10} ' )
493
+ + f'£{ "{:.2f}" .format (text2 ):<10} ' )
486
494
487
495
print (constants .LINE )
496
+
497
+ # Basket total
488
498
print ('TOTAL COST: ' + green (f"£{ '{:.2f}' .format (cost )} " ))
489
499
500
+ # User input required
490
501
user_choice = input (f'\n { orange ("Would you like to make this" )} '
491
502
+ f'{ orange (" purchase? (yes / no) " )} ' )
492
503
504
+ # Validate user input
493
505
if not validate_yes_no (user_choice ):
494
506
continue
495
-
496
507
if user_choice .lower () in ['y' , 'yes' ]:
508
+
497
509
# Check if remaining cash will above 0 after purchase,
498
510
# if so continue, else loop
499
511
remaining_cash = stats ["cash" ] - cost
500
-
501
512
if remaining_cash < 0 :
502
513
print_error_message ("Not enough funds" )
503
514
break
@@ -507,13 +518,15 @@ def purchase_stock_menu(stats):
507
518
stats [i ] += (basket ["portions" ][count ]
508
519
* basket ["total_qty_r" ][count ])
509
520
521
+ # Purchase successful, update user cash balance.
510
522
print (green ('Purchase Successful' ))
511
523
stats ["cash" ] = remaining_cash
512
524
print (cyan ('Remaining balance '
513
525
+ f'{ print_current_balance (stats )} ' ))
514
526
print_press_enter_to ("Press Enter to continue..." )
515
527
break
516
528
529
+ # Purchaser unsuccssgful
517
530
print (red ('Purchase Aborted' ))
518
531
print_press_enter_to ("Press Enter to continue..." )
519
532
break
0 commit comments