Update menu.py
Browse files
menu.py
CHANGED
@@ -9,14 +9,6 @@ sf = get_salesforce_connection()
|
|
9 |
@menu_blueprint.route("/menu", methods=["GET", "POST"])
|
10 |
def menu():
|
11 |
selected_category = request.args.get("category", "All")
|
12 |
-
is_veg_only = request.args.get("veg") == 'on'
|
13 |
-
|
14 |
-
# Priority to Customized Dish only if it's selected
|
15 |
-
if request.args.get("category") == "Customized Dish":
|
16 |
-
selected_category = "Customized Dish"
|
17 |
-
else:
|
18 |
-
selected_category = "Veg" if is_veg_only else "All"
|
19 |
-
|
20 |
user_email = session.get('user_email')
|
21 |
|
22 |
if not user_email:
|
@@ -76,10 +68,18 @@ def menu():
|
|
76 |
if instruction:
|
77 |
instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
|
78 |
|
|
|
|
|
|
|
|
|
79 |
# Get the most frequent add-ons and instructions
|
80 |
most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3] # Top 3 most frequent addons
|
81 |
most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3] # Top 3 most frequent instructions
|
82 |
|
|
|
|
|
|
|
|
|
83 |
# Query to fetch Menu_Item__c records including Total_Ordered__c for best sellers
|
84 |
menu_query = """
|
85 |
SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c
|
@@ -93,8 +93,64 @@ def menu():
|
|
93 |
if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
|
94 |
item['Total_Ordered__c'] = 0 # Default value
|
95 |
|
96 |
-
#
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
except Exception as e:
|
100 |
print(f"Error fetching menu data: {str(e)}")
|
@@ -103,7 +159,7 @@ def menu():
|
|
103 |
referral_code = 'N/A'
|
104 |
reward_points = 0
|
105 |
|
106 |
-
# Pass the
|
107 |
return render_template(
|
108 |
"menu.html",
|
109 |
ordered_menu=ordered_menu,
|
@@ -117,6 +173,7 @@ def menu():
|
|
117 |
most_common_instructions=most_common_instructions # Pass most common instructions
|
118 |
)
|
119 |
|
|
|
120 |
@menu_blueprint.route('/api/addons', methods=['GET'])
|
121 |
def get_addons():
|
122 |
item_name = request.args.get('item_name')
|
|
|
9 |
@menu_blueprint.route("/menu", methods=["GET", "POST"])
|
10 |
def menu():
|
11 |
selected_category = request.args.get("category", "All")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
user_email = session.get('user_email')
|
13 |
|
14 |
if not user_email:
|
|
|
68 |
if instruction:
|
69 |
instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
|
70 |
|
71 |
+
# Debugging print statements for the most common add-ons and instructions
|
72 |
+
print(f"Most frequent add-ons: {addon_counts}")
|
73 |
+
print(f"Most frequent instructions: {instruction_counts}")
|
74 |
+
|
75 |
# Get the most frequent add-ons and instructions
|
76 |
most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3] # Top 3 most frequent addons
|
77 |
most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3] # Top 3 most frequent instructions
|
78 |
|
79 |
+
# Debugging print statements to observe the most frequent add-ons and instructions
|
80 |
+
print(f"Top 3 most common add-ons: {most_common_addons}")
|
81 |
+
print(f"Top 3 most common instructions: {most_common_instructions}")
|
82 |
+
|
83 |
# Query to fetch Menu_Item__c records including Total_Ordered__c for best sellers
|
84 |
menu_query = """
|
85 |
SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c
|
|
|
93 |
if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
|
94 |
item['Total_Ordered__c'] = 0 # Default value
|
95 |
|
96 |
+
# Query to fetch Custom_Dish__c records created within the last 7 days with Total_Ordered__c > 10
|
97 |
+
custom_dish_query = """
|
98 |
+
SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c
|
99 |
+
FROM Custom_Dish__c
|
100 |
+
WHERE CreatedDate >= LAST_N_DAYS:7
|
101 |
+
"""
|
102 |
+
custom_dish_result = sf.query(custom_dish_query)
|
103 |
+
custom_dishes = custom_dish_result['records'] if 'records' in custom_dish_result else []
|
104 |
+
|
105 |
+
# Merge both Menu_Item__c and Custom_Dish__c records into the ordered menu
|
106 |
+
all_items = food_items + custom_dishes
|
107 |
+
|
108 |
+
# Define the order of sections, adding "Best Sellers" at the top
|
109 |
+
section_order = ["Best Sellers", "Starters", "Biryanis", "Curries", "Breads", "Customized dish", "Apetizer", "Desserts", "Soft Drinks"]
|
110 |
+
ordered_menu = {section: [] for section in section_order}
|
111 |
+
|
112 |
+
# Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
|
113 |
+
best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
|
114 |
+
|
115 |
+
if selected_category == "Veg":
|
116 |
+
best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
|
117 |
+
elif selected_category == "Non veg":
|
118 |
+
best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Non veg", "both"]]
|
119 |
+
|
120 |
+
# Take only the top 4 best sellers after filtering
|
121 |
+
best_sellers = best_sellers[:4]
|
122 |
+
|
123 |
+
# Ensure "Best Sellers" is added only if there are items after filtering
|
124 |
+
if best_sellers:
|
125 |
+
ordered_menu["Best Sellers"] = best_sellers
|
126 |
+
|
127 |
+
# Create a set to track item names already added to prevent duplicates
|
128 |
+
added_item_names = set()
|
129 |
+
|
130 |
+
# Filter and organize menu items based on category and section (to avoid duplicates)
|
131 |
+
for item in all_items:
|
132 |
+
section = item.get("Section__c", "Others") # Default to "Others" if missing
|
133 |
+
if section not in ordered_menu:
|
134 |
+
ordered_menu[section] = []
|
135 |
+
|
136 |
+
# Skip item if it's already been added to avoid duplicates
|
137 |
+
if item['Name'] in added_item_names:
|
138 |
+
continue
|
139 |
+
|
140 |
+
# Apply category filters
|
141 |
+
if selected_category == "Veg" and item.get("Veg_NonVeg__c") not in ["Veg", "both"]:
|
142 |
+
continue
|
143 |
+
if selected_category == "Non veg" and item.get("Veg_NonVeg__c") not in ["Non veg", "both"]:
|
144 |
+
continue
|
145 |
+
|
146 |
+
ordered_menu[section].append(item)
|
147 |
+
added_item_names.add(item['Name']) # Add item to the set of added items
|
148 |
+
|
149 |
+
# Remove empty sections
|
150 |
+
ordered_menu = {section: items for section, items in ordered_menu.items() if items}
|
151 |
+
print(f"Final ordered menu: {ordered_menu.keys()}") # Debugging
|
152 |
+
|
153 |
+
categories = ["All", "Veg", "Non veg"]
|
154 |
|
155 |
except Exception as e:
|
156 |
print(f"Error fetching menu data: {str(e)}")
|
|
|
159 |
referral_code = 'N/A'
|
160 |
reward_points = 0
|
161 |
|
162 |
+
# Pass the user's first letter (first_letter) to the template
|
163 |
return render_template(
|
164 |
"menu.html",
|
165 |
ordered_menu=ordered_menu,
|
|
|
173 |
most_common_instructions=most_common_instructions # Pass most common instructions
|
174 |
)
|
175 |
|
176 |
+
|
177 |
@menu_blueprint.route('/api/addons', methods=['GET'])
|
178 |
def get_addons():
|
179 |
item_name = request.args.get('item_name')
|