forked from erp-dev/erp
fix: added merchant_id to printing_order and plate_order
This commit is contained in:
@@ -141,11 +141,12 @@ class PrintingOrderListSerializer(serializers.ModelSerializer):
|
||||
jobs_last_status_summary = serializers.SerializerMethodField()
|
||||
created_by = serializers.IntegerField(source='created_by_id', read_only=True)
|
||||
created_by_name = serializers.SerializerMethodField()
|
||||
merchant_id = serializers.IntegerField(source='merchant.id', read_only=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = models.PrintingOrder
|
||||
fields = [
|
||||
'id', 'human_id', 'customer', 'customer_name', 'customer_phone',
|
||||
'id', 'human_id', 'merchant_id', 'customer', 'customer_name', 'customer_phone',
|
||||
'fabric', 'width', 'is_urgent', 'area', 'address', 'curve',
|
||||
'is_fabric_received', 'outgoing_date', 'is_invalid', 'new_curve',
|
||||
'process', 'process_name', 'progress', 'position', 'print_count',
|
||||
@@ -153,7 +154,7 @@ class PrintingOrderListSerializer(serializers.ModelSerializer):
|
||||
'created_by', 'created_by_name',
|
||||
'created_at', 'updated_at',
|
||||
]
|
||||
read_only_fields = ['id', 'human_id', 'created_at', 'updated_at', 'progress', 'print_count']
|
||||
read_only_fields = ['id', 'human_id', 'created_at', 'updated_at', 'progress', 'print_count', 'merchant_id']
|
||||
|
||||
def get_jobs_status_summary(self, obj):
|
||||
"""
|
||||
@@ -228,11 +229,12 @@ class PrintingOrderDetailSerializer(serializers.ModelSerializer):
|
||||
process_name = serializers.CharField(source='process.name', read_only=True)
|
||||
created_by_name = serializers.SerializerMethodField()
|
||||
progress = serializers.IntegerField(read_only=True)
|
||||
merchant_id = serializers.IntegerField(source='merchant.id', read_only=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = models.PrintingOrder
|
||||
fields = [
|
||||
'id', 'human_id', 'customer', 'customer_name', 'customer_phone', 'customer_area',
|
||||
'id', 'human_id', 'merchant_id', 'customer', 'customer_name', 'customer_phone', 'customer_area',
|
||||
'fabric', 'width', 'is_urgent', 'area', 'address', 'fabric_source',
|
||||
'is_fabric_received', 'craft', 'description', 'outgoing_date',
|
||||
'curve', 'new_curve', 'position', 'created_by_name',
|
||||
@@ -240,7 +242,7 @@ class PrintingOrderDetailSerializer(serializers.ModelSerializer):
|
||||
'is_invalid', 'process', 'process_name', 'progress', 'print_count',
|
||||
'created_at', 'updated_at'
|
||||
]
|
||||
read_only_fields = ['id', 'human_id', 'created_at', 'updated_at', 'progress', 'print_count']
|
||||
read_only_fields = ['id', 'human_id', 'created_at', 'updated_at', 'progress', 'print_count', 'merchant_id']
|
||||
|
||||
def get_created_by_name(self, obj):
|
||||
"""获取创建人名称(员工姓名)"""
|
||||
@@ -316,11 +318,12 @@ class PrintingJobListSerializer(serializers.ModelSerializer):
|
||||
last_completed_state = serializers.CharField(read_only=True)
|
||||
business_object_id = serializers.SerializerMethodField()
|
||||
batch_advance_records = serializers.SerializerMethodField()
|
||||
merchant_id = serializers.IntegerField(source='merchant.id', read_only=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = models.PrintingJob
|
||||
fields = [
|
||||
'id', 'original_id', 'printing_order', 'printing_order_id', 'product', 'product_name',
|
||||
'id', 'original_id', 'merchant_id', 'printing_order', 'printing_order_id', 'product', 'product_name',
|
||||
'product_image_url', 'has_started',
|
||||
'quantity', 'unit', 'size', 'pieces', 'description',
|
||||
'work_state', 'work_state_display',
|
||||
@@ -332,7 +335,7 @@ class PrintingJobListSerializer(serializers.ModelSerializer):
|
||||
read_only_fields = [
|
||||
'id', 'created_at', 'updated_at',
|
||||
'status', 'is_completed', 'progress_percentage', 'last_completed_state',
|
||||
'business_object_id'
|
||||
'business_object_id', 'merchant_id'
|
||||
]
|
||||
|
||||
def get_business_object_id(self, obj):
|
||||
@@ -394,11 +397,12 @@ class PrintingJobDetailSerializer(serializers.ModelSerializer):
|
||||
last_completed_state = serializers.CharField(read_only=True)
|
||||
business_object_id = serializers.SerializerMethodField()
|
||||
batch_advance_records = serializers.SerializerMethodField()
|
||||
merchant_id = serializers.IntegerField(source='merchant.id', read_only=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = models.PrintingJob
|
||||
fields = [
|
||||
'id', 'original_id', 'printing_order', 'printing_order_id', 'product', 'product_name', 'product_code',
|
||||
'id', 'original_id', 'merchant_id', 'printing_order', 'printing_order_id', 'product', 'product_name', 'product_code',
|
||||
'quantity', 'unit', 'size', 'pieces', 'description',
|
||||
'work_state', 'work_state_display',
|
||||
'status', 'status_id', 'is_completed', 'has_started',
|
||||
@@ -411,7 +415,7 @@ class PrintingJobDetailSerializer(serializers.ModelSerializer):
|
||||
'id', 'created_at', 'updated_at',
|
||||
'status', 'status_id', 'is_completed', 'has_started',
|
||||
'progress_percentage', 'last_completed_state',
|
||||
'business_object_id'
|
||||
'business_object_id', 'merchant_id'
|
||||
]
|
||||
|
||||
def get_business_object_id(self, obj):
|
||||
@@ -550,12 +554,13 @@ class PlateOrderListSerializer(PlateOrderDesignCodeMixin, serializers.ModelSeria
|
||||
last_completed_state = serializers.CharField(read_only=True)
|
||||
content_type_id = serializers.SerializerMethodField()
|
||||
created_by_name = serializers.SerializerMethodField()
|
||||
merchant_id = serializers.IntegerField(source='merchant.id', read_only=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = models.PlateOrder
|
||||
|
||||
fields = [
|
||||
'id', 'original_id', 'design_code', 'plate_type', 'plate_date', 'plate_method',
|
||||
'id', 'original_id', 'merchant_id', 'design_code', 'plate_type', 'plate_date', 'plate_method',
|
||||
'plate_image', 'plate_image_url', 'image_name', 'plate_notes', 'reprint_reason',
|
||||
'urgency_level', 'is_invalid',
|
||||
'customer', 'customer_name', 'area', 'default_address',
|
||||
@@ -576,7 +581,7 @@ class PlateOrderListSerializer(PlateOrderDesignCodeMixin, serializers.ModelSeria
|
||||
]
|
||||
read_only_fields = [
|
||||
'id', 'status', 'progress_percentage', 'last_completed_state',
|
||||
'created_at', 'updated_at', 'print_count'
|
||||
'created_at', 'updated_at', 'print_count', 'merchant_id'
|
||||
]
|
||||
|
||||
def get_plate_image_url(self, obj):
|
||||
@@ -630,11 +635,12 @@ class PlateOrderDetailSerializer(PlateOrderDesignCodeMixin, serializers.ModelSer
|
||||
plate_image_url = serializers.SerializerMethodField()
|
||||
process_name = serializers.SerializerMethodField()
|
||||
last_completed_state = serializers.CharField(read_only=True)
|
||||
merchant_id = serializers.IntegerField(source='merchant.id', read_only=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = models.PlateOrder
|
||||
fields = [
|
||||
'id', 'original_id', 'design_code', 'plate_type', 'plate_date', 'plate_method',
|
||||
'id', 'original_id', 'merchant_id', 'design_code', 'plate_type', 'plate_date', 'plate_method',
|
||||
'plate_image', 'plate_image_url', 'image_name', 'plate_notes', 'reprint_reason',
|
||||
'urgency_level', 'is_invalid',
|
||||
'customer', 'customer_name', 'customer_phone', 'area', 'default_address',
|
||||
@@ -656,7 +662,7 @@ class PlateOrderDetailSerializer(PlateOrderDesignCodeMixin, serializers.ModelSer
|
||||
read_only_fields = [
|
||||
'id', 'status', 'status_id', 'is_completed', 'has_started',
|
||||
'progress_percentage', 'business_object_id', 'last_completed_state',
|
||||
'created_at', 'updated_at', 'print_count'
|
||||
'created_at', 'updated_at', 'print_count', 'merchant_id'
|
||||
]
|
||||
|
||||
def get_business_object_id(self, obj):
|
||||
|
||||
@@ -46,6 +46,10 @@ class PrintingOrderService:
|
||||
# 绑定创建人
|
||||
data['created_by'] = user
|
||||
|
||||
# 绑定商户(从当前用户的 employee 获取)
|
||||
if hasattr(user, 'employee') and user.employee and user.employee.merchant:
|
||||
data['merchant'] = user.employee.merchant
|
||||
|
||||
order = printing_models.PrintingOrder.objects.create(**data)
|
||||
return order
|
||||
|
||||
@@ -128,6 +132,10 @@ class PrintingJobService:
|
||||
# 绑定创建人
|
||||
data['created_by'] = user
|
||||
|
||||
# 绑定商户(从当前用户的 employee 获取)
|
||||
if hasattr(user, 'employee') and user.employee and user.employee.merchant:
|
||||
data['merchant'] = user.employee.merchant
|
||||
|
||||
# 创建 PrintingJob
|
||||
job = printing_models.PrintingJob.objects.create(**data)
|
||||
|
||||
|
||||
@@ -106,6 +106,8 @@ class PrintingOrderAPITestCase(TestCase):
|
||||
self.assertIsNotNone(order)
|
||||
self.assertEqual(order.customer.id, self.customer.id)
|
||||
self.assertEqual(order.fabric, '纯棉布料')
|
||||
# 验证 merchant 自动绑定
|
||||
self.assertEqual(order.merchant.id, self.merchant.id)
|
||||
|
||||
def test_list_printing_orders(self):
|
||||
"""测试获取订单列表"""
|
||||
|
||||
@@ -740,9 +740,13 @@ class PlateOrderViewSet(LimitedModelViewSet):
|
||||
|
||||
def perform_create(self, serializer):
|
||||
"""
|
||||
创建时自动绑定创建人(created_by),不允许前端传参控制。
|
||||
创建时自动绑定创建人(created_by)和商户(merchant),不允许前端传参控制。
|
||||
"""
|
||||
serializer.save(created_by=self.request.user)
|
||||
user = self.request.user
|
||||
merchant = None
|
||||
if hasattr(user, 'employee') and user.employee and user.employee.merchant:
|
||||
merchant = user.employee.merchant
|
||||
serializer.save(created_by=user, merchant=merchant)
|
||||
|
||||
@action(detail=True, methods=['post'])
|
||||
def invalidate(self, request, pk=None):
|
||||
|
||||
Reference in New Issue
Block a user