AnnasBlackHat commited on
Commit
2241ab1
·
1 Parent(s): 13663b1

add edit form

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -17,9 +17,10 @@ def make_api_request(product_name, outlet_name, start_date):
17
  # Make the API request with query parameters
18
  params = {"product": product_name, "outlet": outlet_name, "start_date": start_date_millis}
19
  print(f'--- make a request: {params}')
20
- response = requests.get(api_url, params=params)
21
 
22
  if response.status_code == 200:
 
23
  return response.json()
24
  else:
25
  st.error(f"Error: {response.status_code}")
@@ -31,12 +32,6 @@ def format_date(date_str):
31
  formatted_date = pd.to_datetime(date_str, unit='ms') + pd.to_timedelta("7 hours")
32
  return formatted_date.strftime("%d/%m/%Y %H:%M")
33
 
34
- # def display_edit(col):
35
- # col.write("Edit the data")
36
- # stock_key = col.text_input("Stock Key (e.g stock_opname #764)")
37
- # stock_in = col.number_input("Stock In", min_value=0)
38
- # col.button("Update")
39
-
40
  # Set the page to full width
41
  st.set_page_config(layout="wide")
42
 
@@ -61,7 +56,11 @@ with st.form("my_form"):
61
  # Make the API request
62
  api_data = make_api_request(product_name, outlet_name, start_date)
63
 
 
 
 
64
  if api_data and api_data["data"]:
 
65
  # Convert API response to DataFrame
66
  df = pd.json_normalize(api_data["data"])
67
  df["stock in"] = df["stock_in_source"] + " #" + df["stock_in_id"].astype(str)
 
17
  # Make the API request with query parameters
18
  params = {"product": product_name, "outlet": outlet_name, "start_date": start_date_millis}
19
  print(f'--- make a request: {params}')
20
+ response = requests.get(api_url, params=params)
21
 
22
  if response.status_code == 200:
23
+ # print('response ', response.json())
24
  return response.json()
25
  else:
26
  st.error(f"Error: {response.status_code}")
 
32
  formatted_date = pd.to_datetime(date_str, unit='ms') + pd.to_timedelta("7 hours")
33
  return formatted_date.strftime("%d/%m/%Y %H:%M")
34
 
 
 
 
 
 
 
35
  # Set the page to full width
36
  st.set_page_config(layout="wide")
37
 
 
56
  # Make the API request
57
  api_data = make_api_request(product_name, outlet_name, start_date)
58
 
59
+ if api_data and api_data['data'] is None:
60
+ st.error("No data found. Make sure to stock opname the product!")
61
+
62
  if api_data and api_data["data"]:
63
+ st.json(api_data)
64
  # Convert API response to DataFrame
65
  df = pd.json_normalize(api_data["data"])
66
  df["stock in"] = df["stock_in_source"] + " #" + df["stock_in_id"].astype(str)