Pārlūkot izejas kodu

fix(expense): 编辑回显 - 增加 adapter_type→applicable_scope 映射 + 类型安全

alphah 2 nedēļas atpakaļ
vecāks
revīzija
428d259149

+ 9 - 8
backend/app/plugin/module_payment/expense/institution/service.py

@@ -605,14 +605,15 @@ class InstitutionService:
             log.warning(f"合并本地DB字段失败: {e}")
 
         # 从支付宝 owner_id_list 映射为前端需要的 employee_ids
-        if not result_dict.get("employee_ids"):
-            owner_ids = result_dict.get("owner_id_list")
-            if owner_ids and result_dict.get("adapter_type") in ("EMPLOYEE_SELECT", None):
-                result_dict["employee_ids"] = list(owner_ids)
-        if not result_dict.get("scope_owner_id_list"):
-            owner_ids = result_dict.get("owner_id_list")
-            if owner_ids:
-                result_dict["scope_owner_id_list"] = list(owner_ids)
+        owner_ids = result_dict.get("owner_id_list")
+        adapter_type = result_dict.get("adapter_type")
+        if not result_dict.get("employee_ids") and owner_ids and isinstance(owner_ids, list):
+            result_dict["employee_ids"] = owner_ids
+        if not result_dict.get("scope_owner_id_list") and owner_ids and isinstance(owner_ids, list):
+            result_dict["scope_owner_id_list"] = owner_ids
+        if adapter_type and not result_dict.get("applicable_scope"):
+            scope_map = {"EMPLOYEE_SELECT": "employee", "EMPLOYEE_DEPARTMENT": "department", "EMPLOYEE_ALL": "all"}
+            result_dict["applicable_scope"] = scope_map.get(adapter_type, result_dict.get("applicable_scope", "none"))
 
         # 补充本地规则和额度
         from app.plugin.module_payment.expense.rule.model import ExpenseRuleModel