nagasurendra commited on
Commit
89d0ec7
·
verified ·
1 Parent(s): eb9be14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -489,7 +489,7 @@ def menu():
489
  referral_code = user_result['records'][0].get('Referral__c', 'N/A')
490
  reward_points = user_result['records'][0].get('Reward_Points__c', 0)
491
 
492
- # Query to fetch menu items including Total_Ordered__c for best sellers
493
  menu_query = """
494
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c
495
  FROM Menu_Item__c
@@ -504,14 +504,26 @@ def menu():
504
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
505
  item['Total_Ordered__c'] = 0 # Default value
506
 
507
-
 
 
 
 
 
 
 
 
 
 
508
 
509
  # Define the order of sections, adding "Best Sellers" at the top
510
- section_order = ["Best Sellers", "Starters","Biryanis","Curries","Breads","Customized dish","Apetizer", "Desserts", "Soft Drinks"]
511
  ordered_menu = {section: [] for section in section_order}
 
512
  # Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
513
- best_sellers = sorted(food_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
514
  print(f"Best sellers: {[item['Name'] for item in best_sellers]}") # Debugging
 
515
  if selected_category == "Veg":
516
  best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
517
  elif selected_category == "Non veg":
@@ -524,8 +536,8 @@ def menu():
524
  if best_sellers:
525
  ordered_menu["Best Sellers"] = best_sellers
526
 
527
- # Filter and organize menu items based on category and section
528
- for item in food_items:
529
  section = item.get("Section__c", "Others") # Default to "Others" if missing
530
  if section not in ordered_menu:
531
  ordered_menu[section] = []
 
489
  referral_code = user_result['records'][0].get('Referral__c', 'N/A')
490
  reward_points = user_result['records'][0].get('Reward_Points__c', 0)
491
 
492
+ # Query to fetch Menu_Item__c records including Total_Ordered__c for best sellers
493
  menu_query = """
494
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c
495
  FROM Menu_Item__c
 
504
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
505
  item['Total_Ordered__c'] = 0 # Default value
506
 
507
+ # Query to fetch Custom_Dish__c records created within the last 7 days with Total_Ordered__c > 10
508
+ custom_dish_query = """
509
+ SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c
510
+ FROM Custom_Dish__c
511
+ WHERE CreatedDate >= LAST_N_DAYS:7
512
+ """
513
+ custom_dish_result = sf.query(custom_dish_query)
514
+ custom_dishes = custom_dish_result['records'] if 'records' in custom_dish_result else []
515
+
516
+ # Merge both Menu_Item__c and Custom_Dish__c records into the ordered menu
517
+ all_items = food_items + custom_dishes
518
 
519
  # Define the order of sections, adding "Best Sellers" at the top
520
+ section_order = ["Best Sellers", "Starters", "Biryanis", "Curries", "Breads", "Customized dish", "Apetizer", "Desserts", "Soft Drinks"]
521
  ordered_menu = {section: [] for section in section_order}
522
+
523
  # Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
524
+ best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
525
  print(f"Best sellers: {[item['Name'] for item in best_sellers]}") # Debugging
526
+
527
  if selected_category == "Veg":
528
  best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
529
  elif selected_category == "Non veg":
 
536
  if best_sellers:
537
  ordered_menu["Best Sellers"] = best_sellers
538
 
539
+ # Filter and organize menu items based on category and section (to avoid duplicates)
540
+ for item in all_items:
541
  section = item.get("Section__c", "Others") # Default to "Others" if missing
542
  if section not in ordered_menu:
543
  ordered_menu[section] = []