rairo commited on
Commit
c19b014
·
verified ·
1 Parent(s): c2b14f8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +6 -5
main.py CHANGED
@@ -113,7 +113,7 @@ def process_receipt_endpoint():
113
 
114
  user_ref = db.reference(f'users/{uid}')
115
  user_data = user_ref.get()
116
- check_daily_reset(user_ref)
117
 
118
  # Handle manual entry
119
  if request.form.get('manual_entry') == 'true':
@@ -158,6 +158,7 @@ def process_receipt_endpoint():
158
  print(e)
159
  return jsonify({'error': str(e)}), 500
160
 
 
161
  def handle_manual_entry(uid, user_ref, user_data):
162
  try:
163
  data = {
@@ -195,9 +196,9 @@ def validate_and_save_transaction(uid, user_data, data, file_hash, image_bytes,
195
  return jsonify({'error': f"Transaction with Receipt #{receipt_number} and identical items already exists"}), 400
196
 
197
  total = float(data.get('total', 0))
198
- if total > user_data['remaining_cash']:
199
- return jsonify({'error': 'Insufficient funds'}), 400
200
-
201
  # Upload image if available
202
  image_url = None
203
  if image_bytes and not manual:
@@ -206,7 +207,7 @@ def validate_and_save_transaction(uid, user_data, data, file_hash, image_bytes,
206
  blob.upload_from_string(image_bytes, content_type='image/jpeg')
207
  image_url = blob.public_url
208
 
209
- # Update user cash
210
  new_remaining = user_data['remaining_cash'] - total
211
  db.reference(f'users/{uid}').update({'remaining_cash': new_remaining})
212
 
 
113
 
114
  user_ref = db.reference(f'users/{uid}')
115
  user_data = user_ref.get()
116
+ # Removed: check_daily_reset(user_ref)
117
 
118
  # Handle manual entry
119
  if request.form.get('manual_entry') == 'true':
 
158
  print(e)
159
  return jsonify({'error': str(e)}), 500
160
 
161
+
162
  def handle_manual_entry(uid, user_ref, user_data):
163
  try:
164
  data = {
 
196
  return jsonify({'error': f"Transaction with Receipt #{receipt_number} and identical items already exists"}), 400
197
 
198
  total = float(data.get('total', 0))
199
+
200
+ # Removed the check for insufficient funds to allow negative balances
201
+
202
  # Upload image if available
203
  image_url = None
204
  if image_bytes and not manual:
 
207
  blob.upload_from_string(image_bytes, content_type='image/jpeg')
208
  image_url = blob.public_url
209
 
210
+ # Update user cash - now allowing negative values
211
  new_remaining = user_data['remaining_cash'] - total
212
  db.reference(f'users/{uid}').update({'remaining_cash': new_remaining})
213