1
0
forked from erp-dev/erp

feat: shipment patch

This commit is contained in:
2026-04-02 18:07:06 +08:00
parent d36d9c1d9c
commit 1be840a8c2
14 changed files with 979 additions and 72 deletions

View File

@@ -1,12 +1,13 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.db import transaction
from rest_framework import serializers, status
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from basic_info import models as basic_models
from basic_info.services import EmployeeUserProvisioningService
from django.contrib.auth import get_user_model
User = get_user_model()
@@ -72,50 +73,20 @@ class QuickCreateEmployeeUserView(APIView):
serializer.is_valid(raise_exception=True)
data = serializer.validated_data
merchant = basic_models.Merchant.objects.get(id=data['merchant_id'])
display_name = data['display_name']
status_value = data.get('status') or basic_models.EmployeeStatusEnum.ACTIVE
role_id = data.get('role_id')
with transaction.atomic():
user = User.objects.create_user(
username=data['username'],
password=data['password'],
email=data.get('email') or '',
)
user.first_name = display_name
user.save(update_fields=['first_name'])
# 如果指定了角色,将用户添加到对应的 Group
if role_id:
group = Group.objects.get(id=role_id)
user.groups.add(group)
employee = basic_models.Employee.objects.create(
merchant=merchant,
sys_user=user,
name=display_name,
mobile=data.get('mobile') or '',
area=data.get('area') or '',
description=data.get('description') or '',
status=status_value,
)
return Response(
{
'user': {
'id': user.id,
'username': user.username,
'display_name': display_name,
'role_id': role_id,
},
'employee': {
'id': employee.id,
'name': employee.name,
'status': employee.status,
'merchant': merchant.id,
},
},
status=status.HTTP_201_CREATED,
result = EmployeeUserProvisioningService.quick_create_employee_user(
username=data["username"],
password=data["password"],
display_name=data["display_name"],
merchant_id=data["merchant_id"],
email=data.get("email"),
mobile=data.get("mobile"),
area=data.get("area"),
description=data.get("description"),
status=data.get("status"),
role_id=data.get("role_id"),
)
return Response(
result.to_dict(),
status=status.HTTP_201_CREATED,
)