remove organization assignment logic in device and services modules
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
from rest_framework.exceptions import APIException
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
from rest_framework.exceptions import APIException
|
||||||
|
|
||||||
|
|
||||||
class DeviceAlreadyAssigned(APIException):
|
class DeviceAlreadyAssigned(APIException):
|
||||||
status_code = status.HTTP_403_FORBIDDEN
|
status_code = status.HTTP_403_FORBIDDEN
|
||||||
default_detail = "این دستگاه قبلا به این کلاینت تخصیص داده شده است" # noqa
|
default_detail = "این دستگاه قبلا به این کلاینت تخصیص داده شده است" # noqa
|
||||||
|
|
||||||
|
|
||||||
|
class OrganizationDeviceNotAssigned(APIException):
|
||||||
|
status_code = status.HTTP_403_FORBIDDEN
|
||||||
|
default_detail = "این سازمان دستگاه فعالی ندارد" # noqa
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
from apps.product.web.api.v1.serializers.quota_distribution_serializers import QuotaDistributionSerializer
|
|
||||||
from apps.authentication.api.v1.serializers.serializer import BankAccountSerializer
|
|
||||||
from apps.pos_device.web.api.v1.serilaizers import client as client_serializer
|
|
||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
from apps.pos_device import models as pos_models
|
|
||||||
from rest_framework.exceptions import APIException
|
from apps.authentication.api.v1.serializers.serializer import BankAccountSerializer
|
||||||
from apps.pos_device import exceptions as pos_exceptions
|
from apps.pos_device import exceptions as pos_exceptions
|
||||||
from rest_framework import status
|
from apps.pos_device import models as pos_models
|
||||||
|
from apps.pos_device.web.api.v1.serilaizers import client as client_serializer
|
||||||
|
from apps.product.web.api.v1.serializers.quota_distribution_serializers import QuotaDistributionSerializer
|
||||||
|
|
||||||
|
|
||||||
class ProviderCompanySerializer(ModelSerializer):
|
class ProviderCompanySerializer(ModelSerializer):
|
||||||
@@ -99,6 +98,18 @@ class StakeHolderShareAmountSerializer(ModelSerializer):
|
|||||||
model = pos_models.StakeHolderShareAmount
|
model = pos_models.StakeHolderShareAmount
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
def validate(self, attrs):
|
||||||
|
stakeholders = attrs['stakeholders']
|
||||||
|
|
||||||
|
# check organization has pos device
|
||||||
|
assigned_organization = pos_models.Organization.objects.get(
|
||||||
|
id=attrs['distribution'].assigned_organization
|
||||||
|
)
|
||||||
|
if not assigned_organization.has_pos:
|
||||||
|
raise pos_exceptions.OrganizationDeviceNotAssigned()
|
||||||
|
|
||||||
|
return attrs
|
||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
representation = super().to_representation(instance)
|
representation = super().to_representation(instance)
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ from apps.core.mixins.admin_mixin import AdminFilterMixin
|
|||||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||||
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from apps.pos_device import models as pos_models
|
from apps.pos_device import models as pos_models
|
||||||
from apps.pos_device.services.services import get_organization_by_stake_holder
|
|
||||||
from apps.pos_device.web.api.v1.serilaizers import device as device_serializer
|
from apps.pos_device.web.api.v1.serilaizers import device as device_serializer
|
||||||
from apps.pos_device.web.api.v1.viewsets.client import POSClientViewSet
|
from apps.pos_device.web.api.v1.viewsets.client import POSClientViewSet
|
||||||
from apps.product.models import Broker
|
from apps.product.models import Broker
|
||||||
@@ -238,7 +237,7 @@ class DeviceAssignmentViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
|||||||
client_org.save()
|
client_org.save()
|
||||||
|
|
||||||
# after pos device assignment, must set owner
|
# after pos device assignment, must set owner
|
||||||
# as default stake holder
|
# as default stakeholder
|
||||||
pos_models.StakeHolders.objects.create(
|
pos_models.StakeHolders.objects.create(
|
||||||
assignment=assignment,
|
assignment=assignment,
|
||||||
device=assignment.device,
|
device=assignment.device,
|
||||||
@@ -381,13 +380,10 @@ class StakeHolderShareAmountViewSet(SoftDeleteMixin, viewsets.ModelViewSet, Dyna
|
|||||||
organization = get_organization_by_user(request.user)
|
organization = get_organization_by_user(request.user)
|
||||||
data.update({'registering_organization': organization.id})
|
data.update({'registering_organization': organization.id})
|
||||||
|
|
||||||
# set assigner and assigned organization in distribution data
|
# set assigner organization in distribution data
|
||||||
assigner_organization = get_organization_by_user(request.user)
|
assigner_organization = get_organization_by_user(request.user)
|
||||||
data['distribution'].update({'assigner_organization': assigner_organization.id})
|
data['distribution'].update({'assigner_organization': assigner_organization.id})
|
||||||
|
|
||||||
assigned_organization = get_organization_by_stake_holder(id=data['stakeholders'])
|
|
||||||
data['distribution'].update({'assigned_organization': assigned_organization.id})
|
|
||||||
|
|
||||||
# create distribution
|
# create distribution
|
||||||
if 'distribution' in data.keys():
|
if 'distribution' in data.keys():
|
||||||
distribution = CustomOperations().custom_create(
|
distribution = CustomOperations().custom_create(
|
||||||
|
|||||||
Reference in New Issue
Block a user