signer: role choice + placeholder API
Browse files- form_logic.py +3 -0
- streamlit_app.py +25 -7
form_logic.py
CHANGED
|
@@ -33,6 +33,9 @@ FORM_TYPES = [
|
|
| 33 |
|
| 34 |
DOC_TYPE_OPTIONS = ["แจ้งให้เริ่มเข้าทำงาน", "แจ้งให้เริ่มส่งมอบสินค้า"]
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
# Placeholder ในแบบฟอร์มต้นฉบับ
|
| 37 |
PLACEHOLDER_DOC_NUM_F1 = "หมายเลขเอกสาร"
|
| 38 |
PLACEHOLDER_PO_F1 = "PO_No"
|
|
|
|
| 33 |
|
| 34 |
DOC_TYPE_OPTIONS = ["แจ้งให้เริ่มเข้าทำงาน", "แจ้งให้เริ่มส่งมอบสินค้า"]
|
| 35 |
|
| 36 |
+
# ผู้ลงนาม: เลือกบทบาทผู้ลงนาม แล้วระบบจะดึงชื่อจริงจาก API ตามบทบาทที่เลือก
|
| 37 |
+
SIGNER_ROLES = ["ผู้มีอำนาจอนุมัติจัดหาสินค้า", "ประธานคณะกรรมการตรวจรับ"]
|
| 38 |
+
|
| 39 |
# Placeholder ในแบบฟอร์มต้นฉบับ
|
| 40 |
PLACEHOLDER_DOC_NUM_F1 = "หมายเลขเอกสาร"
|
| 41 |
PLACEHOLDER_PO_F1 = "PO_No"
|
streamlit_app.py
CHANGED
|
@@ -23,6 +23,7 @@ from form_logic import (
|
|
| 23 |
generate_form,
|
| 24 |
FORM_TYPES,
|
| 25 |
DOC_TYPE_OPTIONS,
|
|
|
|
| 26 |
DISPLAY_FIELDS,
|
| 27 |
)
|
| 28 |
from auth_gate import require_login, render_topbar
|
|
@@ -102,6 +103,19 @@ def lookup_po_in_bytes(po_number, file_bytes, sheet_name=None, po_column="poNo")
|
|
| 102 |
wb.close()
|
| 103 |
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# =============================================================================
|
| 106 |
# Config: live data source — OneDrive "anyone with the link" (ตั้งใน Space secret DATA_URL)
|
| 107 |
# =============================================================================
|
|
@@ -1008,7 +1022,7 @@ has_file = bool(st.session_state.generated_file)
|
|
| 1008 |
|
| 1009 |
cur_po = st.session_state.get("po_input_widget", "") or ""
|
| 1010 |
cur_doc = st.session_state.get("doc_number_widget", "") or ""
|
| 1011 |
-
cur_signer = st.session_state.get("
|
| 1012 |
cur_form = st.session_state.get("form_select_widget", FORM_TYPES[0]["label"])
|
| 1013 |
|
| 1014 |
# Going back to edit Step 1 must regress the timeline: if the PO field no longer
|
|
@@ -1217,10 +1231,14 @@ with right_col:
|
|
| 1217 |
else:
|
| 1218 |
doc_type = ""
|
| 1219 |
|
| 1220 |
-
|
| 1221 |
-
|
| 1222 |
-
|
| 1223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1224 |
|
| 1225 |
st.markdown("<div style='height: 0.75rem;'></div>", unsafe_allow_html=True)
|
| 1226 |
|
|
@@ -1233,8 +1251,8 @@ with right_col:
|
|
| 1233 |
errors = []
|
| 1234 |
if not doc_number.strip():
|
| 1235 |
errors.append("กรุณากรอกหมายเลขเอกสาร")
|
| 1236 |
-
if not
|
| 1237 |
-
errors.append("กรุณา
|
| 1238 |
if selected_form["uses_po"] and not po_number.strip():
|
| 1239 |
errors.append("กรุณากรอกเลข PO")
|
| 1240 |
|
|
|
|
| 23 |
generate_form,
|
| 24 |
FORM_TYPES,
|
| 25 |
DOC_TYPE_OPTIONS,
|
| 26 |
+
SIGNER_ROLES,
|
| 27 |
DISPLAY_FIELDS,
|
| 28 |
)
|
| 29 |
from auth_gate import require_login, render_topbar
|
|
|
|
| 103 |
wb.close()
|
| 104 |
|
| 105 |
|
| 106 |
+
# =============================================================================
|
| 107 |
+
# ผู้ลงนาม: resolve a signer ROLE → the person's name.
|
| 108 |
+
# =============================================================================
|
| 109 |
+
def fetch_signer_name(role):
|
| 110 |
+
"""แปลงบทบาทผู้ลงนาม (role) เป็นชื่อจริงของผู้มีอำนาจลงนาม.
|
| 111 |
+
|
| 112 |
+
PLACEHOLDER — ยังไม่ได้ต่อ API จริง. ตอนนี้คืนค่าเป็นชื่อบทบาทที่เลือกไว้
|
| 113 |
+
เพื่อให้การสร้างเอกสารทำงานได้ตามปกติ. เมื่อมี endpoint จริงให้ยิง API ที่นี่
|
| 114 |
+
แล้วคืนชื่อจริงตาม role ที่เลือก.
|
| 115 |
+
"""
|
| 116 |
+
return role or ""
|
| 117 |
+
|
| 118 |
+
|
| 119 |
# =============================================================================
|
| 120 |
# Config: live data source — OneDrive "anyone with the link" (ตั้งใน Space secret DATA_URL)
|
| 121 |
# =============================================================================
|
|
|
|
| 1022 |
|
| 1023 |
cur_po = st.session_state.get("po_input_widget", "") or ""
|
| 1024 |
cur_doc = st.session_state.get("doc_number_widget", "") or ""
|
| 1025 |
+
cur_signer = fetch_signer_name(st.session_state.get("signer_role_widget"))
|
| 1026 |
cur_form = st.session_state.get("form_select_widget", FORM_TYPES[0]["label"])
|
| 1027 |
|
| 1028 |
# Going back to edit Step 1 must regress the timeline: if the PO field no longer
|
|
|
|
| 1231 |
else:
|
| 1232 |
doc_type = ""
|
| 1233 |
|
| 1234 |
+
signer_role = st.selectbox("ผู้ลงนาม *",
|
| 1235 |
+
SIGNER_ROLES,
|
| 1236 |
+
index=None,
|
| 1237 |
+
placeholder="เลือกผู้มีอำนาจลงนาม",
|
| 1238 |
+
key="signer_role_widget",
|
| 1239 |
+
disabled=not step1_done)
|
| 1240 |
+
# เลือกบทบาทแล้วยิง API ดึงชื่อจริง (ตอนนี้เป็น placeholder คืนชื่อบทบาท)
|
| 1241 |
+
signer = fetch_signer_name(signer_role) if signer_role else ""
|
| 1242 |
|
| 1243 |
st.markdown("<div style='height: 0.75rem;'></div>", unsafe_allow_html=True)
|
| 1244 |
|
|
|
|
| 1251 |
errors = []
|
| 1252 |
if not doc_number.strip():
|
| 1253 |
errors.append("กรุณากรอกหมายเลขเอกสาร")
|
| 1254 |
+
if not signer_role:
|
| 1255 |
+
errors.append("กรุณาเลือกผู้ลงนาม")
|
| 1256 |
if selected_form["uses_po"] and not po_number.strip():
|
| 1257 |
errors.append("กรุณากรอกเลข PO")
|
| 1258 |
|