change quota serializer key names
This commit is contained in:
@@ -19,27 +19,27 @@ class QuotaSerializer(serializers.ModelSerializer):
|
||||
instance.sale_unit
|
||||
).data
|
||||
representation['product'] = {"product": instance.product.name, "product_id": instance.product.id}
|
||||
representation['incentive_plan'] = QuotaIncentiveAssignmentSerializer(
|
||||
representation['incentive_plan_data'] = QuotaIncentiveAssignmentSerializer(
|
||||
instance.incentive_assignments.all(),
|
||||
many=True
|
||||
).data
|
||||
|
||||
representation['attribute_values'] = product_serializers.AttributeValueSerializer(
|
||||
representation['price_attributes_data'] = product_serializers.AttributeValueSerializer(
|
||||
instance.attribute_values.all(),
|
||||
many=True
|
||||
).data
|
||||
|
||||
representation['brokers'] = QuotaBrokerValueSerializer(
|
||||
representation['broker_data'] = QuotaBrokerValueSerializer(
|
||||
instance.broker_values.all(),
|
||||
many=True
|
||||
).data
|
||||
|
||||
representation['livestock_allocations'] = QuotaLiveStockAllocationSerializer(
|
||||
representation['livestock_allocation_data'] = QuotaLiveStockAllocationSerializer(
|
||||
instance.livestock_allocations.all(),
|
||||
many=True
|
||||
).data
|
||||
|
||||
representation['livestock_limitations'] = QuotaLiveStockAgeLimitationSerializer(
|
||||
representation['livestock_age_limitations'] = QuotaLiveStockAgeLimitationSerializer(
|
||||
instance.livestock_age_limitations.all(),
|
||||
many=True
|
||||
).data
|
||||
|
||||
@@ -146,13 +146,21 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
|
||||
if 'incentive_plan_data' in request.data.keys():
|
||||
for plan in request.data['incentive_plan_data']:
|
||||
plan.update({'quota': quota.id})
|
||||
incentive_plan = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=QuotaIncentiveAssignmentViewSet(),
|
||||
data_key='incentive_plan_data',
|
||||
obj_id=plan['id'],
|
||||
data=plan
|
||||
)
|
||||
if 'id' in plan.keys():
|
||||
incentive_plan = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=QuotaIncentiveAssignmentViewSet(),
|
||||
data_key='incentive_plan_data',
|
||||
obj_id=plan['id'],
|
||||
data=plan
|
||||
)
|
||||
else:
|
||||
incentive_plan = CustomOperations().custom_create(
|
||||
request=request,
|
||||
view=QuotaIncentiveAssignmentViewSet(),
|
||||
data_key='incentive_plan_data',
|
||||
data=plan
|
||||
)
|
||||
plans_list.append(incentive_plan)
|
||||
|
||||
# create product price attributes for quota
|
||||
@@ -160,24 +168,38 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
|
||||
if 'price_attributes_data' in request.data.keys():
|
||||
for attr in request.data['price_attributes_data']:
|
||||
attr.update({'quota': quota.id})
|
||||
attributes = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=product_api.AttributeValueViewSet(),
|
||||
obj_id=attr['id'],
|
||||
data=attr
|
||||
)
|
||||
if 'id' in attr.keys():
|
||||
attributes = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=product_api.AttributeValueViewSet(),
|
||||
obj_id=attr['id'],
|
||||
data=attr
|
||||
)
|
||||
else:
|
||||
attributes = CustomOperations().custom_create(
|
||||
request=request,
|
||||
view=product_api.AttributeValueViewSet(),
|
||||
data=attr
|
||||
)
|
||||
attributes_value_list.append(attributes)
|
||||
# create product broker values for quota
|
||||
broker_data_list = []
|
||||
if 'broker_data' in request.data.keys():
|
||||
for broker in request.data['broker_data']:
|
||||
broker.update({'quota': quota.id})
|
||||
broker_value = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=QuotaBrokerValueViewSet(),
|
||||
obj_id=broker['id'],
|
||||
data=broker
|
||||
)
|
||||
if 'id' in broker.keys():
|
||||
broker_value = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=QuotaBrokerValueViewSet(),
|
||||
obj_id=broker['id'],
|
||||
data=broker
|
||||
)
|
||||
else:
|
||||
broker_value = CustomOperations().custom_create(
|
||||
request=request,
|
||||
view=QuotaBrokerValueViewSet(),
|
||||
data=broker
|
||||
)
|
||||
broker_data_list.append(broker_value)
|
||||
|
||||
# create livestock allocations to quota
|
||||
@@ -185,24 +207,38 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
|
||||
if 'livestock_allocation_data' in request.data.keys():
|
||||
for ls_alloc in request.data['livestock_allocation_data']:
|
||||
ls_alloc.update({'quota': quota.id})
|
||||
allocations = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=QuotaLiveStockAllocationViewSet(),
|
||||
obj_id=ls_alloc['id'],
|
||||
data=ls_alloc
|
||||
)
|
||||
if 'id' in ls_alloc.keys():
|
||||
allocations = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=QuotaLiveStockAllocationViewSet(),
|
||||
obj_id=ls_alloc['id'],
|
||||
data=ls_alloc
|
||||
)
|
||||
else:
|
||||
allocations = CustomOperations().custom_create(
|
||||
request=request,
|
||||
view=QuotaLiveStockAllocationViewSet(),
|
||||
data=ls_alloc
|
||||
)
|
||||
allocations_list.append(allocations)
|
||||
# create livestock age limits for quota
|
||||
livestock_age_limits = []
|
||||
if 'livestock_age_limitations' in request.data.keys():
|
||||
for age_limit in request.data['livestock_age_limitations']:
|
||||
age_limit.update({'quota': quota.id})
|
||||
age_limit_creation_object = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=QuotaLiveStockAgeLimitation(),
|
||||
obj_id=age_limit['id'],
|
||||
data=age_limit
|
||||
)
|
||||
if 'id' in age_limit.keys():
|
||||
age_limit_creation_object = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=QuotaLiveStockAgeLimitation(),
|
||||
obj_id=age_limit['id'],
|
||||
data=age_limit
|
||||
)
|
||||
else:
|
||||
age_limit_creation_object = CustomOperations().custom_create(
|
||||
request=request,
|
||||
view=QuotaLiveStockAgeLimitation(),
|
||||
data=age_limit
|
||||
)
|
||||
livestock_age_limits.append(age_limit_creation_object)
|
||||
|
||||
data = {
|
||||
|
||||
Reference in New Issue
Block a user