change structure of quota update - recreate fields
This commit is contained in:
@@ -146,101 +146,87 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
|
|||||||
# create incentive plan
|
# create incentive plan
|
||||||
plans_list = []
|
plans_list = []
|
||||||
if 'incentive_plan_data' in request.data.keys():
|
if 'incentive_plan_data' in request.data.keys():
|
||||||
|
|
||||||
|
# remove all incentive assignment relations
|
||||||
|
quota.incentive_assignments.all().delete()
|
||||||
|
|
||||||
for plan in request.data['incentive_plan_data']:
|
for plan in request.data['incentive_plan_data']:
|
||||||
|
# create new relations
|
||||||
plan.update({'quota': quota.id})
|
plan.update({'quota': quota.id})
|
||||||
if 'id' in plan.keys():
|
incentive_plan = CustomOperations().custom_create(
|
||||||
incentive_plan = CustomOperations().custom_update(
|
request=request,
|
||||||
request=request,
|
view=QuotaIncentiveAssignmentViewSet(),
|
||||||
view=QuotaIncentiveAssignmentViewSet(),
|
data_key='incentive_plan_data',
|
||||||
data_key='incentive_plan_data',
|
data=plan
|
||||||
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)
|
plans_list.append(incentive_plan)
|
||||||
|
|
||||||
# create product price attributes for quota
|
# create product price attributes for quota
|
||||||
attributes_value_list = [] # noqa
|
attributes_value_list = [] # noqa
|
||||||
if 'price_attributes_data' in request.data.keys():
|
if 'price_attributes_data' in request.data.keys():
|
||||||
|
|
||||||
|
# remove all price attribute relations
|
||||||
|
quota.attribute_values.all().delete()
|
||||||
|
|
||||||
for attr in request.data['price_attributes_data']:
|
for attr in request.data['price_attributes_data']:
|
||||||
|
# create new relations
|
||||||
attr.update({'quota': quota.id})
|
attr.update({'quota': quota.id})
|
||||||
if 'id' in attr.keys():
|
attributes = CustomOperations().custom_create(
|
||||||
attributes = CustomOperations().custom_update(
|
request=request,
|
||||||
request=request,
|
view=product_api.AttributeValueViewSet(),
|
||||||
view=product_api.AttributeValueViewSet(),
|
data=attr
|
||||||
obj_id=attr['id'],
|
)
|
||||||
data=attr
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
attributes = CustomOperations().custom_create(
|
|
||||||
request=request,
|
|
||||||
view=product_api.AttributeValueViewSet(),
|
|
||||||
data=attr
|
|
||||||
)
|
|
||||||
attributes_value_list.append(attributes)
|
attributes_value_list.append(attributes)
|
||||||
|
|
||||||
# create product broker values for quota
|
# create product broker values for quota
|
||||||
broker_data_list = []
|
broker_data_list = [] # noqa
|
||||||
if 'broker_data' in request.data.keys():
|
if 'broker_data' in request.data.keys():
|
||||||
|
|
||||||
|
# remove broker values relations
|
||||||
|
quota.broker_values.all().delete()
|
||||||
|
|
||||||
for broker in request.data['broker_data']:
|
for broker in request.data['broker_data']:
|
||||||
|
# create new relations
|
||||||
broker.update({'quota': quota.id})
|
broker.update({'quota': quota.id})
|
||||||
if 'id' in broker.keys():
|
broker_value = CustomOperations().custom_create(
|
||||||
broker_value = CustomOperations().custom_update(
|
request=request,
|
||||||
request=request,
|
view=QuotaBrokerValueViewSet(),
|
||||||
view=QuotaBrokerValueViewSet(),
|
data=broker
|
||||||
obj_id=broker['id'],
|
)
|
||||||
data=broker
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
broker_value = CustomOperations().custom_create(
|
|
||||||
request=request,
|
|
||||||
view=QuotaBrokerValueViewSet(),
|
|
||||||
data=broker
|
|
||||||
)
|
|
||||||
broker_data_list.append(broker_value)
|
broker_data_list.append(broker_value)
|
||||||
|
|
||||||
# create livestock allocations to quota
|
# create livestock allocations to quota
|
||||||
allocations_list = []
|
allocations_list = []
|
||||||
if 'livestock_allocation_data' in request.data.keys():
|
if 'livestock_allocation_data' in request.data.keys():
|
||||||
|
|
||||||
|
# remove livestock allocations data relations
|
||||||
|
quota.livestock_allocations.all().delete()
|
||||||
|
|
||||||
for ls_alloc in request.data['livestock_allocation_data']:
|
for ls_alloc in request.data['livestock_allocation_data']:
|
||||||
|
# create new relations
|
||||||
ls_alloc.update({'quota': quota.id})
|
ls_alloc.update({'quota': quota.id})
|
||||||
if 'id' in ls_alloc.keys():
|
allocations = CustomOperations().custom_create(
|
||||||
allocations = CustomOperations().custom_update(
|
request=request,
|
||||||
request=request,
|
view=QuotaLiveStockAllocationViewSet(),
|
||||||
view=QuotaLiveStockAllocationViewSet(),
|
data=ls_alloc
|
||||||
obj_id=ls_alloc['id'],
|
)
|
||||||
data=ls_alloc
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
allocations = CustomOperations().custom_create(
|
|
||||||
request=request,
|
|
||||||
view=QuotaLiveStockAllocationViewSet(),
|
|
||||||
data=ls_alloc
|
|
||||||
)
|
|
||||||
allocations_list.append(allocations)
|
allocations_list.append(allocations)
|
||||||
|
|
||||||
# create livestock age limits for quota
|
# create livestock age limits for quota
|
||||||
livestock_age_limits = []
|
livestock_age_limits = []
|
||||||
if 'livestock_age_limitations' in request.data.keys():
|
if 'livestock_age_limitations' in request.data.keys():
|
||||||
|
|
||||||
|
# remove live stock age limit relations
|
||||||
|
quota.livestock_age_limitations.all().delete()
|
||||||
|
|
||||||
for age_limit in request.data['livestock_age_limitations']:
|
for age_limit in request.data['livestock_age_limitations']:
|
||||||
|
# create new relations
|
||||||
age_limit.update({'quota': quota.id})
|
age_limit.update({'quota': quota.id})
|
||||||
if 'id' in age_limit.keys():
|
age_limit_creation_object = CustomOperations().custom_create(
|
||||||
age_limit_creation_object = CustomOperations().custom_update(
|
request=request,
|
||||||
request=request,
|
view=QuotaLiveStockAgeLimitation(),
|
||||||
view=QuotaLiveStockAgeLimitation(),
|
data=age_limit
|
||||||
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)
|
livestock_age_limits.append(age_limit_creation_object)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user