rairo commited on
Commit
1f5b5a3
·
verified ·
1 Parent(s): 2cebcff

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +40 -28
main.py CHANGED
@@ -263,14 +263,17 @@ def get_user_dashboard():
263
  last_seen_currency_code = default_currency_code
264
 
265
  # Process Sales
266
- sales_query = bot_user_ref.collection('sales')
267
- if start_date:
268
- sales_query = sales_query.where('createdAt', '>=', start_date)
269
- if end_date:
270
- sales_query = sales_query.where('createdAt', '<=', end_date)
271
 
272
- for doc in sales_query.stream():
273
- details = doc.to_dict().get('details', {})
 
 
 
 
274
  currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
275
  last_seen_currency_code = currency_code
276
  quantity, price, cost = int(details.get('quantity', 1)), float(details.get('price', 0)), float(details.get('cost', 0))
@@ -279,13 +282,16 @@ def get_user_dashboard():
279
  sales_count += 1
280
 
281
  # Process Expenses
282
- expenses_query = bot_user_ref.collection('expenses')
283
- if start_date:
284
- expenses_query = expenses_query.where('createdAt', '>=', start_date)
285
- if end_date:
286
- expenses_query = expenses_query.where('createdAt', '<=', end_date)
 
 
 
 
287
 
288
- for doc in expenses_query.stream():
289
  details = doc.to_dict().get('details', {})
290
  currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
291
  last_seen_currency_code = currency_code
@@ -865,14 +871,17 @@ def get_admin_dashboard_stats():
865
  user_sales_data[phone] = {'total_revenue_by_currency': {}, 'item_sales': {}}
866
  last_seen_currency_code = normalize_currency_code(phone_to_user_map.get(phone, {}).get('defaultCurrency'), 'USD')
867
 
868
- sales_query = bot_user_ref.collection('sales')
869
- if start_date:
870
- sales_query = sales_query.where('createdAt', '>=', start_date)
871
- if end_date:
872
- sales_query = sales_query.where('createdAt', '<=', end_date)
 
 
 
 
873
 
874
- for sale_doc in sales_query.stream():
875
- details = sale_doc.to_dict().get('details', {})
876
  currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
877
  last_seen_currency_code = currency_code
878
  quantity, price, cost = int(details.get('quantity', 1)), float(details.get('price', 0)), float(details.get('cost', 0))
@@ -888,14 +897,17 @@ def get_admin_dashboard_stats():
888
  if item_name not in global_item_revenue: global_item_revenue[item_name] = {}
889
  global_item_revenue[item_name][currency_code] = global_item_revenue[item_name].get(currency_code, 0) + sale_revenue
890
 
891
- expenses_query = bot_user_ref.collection('expenses')
892
- if start_date:
893
- expenses_query = expenses_query.where('createdAt', '>=', start_date)
894
- if end_date:
895
- expenses_query = expenses_query.where('createdAt', '<=', end_date)
896
-
897
- for expense_doc in expenses_query.stream():
898
- details = expense_doc.to_dict().get('details', {})
 
 
 
899
  currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
900
  last_seen_currency_code = currency_code
901
  amount = float(details.get('amount', 0))
 
263
  last_seen_currency_code = default_currency_code
264
 
265
  # Process Sales
266
+ sales_query = bot_user_ref.collection('sales').stream()
267
+ for doc in sales_query:
268
+ doc_data = doc.to_dict()
269
+ created_at = doc_data.get('createdAt')
 
270
 
271
+ if start_date and (not created_at or created_at < start_date):
272
+ continue
273
+ if end_date and (not created_at or created_at > end_date):
274
+ continue
275
+
276
+ details = doc_data.get('details', {})
277
  currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
278
  last_seen_currency_code = currency_code
279
  quantity, price, cost = int(details.get('quantity', 1)), float(details.get('price', 0)), float(details.get('cost', 0))
 
282
  sales_count += 1
283
 
284
  # Process Expenses
285
+ expenses_query = bot_user_ref.collection('expenses').stream()
286
+ for doc in expenses_query:
287
+ doc_data = doc.to_dict()
288
+ created_at = doc_data.get('createdAt')
289
+
290
+ if start_date and (not created_at or created_at < start_date):
291
+ continue
292
+ if end_date and (not created_at or created_at > end_date):
293
+ continue
294
 
 
295
  details = doc.to_dict().get('details', {})
296
  currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
297
  last_seen_currency_code = currency_code
 
871
  user_sales_data[phone] = {'total_revenue_by_currency': {}, 'item_sales': {}}
872
  last_seen_currency_code = normalize_currency_code(phone_to_user_map.get(phone, {}).get('defaultCurrency'), 'USD')
873
 
874
+ sales_query = bot_user_ref.collection('sales').stream()
875
+ for sale_doc in sales_query:
876
+ sale_data = sale_doc.to_dict()
877
+ created_at = sale_data.get('createdAt')
878
+
879
+ if start_date and (not created_at or created_at < start_date):
880
+ continue
881
+ if end_date and (not created_at or created_at > end_date):
882
+ continue
883
 
884
+ details = sale_data.get('details', {})
 
885
  currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
886
  last_seen_currency_code = currency_code
887
  quantity, price, cost = int(details.get('quantity', 1)), float(details.get('price', 0)), float(details.get('cost', 0))
 
897
  if item_name not in global_item_revenue: global_item_revenue[item_name] = {}
898
  global_item_revenue[item_name][currency_code] = global_item_revenue[item_name].get(currency_code, 0) + sale_revenue
899
 
900
+ expenses_query = bot_user_ref.collection('expenses').stream()
901
+ for expense_doc in expenses_query:
902
+ expense_data = expense_doc.to_dict()
903
+ created_at = expense_data.get('createdAt')
904
+
905
+ if start_date and (not created_at or created_at < start_date):
906
+ continue
907
+ if end_date and (not created_at or created_at > end_date):
908
+ continue
909
+
910
+ details = expense_data.get('details', {})
911
  currency_code = normalize_currency_code(details.get('currency'), last_seen_currency_code)
912
  last_seen_currency_code = currency_code
913
  amount = float(details.get('amount', 0))