create rancher incentive plan structure - add pos device main sheba
This commit is contained in:
@@ -2,9 +2,10 @@ from rest_framework import serializers
|
||||
from apps.product import models as product_models
|
||||
from apps.authorization.api.v1 import serializers as authorize_serializers
|
||||
from apps.authentication.api.v1.serializers.serializer import OrganizationSerializer, OrganizationTypeSerializer
|
||||
from apps.product import exceptions
|
||||
|
||||
|
||||
class ProductCategorySerializer(serializers.ModelSerializer):
|
||||
class ProductCategorySerializer(serializers.ModelSerializer): # noqa
|
||||
class Meta:
|
||||
model = product_models.ProductCategory
|
||||
fields = '__all__'
|
||||
@@ -161,3 +162,20 @@ class IncentivePlanRancherSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.IncentivePlanRancher
|
||||
fields = '__all__'
|
||||
|
||||
def validate(self, attrs):
|
||||
""" validate incentive plans of a rancher """
|
||||
|
||||
rancher_plans_data = self.context['request'].data['data']
|
||||
|
||||
# check if rancher with same plan & livestock exists
|
||||
if not self.instance:
|
||||
for plan in rancher_plans_data:
|
||||
if product_models.IncentivePlanRancher.objects.filter(
|
||||
plan_id=plan['plan'],
|
||||
rancher_id=plan['rancher'],
|
||||
livestock_type_id=plan['livestock_type'],
|
||||
).exists():
|
||||
raise exceptions.RancherIncentivePlanExists()
|
||||
|
||||
return attrs
|
||||
|
||||
Reference in New Issue
Block a user