forked from erp-dev/erp
fix: business cancel service merged
This commit is contained in:
@@ -13,6 +13,21 @@ from .services import PrintingOrderService, PrintingJobService
|
||||
from basic_info.models import Customer, Employee
|
||||
|
||||
|
||||
def _include_sales_order_bound(context) -> bool:
|
||||
request = context.get('request') if context else None
|
||||
if not request:
|
||||
return True
|
||||
raw_value = request.query_params.get('include_sales_order_bound')
|
||||
return str(raw_value).lower() not in {'0', 'false', 'no'}
|
||||
|
||||
|
||||
def _get_is_sales_order_bound(obj) -> bool:
|
||||
annotated_value = getattr(obj, 'annotated_is_sales_order_bound', None)
|
||||
if annotated_value is not None:
|
||||
return bool(annotated_value)
|
||||
return bool(obj.is_sales_order_bound)
|
||||
|
||||
|
||||
def _build_absolute_media_url(url: str | None, request):
|
||||
return build_public_media_url(url, request=request)
|
||||
|
||||
@@ -346,6 +361,8 @@ class PrintingJobListSerializer(serializers.ModelSerializer):
|
||||
business_object_id = serializers.SerializerMethodField()
|
||||
batch_advance_records = serializers.SerializerMethodField()
|
||||
saleitems = serializers.SerializerMethodField()
|
||||
is_sales_order_bound = serializers.SerializerMethodField()
|
||||
billed_quantity = serializers.DecimalField(max_digits=18, decimal_places=2, read_only=True)
|
||||
merchant_id = serializers.IntegerField(source='merchant.id', read_only=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
@@ -353,10 +370,11 @@ class PrintingJobListSerializer(serializers.ModelSerializer):
|
||||
fields = [
|
||||
'id', 'original_id', 'merchant_id', 'printing_order', 'printing_order_id', 'external_order_id', 'product', 'product_name',
|
||||
'product_image_url', 'has_started',
|
||||
'quantity', 'unit', 'size', 'pieces', 'description',
|
||||
'quantity', 'billed_quantity', 'unit', 'size', 'pieces', 'description',
|
||||
'work_state', 'work_state_display',
|
||||
'status', 'is_completed', 'is_production_completed', 'progress_percentage', 'last_completed_state',
|
||||
'business_object_id',
|
||||
'is_sales_order_bound',
|
||||
'batch_advance_records',
|
||||
'saleitems',
|
||||
'created_at', 'updated_at'
|
||||
@@ -364,8 +382,14 @@ class PrintingJobListSerializer(serializers.ModelSerializer):
|
||||
read_only_fields = [
|
||||
'id', 'created_at', 'updated_at',
|
||||
'status', 'is_completed', 'is_production_completed', 'progress_percentage', 'last_completed_state',
|
||||
'business_object_id', 'merchant_id'
|
||||
'business_object_id', 'is_sales_order_bound', 'billed_quantity', 'merchant_id'
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
data = super().to_representation(instance)
|
||||
if not _include_sales_order_bound(self.context):
|
||||
data.pop('is_sales_order_bound', None)
|
||||
return data
|
||||
|
||||
def get_business_object_id(self, obj):
|
||||
"""安全地获取 business_object_id"""
|
||||
@@ -422,6 +446,9 @@ class PrintingJobListSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
return SalesItemSerializer(items, many=True).data
|
||||
|
||||
def get_is_sales_order_bound(self, obj):
|
||||
return _get_is_sales_order_bound(obj)
|
||||
|
||||
|
||||
class PrintingJobDetailSerializer(serializers.ModelSerializer):
|
||||
"""印染款式明细详情序列化器"""
|
||||
@@ -440,17 +467,20 @@ class PrintingJobDetailSerializer(serializers.ModelSerializer):
|
||||
business_object_id = serializers.SerializerMethodField()
|
||||
batch_advance_records = serializers.SerializerMethodField()
|
||||
saleitems = serializers.SerializerMethodField()
|
||||
is_sales_order_bound = serializers.SerializerMethodField()
|
||||
billed_quantity = serializers.DecimalField(max_digits=18, decimal_places=2, read_only=True)
|
||||
merchant_id = serializers.IntegerField(source='merchant.id', read_only=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = models.PrintingJob
|
||||
fields = [
|
||||
'id', 'original_id', 'merchant_id', 'printing_order', 'printing_order_id', 'external_order_id', 'product', 'product_name', 'product_code',
|
||||
'quantity', 'unit', 'size', 'pieces', 'description',
|
||||
'quantity', 'billed_quantity', 'unit', 'size', 'pieces', 'description',
|
||||
'work_state', 'work_state_display',
|
||||
'status', 'status_id', 'is_completed', 'is_production_completed', 'has_started',
|
||||
'progress_percentage', 'last_completed_state',
|
||||
'business_object_id',
|
||||
'is_sales_order_bound',
|
||||
'batch_advance_records',
|
||||
'saleitems',
|
||||
'created_at', 'updated_at'
|
||||
@@ -459,8 +489,14 @@ class PrintingJobDetailSerializer(serializers.ModelSerializer):
|
||||
'id', 'created_at', 'updated_at',
|
||||
'status', 'status_id', 'is_completed', 'is_production_completed', 'has_started',
|
||||
'progress_percentage', 'last_completed_state',
|
||||
'business_object_id', 'merchant_id'
|
||||
'business_object_id', 'is_sales_order_bound', 'billed_quantity', 'merchant_id'
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
data = super().to_representation(instance)
|
||||
if not _include_sales_order_bound(self.context):
|
||||
data.pop('is_sales_order_bound', None)
|
||||
return data
|
||||
|
||||
def get_business_object_id(self, obj):
|
||||
"""安全地获取 business_object_id"""
|
||||
@@ -485,19 +521,23 @@ class PrintingJobDetailSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
return SalesItemSerializer(items, many=True).data
|
||||
|
||||
def get_is_sales_order_bound(self, obj):
|
||||
return _get_is_sales_order_bound(obj)
|
||||
|
||||
|
||||
class PrintingJobCreateUpdateSerializer(serializers.ModelSerializer):
|
||||
"""印染款式明细创建/更新序列化器"""
|
||||
external_order_id = serializers.CharField(source='printing_order.external_order_id', read_only=True)
|
||||
batch_advance_records = serializers.SerializerMethodField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = models.PrintingJob
|
||||
fields = [
|
||||
'id', 'original_id', 'printing_order', 'product', 'quantity', 'unit', 'size', 'pieces', 'description',
|
||||
'id', 'original_id', 'printing_order', 'external_order_id', 'product', 'quantity', 'unit', 'size', 'pieces', 'description',
|
||||
'work_state',
|
||||
'batch_advance_records',
|
||||
]
|
||||
read_only_fields = ['id']
|
||||
read_only_fields = ['id', 'external_order_id']
|
||||
extra_kwargs = {
|
||||
'size': {'required': False, 'allow_null': True, 'allow_blank': True},
|
||||
'pieces': {'required': False, 'allow_null': True},
|
||||
|
||||
Reference in New Issue
Block a user