Przeglądaj źródła

fix: 创建制度时包含未激活员工(EMPLOYEE_CREATE)的额度记录

- _create_institution_quotas: 将员工查询从仅EMPLOYEE_ACTIVATED扩
  大为EMPLOYEE_CREATE+EMPLOYEE_ACTIVATED
- 未激活员工创建PENDING待发放记录,激活后由联动逻辑更新状态
alphah 2 tygodni temu
rodzic
commit
ac2a764002

+ 13 - 12
backend/app/plugin/module_payment/expense/institution/service.py

@@ -317,28 +317,29 @@ class InstitutionService:
         if adapter_type == "EMPLOYEE_SELECT":
             # 按员工选择 → 直接使用传入的员工ID
             employee_ids = [str(i) for i in add_ids if i]
-        elif adapter_type in ("EMPLOYEE_DEPARTMENT", "DEPARTMENT_SELECT"):
-            # 按部门 → 查该部门下的所有员工
+        elif adapter_type == "EMPLOYEE_ALL":
+            # 全部员工(包括未激活的,待后续激活时更新状态)
+            from app.plugin.module_payment.employee.model import EmployeeModel
+            emp_stmt = select(EmployeeModel).where(
+                EmployeeModel.enterprise_id == enterprise_id,
+                EmployeeModel.status.in_(["EMPLOYEE_CREATE", "EMPLOYEE_ACTIVATED"]),
+            )
+            emp_result = await auth.db.execute(emp_stmt)
+            employee_ids = [emp.employee_id for emp in emp_result.scalars().all() if emp.employee_id]
+
+        elif adapter_type == "EMPLOYEE_DEPARTMENT":
+            # 按部门 → 查该部门下的所有员工(包括未激活的)
             for dept_id in add_ids:
                 dept_id_str = str(dept_id)
                 from app.plugin.module_payment.employee.model import EmployeeModel
                 emp_stmt = select(EmployeeModel).where(
                     EmployeeModel.enterprise_id == enterprise_id,
-                    EmployeeModel.status == "EMPLOYEE_ACTIVATED",
+                    EmployeeModel.status.in_(["EMPLOYEE_CREATE", "EMPLOYEE_ACTIVATED"]),
                 )
                 emp_result = await auth.db.execute(emp_stmt)
                 for emp in emp_result.scalars().all():
                     if emp.department_ids and dept_id_str in emp.department_ids:
                         employee_ids.append(emp.employee_id)
-        elif adapter_type == "EMPLOYEE_ALL":
-            # 全部员工
-            from app.plugin.module_payment.employee.model import EmployeeModel
-            emp_stmt = select(EmployeeModel).where(
-                EmployeeModel.enterprise_id == enterprise_id,
-                EmployeeModel.status == "EMPLOYEE_ACTIVATED",
-            )
-            emp_result = await auth.db.execute(emp_stmt)
-            employee_ids = [emp.employee_id for emp in emp_result.scalars().all() if emp.employee_id]
 
         # 去重
         employee_ids = list(set(employee_ids))