EricGEGE commited on
Commit
05dacae
·
verified ·
1 Parent(s): 4e33fee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -67,23 +67,24 @@ def approve_order(order_id, approver_role):
67
  orders = sheet.worksheet(PURCHASE_ORDERS_SHEET)
68
  order_records = orders.get_all_records()
69
  order_records = sorted(order_records, key=lambda x: x['timestamp'], reverse=True)
70
- order_index = next((index for (index, d) in enumerate(order_records) if d["运编号"] == order_id), None)
71
 
72
- if order_index is None:
73
  return '订单未找到'
74
 
75
- current_status = order_records[order_index]['审批状态']
 
76
 
77
- if (current_status == '待单证审批' and approver_role != '单证') or \
78
- (current_status == '待财务审批' and approver_role != '财务') or \
79
- (current_status == '待总经理审批' and approver_role != '总经理'):
80
- return f'只有{current_status}角色可以批准当前订单'
81
 
82
- next_status = get_next_approval_status(current_status)
83
- headers = list(order_records[0].keys())
84
- orders.update_cell(order_index + 2, headers.index('审批状态') + 1, next_status) # Update approval status
85
- orders.update_cell(order_index + 2, headers.index('timestamp') + 1,
86
- datetime.now().strftime('%m/%d/%Y %H:%M')) # Update timestamp
87
 
88
  return '订单已批准'
89
  except Exception as e:
 
67
  orders = sheet.worksheet(PURCHASE_ORDERS_SHEET)
68
  order_records = orders.get_all_records()
69
  order_records = sorted(order_records, key=lambda x: x['timestamp'], reverse=True)
70
+ order_indexes = [index for index, d in enumerate(order_records) if d["运编号"] == order_id]
71
 
72
+ if not order_indexes:
73
  return '订单未找到'
74
 
75
+ for order_index in order_indexes:
76
+ current_status = order_records[order_index]['审批状态']
77
 
78
+ if (current_status == '待单证审批' and approver_role != '单证') or \
79
+ (current_status == '待财务审批' and approver_role != '财务') or \
80
+ (current_status == '待总经理审批' and approver_role != '总经理'):
81
+ return f'只有{current_status}角色可以批准当前订单'
82
 
83
+ next_status = get_next_approval_status(current_status)
84
+ headers = list(order_records[0].keys())
85
+ orders.update_cell(order_index + 2, headers.index('审批状态') + 1, next_status) # 更新审批状态
86
+ orders.update_cell(order_index + 2, headers.index('timestamp') + 1,
87
+ datetime.now().strftime('%m/%d/%Y %H:%M')) # 更新时间戳
88
 
89
  return '订单已批准'
90
  except Exception as e: