change structure of quota update - recreate fields

This commit is contained in:
2025-07-23 14:38:19 +03:30
parent b7556a52a1
commit 357d6d5cac

View File

@@ -146,101 +146,87 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
# create incentive plan
plans_list = []
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']:
# create new relations
plan.update({'quota': quota.id})
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
)
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
attributes_value_list = [] # noqa
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']:
# create new relations
attr.update({'quota': quota.id})
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 = 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 = []
broker_data_list = [] # noqa
if 'broker_data' in request.data.keys():
# remove broker values relations
quota.broker_values.all().delete()
for broker in request.data['broker_data']:
# create new relations
broker.update({'quota': quota.id})
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_value = CustomOperations().custom_create(
request=request,
view=QuotaBrokerValueViewSet(),
data=broker
)
broker_data_list.append(broker_value)
# create livestock allocations to quota
allocations_list = []
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']:
# create new relations
ls_alloc.update({'quota': quota.id})
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 = 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():
# remove live stock age limit relations
quota.livestock_age_limitations.all().delete()
for age_limit in request.data['livestock_age_limitations']:
# create new relations
age_limit.update({'quota': quota.id})
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
)
age_limit_creation_object = CustomOperations().custom_create(
request=request,
view=QuotaLiveStockAgeLimitation(),
data=age_limit
)
livestock_age_limits.append(age_limit_creation_object)
data = {