remove organization assignment logic in device and services modules

This commit is contained in:
2025-10-22 14:53:10 +03:30
parent 91e2a0bb0b
commit a2ff8b863e
3 changed files with 25 additions and 13 deletions

View File

@@ -1,7 +1,12 @@
from rest_framework.exceptions import APIException
from rest_framework import status
from rest_framework.exceptions import APIException
class DeviceAlreadyAssigned(APIException):
status_code = status.HTTP_403_FORBIDDEN
default_detail = "این دستگاه قبلا به این کلاینت تخصیص داده شده است" # noqa
class OrganizationDeviceNotAssigned(APIException):
status_code = status.HTTP_403_FORBIDDEN
default_detail = "این سازمان دستگاه فعالی ندارد" # noqa

View File

@@ -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 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 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):
@@ -99,6 +98,18 @@ class StakeHolderShareAmountSerializer(ModelSerializer):
model = pos_models.StakeHolderShareAmount
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):
representation = super().to_representation(instance)

View File

@@ -22,7 +22,6 @@ from apps.core.mixins.admin_mixin import AdminFilterMixin
from apps.core.mixins.search_mixin import DynamicSearchMixin
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
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.viewsets.client import POSClientViewSet
from apps.product.models import Broker
@@ -238,7 +237,7 @@ class DeviceAssignmentViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
client_org.save()
# after pos device assignment, must set owner
# as default stake holder
# as default stakeholder
pos_models.StakeHolders.objects.create(
assignment=assignment,
device=assignment.device,
@@ -381,13 +380,10 @@ class StakeHolderShareAmountViewSet(SoftDeleteMixin, viewsets.ModelViewSet, Dyna
organization = get_organization_by_user(request.user)
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)
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
if 'distribution' in data.keys():
distribution = CustomOperations().custom_create(