diff --git a/User/views.py b/User/views.py index e20a5e9..bad37b8 100644 --- a/User/views.py +++ b/User/views.py @@ -1339,6 +1339,24 @@ class approvalProcessing(APIView): except User.DoesNotExist: return Response({'status': 'error', 'message': '用户记录不存在或已被删除', 'code': 1}, status=status.HTTP_404_NOT_FOUND) + # 接收离职工资参数(可选,审批人可以填写) + settlement_salary = request.data.get('settlement_salary') + + # 如果审批人填写了离职工资,更新审批记录的content字段 + if settlement_salary: + # 更新审批内容中的结算工资信息 + content = approval.content + # 替换或添加结算工资信息 + if "结算工资:" in content: + # 使用正则表达式替换结算工资部分 + import re + content = re.sub(r'结算工资:[^,]*', f'结算工资:{settlement_salary}元', content) + else: + # 如果content中没有结算工资信息,添加到末尾 + content = content + f",结算工资:{settlement_salary}元" + approval.content = content + approval.save(update_fields=['content']) + # 检查当前是否已经是财务审核 if approval.personincharge == "财务" and approval.state == "已抄送财务": # 财务部审核逻辑:财务部只需要一个人审核完即可完成 @@ -1354,7 +1372,7 @@ class approvalProcessing(APIView): approval.save(update_fields=['state']) return Response({'message': '处理成功', 'code': 0}, status=status.HTTP_200_OK) - # 使用统一的审核流程处理函数 + # 使用统一的审核流程处理函数(会同步离职工资信息到下一个审批人) from User.utils import process_approval_flow current_approver = approval.personincharge is_completed, error = process_approval_flow( diff --git a/finance/views.py b/finance/views.py index 65aeb33..448ede2 100644 --- a/finance/views.py +++ b/finance/views.py @@ -2093,6 +2093,8 @@ class UserDeparture(APIView): def post(self, request, *args, **kwargs): """ 离职财务登记 + 优化后:只需填写姓名和离职时间,其余字段从人事管理中同步 + 离职工资由审批人填写 如果用户有案件(作为承办人员),需要先转移案件才能完成离职登记 :param request: :param args: @@ -2107,8 +2109,9 @@ class UserDeparture(APIView): if personincharge and not approvers: approvers = [personincharge] if personincharge else None + # 只验证必填字段:姓名和离职时间 if not all([username, Dateofdeparture]): - return Response({'status': 'error', 'message': '缺少参数:用户名和离职时间不能为空', 'code': 1}, + return Response({'status': 'error', 'message': '缺少参数:姓名和离职时间不能为空', 'code': 1}, status=status.HTTP_400_BAD_REQUEST) try: @@ -2159,7 +2162,7 @@ class UserDeparture(APIView): # 根据团队类型判断是否需要审批 # 规则: # - 个人团队(personal/独立律师):不触发审批 - # - 团队(team/团队律师):需要审批,直接选择某个人,审批人需要指定结算工资 + # - 团队(team/团队律师):需要审批,审批人需要指定结算工资 from User.models import Team # 获取用户的团队信息 @@ -2178,16 +2181,33 @@ class UserDeparture(APIView): today = datetime.datetime.now() formatted_date = today.strftime("%Y-%m-%d") - settlement_salary = request.data.get('settlement_salary') # 结算工资(可选,审批人可以后续填写) - - content = f"{username}在{Dateofdeparture}办理离职" - if settlement_salary: - content += f",结算工资:{settlement_salary}" + # 从人事管理同步用户信息,构建审批内容 + # 包含用户的基本信息:姓名、岗位、部门、团队等 + content_parts = [f"{user.username}在{Dateofdeparture}办理离职登记"] + + # 同步岗位信息 + if user.position: + content_parts.append(f"岗位:{user.position}") + + # 同步部门信息 + departments = user.department.filter(is_deleted=False) + if departments.exists(): + dept_names = [dept.username for dept in departments] + content_parts.append(f"部门:{', '.join(dept_names)}") + + # 同步团队信息 + if user.team: + content_parts.append(f"团队:{user.team}") + + # 离职工资由审批人填写,初始状态为"待审批人指定" + content_parts.append("结算工资:待审批人指定") + + content = ",".join(content_parts) approval, approvers_order_json, needs_approval = create_approval_with_team_logic( team_name=team_name, approvers=approvers, - title=username + "离职财务登记", + title=user.username + "离职财务登记", content=content, approval_type="离职财务登记", user_id=str(user.id), @@ -2225,45 +2245,28 @@ class UserDeparture(APIView): remark=f'新增离职财务登记:{user.username},离职时间 {Dateofdeparture}(个人团队,无需审批)' ) else: - - # 构建审批内容,包含结算工资信息(如果已提供) - content_parts = [f"{username}在{Dateofdeparture}办理离职登记"] - if settlement_salary: - content_parts.append(f"结算工资:{settlement_salary}元") - else: - content_parts.append("结算工资:待审批人指定") - content = ",".join(content_parts) - - approval = Approval.objects.create( - title=username + "离职财务登记", - content=content, - times=formatted_date, - personincharge=personincharge, # 直接使用审批人用户名 - state='审核中', - type="离职财务登记", - user_id=str(user.id) - ) - - # 记录操作日志 - new_data = { - 'user_id': user.id, - 'username': user.username, - 'Dateofdeparture': Dateofdeparture, - 'state': user.state, - 'approver': personincharge, - 'settlement_salary': settlement_salary if settlement_salary else '待审批人指定' - } - log_operation( - request=request, - operation_type='CREATE', - module='Finance', - action='新增离职财务登记', - target_type='User', - target_id=user.id, - target_name=user.username, - new_data=new_data, - remark=f'新增离职财务登记:{user.username},离职时间 {Dateofdeparture}' - ) + # 如果创建了审批记录,记录操作日志 + if approval: + new_data = { + 'user_id': user.id, + 'username': user.username, + 'Dateofdeparture': Dateofdeparture, + 'state': user.state, + 'position': user.position, + 'team': user.team, + 'settlement_salary': '待审批人指定' + } + log_operation( + request=request, + operation_type='CREATE', + module='Finance', + action='新增离职财务登记', + target_type='User', + target_id=user.id, + target_name=user.username, + new_data=new_data, + remark=f'新增离职财务登记:{user.username},离职时间 {Dateofdeparture}' + ) return Response({ 'message': '离职登记成功', diff --git a/jyls_django/__init__.py b/jyls_django/__init__.py index c45523b..3678c63 100644 --- a/jyls_django/__init__.py +++ b/jyls_django/__init__.py @@ -1,2 +1,6 @@ import pymysql + +# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求 +# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本 +pymysql.version_info = (2, 2, 1, "final", 0) pymysql.install_as_MySQLdb() \ No newline at end of file diff --git a/jyls_django/asgi.py b/jyls_django/asgi.py index fc56d8f..04af2d6 100644 --- a/jyls_django/asgi.py +++ b/jyls_django/asgi.py @@ -9,6 +9,10 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ # 使用 PyMySQL 替代 mysqlclient(必须在导入 Django 之前) import pymysql + +# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求 +# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本 +pymysql.version_info = (2, 2, 1, "final", 0) pymysql.install_as_MySQLdb() import os diff --git a/jyls_django/settings.py b/jyls_django/settings.py index 78bd006..5a81e66 100644 --- a/jyls_django/settings.py +++ b/jyls_django/settings.py @@ -12,6 +12,10 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ # 使用 PyMySQL 替代 mysqlclient(必须在导入其他模块之前) import pymysql + +# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求 +# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本 +pymysql.version_info = (2, 2, 1, "final", 0) pymysql.install_as_MySQLdb() from pathlib import Path diff --git a/jyls_django/wsgi.py b/jyls_django/wsgi.py index 20dc8e0..d4f3030 100644 --- a/jyls_django/wsgi.py +++ b/jyls_django/wsgi.py @@ -9,6 +9,10 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ # 使用 PyMySQL 替代 mysqlclient(必须在导入 Django 之前) import pymysql + +# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求 +# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本 +pymysql.version_info = (2, 2, 1, "final", 0) pymysql.install_as_MySQLdb() import os diff --git a/manage.py b/manage.py index ac2e609..97fa721 100644 --- a/manage.py +++ b/manage.py @@ -2,6 +2,10 @@ """Django's command-line utility for administrative tasks.""" # 使用 PyMySQL 替代 mysqlclient(必须在导入 Django 之前) import pymysql + +# 覆盖 PyMySQL 的版本信息以满足 Django 4.2+ 的要求 +# Django 4.2+ 要求 mysqlclient 2.2.1 或更高版本 +pymysql.version_info = (2, 2, 1, "final", 0) pymysql.install_as_MySQLdb() import os