Ankushbl6 commited on
Commit
3218acd
·
verified ·
1 Parent(s): 49486db

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +13 -1
src/streamlit_app.py CHANGED
@@ -1343,8 +1343,12 @@ elif len(st.session_state.batch_results) > 0:
1343
  except (AttributeError, ValueError):
1344
  due_date_str = ""
1345
 
 
 
 
 
1346
  # Calculate totals from line items (always, for both save and download)
1347
- line_items_list = edited_df.to_dict('records')
1348
  calculated_subtotal = sum(clean_float(item.get('Amount', 0)) for item in line_items_list)
1349
  calculated_total_tax = sum(clean_float(item.get('Tax', 0)) for item in line_items_list)
1350
  calculated_total = sum(clean_float(item.get('Line Total', 0)) for item in line_items_list)
@@ -1388,8 +1392,16 @@ elif len(st.session_state.batch_results) > 0:
1388
  # Save to batch_results (this persists the data)
1389
  st.session_state.batch_results[selected_hash]["edited_data"] = updated
1390
 
 
 
 
 
 
1391
  # Show success message
1392
  st.success("✅ Saved")
 
 
 
1393
 
1394
  # Per-file CSV download (ALWAYS visible, uses current edited values)
1395
  download_data = {
 
1343
  except (AttributeError, ValueError):
1344
  due_date_str = ""
1345
 
1346
+ # Get the current line items from session state (not the form-scoped edited_df)
1347
+ items_state_key = f"items_df_{selected_hash}"
1348
+ current_items_df = st.session_state.get(items_state_key, pd.DataFrame())
1349
+
1350
  # Calculate totals from line items (always, for both save and download)
1351
+ line_items_list = current_items_df.to_dict('records')
1352
  calculated_subtotal = sum(clean_float(item.get('Amount', 0)) for item in line_items_list)
1353
  calculated_total_tax = sum(clean_float(item.get('Tax', 0)) for item in line_items_list)
1354
  calculated_total = sum(clean_float(item.get('Line Total', 0)) for item in line_items_list)
 
1392
  # Save to batch_results (this persists the data)
1393
  st.session_state.batch_results[selected_hash]["edited_data"] = updated
1394
 
1395
+ # CRITICAL: Clear items_df from session state so it rebuilds from saved data on next rerun
1396
+ items_state_key = f"items_df_{selected_hash}"
1397
+ if items_state_key in st.session_state:
1398
+ del st.session_state[items_state_key]
1399
+
1400
  # Show success message
1401
  st.success("✅ Saved")
1402
+
1403
+ # Rerun to reload the form with saved data
1404
+ st.rerun()
1405
 
1406
  # Per-file CSV download (ALWAYS visible, uses current edited values)
1407
  download_data = {