LogicGoInfotechSpaces commited on
Commit
ef928f0
·
1 Parent(s): af904a9

Prioritize user-provided budget_amount over budget's maxAmount when category_id is a budget _id

Browse files
Files changed (1) hide show
  1. app/smart_recommendation.py +11 -12
app/smart_recommendation.py CHANGED
@@ -352,11 +352,6 @@ class SmartBudgetRecommender:
352
  budget_user_match = (str(budget_created_by) == str(user_id))
353
 
354
  if budget_user_match:
355
- # Extract budget amount and categories
356
- budget_max_amount = float(budget_by_id.get("maxAmount", 0) or 0)
357
- budget_spend_amount = float(budget_by_id.get("spendAmount", 0) or 0)
358
- budget_amount_from_budget = budget_spend_amount if budget_spend_amount > 0 else budget_max_amount
359
-
360
  # Extract categories from headCategories
361
  head_categories = budget_by_id.get("headCategories", [])
362
  category_ids_in_budget = []
@@ -372,18 +367,22 @@ class SmartBudgetRecommender:
372
  if nc_id:
373
  category_ids_in_budget.append(str(nc_id))
374
 
375
- # If budget has categories and amount, generate recommendation
376
- if category_ids_in_budget and budget_amount_from_budget > 0:
377
  # Use the first category ID found in the budget
378
  actual_category_id = category_ids_in_budget[0]
379
  category_name = self._get_category_name(actual_category_id)
380
 
381
- # Use budget amount if no budget_amount provided
382
- if budget_amount is None:
383
- budget_amount = budget_amount_from_budget
 
 
384
 
385
- # Generate recommendation using the budget's data
386
- avg_expense = budget_amount
 
 
387
  monthly_values = [avg_expense]
388
  std_dev = avg_expense * 0.05
389
  months_analyzed = 1
 
352
  budget_user_match = (str(budget_created_by) == str(user_id))
353
 
354
  if budget_user_match:
 
 
 
 
 
355
  # Extract categories from headCategories
356
  head_categories = budget_by_id.get("headCategories", [])
357
  category_ids_in_budget = []
 
367
  if nc_id:
368
  category_ids_in_budget.append(str(nc_id))
369
 
370
+ # If budget has categories, generate recommendation
371
+ if category_ids_in_budget:
372
  # Use the first category ID found in the budget
373
  actual_category_id = category_ids_in_budget[0]
374
  category_name = self._get_category_name(actual_category_id)
375
 
376
+ # PRIORITY: Use provided budget_amount if available, otherwise use budget's maxAmount
377
+ if budget_amount is None or budget_amount <= 0:
378
+ budget_max_amount = float(budget_by_id.get("maxAmount", 0) or 0)
379
+ budget_spend_amount = float(budget_by_id.get("spendAmount", 0) or 0)
380
+ budget_amount = budget_spend_amount if budget_spend_amount > 0 else budget_max_amount
381
 
382
+ # If we have a valid budget amount, generate recommendation
383
+ if budget_amount and budget_amount > 0:
384
+ # Generate recommendation using the provided budget_amount (user's input)
385
+ avg_expense = budget_amount
386
  monthly_values = [avg_expense]
387
  std_dev = avg_expense * 0.05
388
  months_analyzed = 1