add organization assignment logic in device and services modules
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
|
import typing
|
||||||
|
|
||||||
|
from apps.pos_device.models import Device, StakeHolders
|
||||||
from apps.product.models import (
|
from apps.product.models import (
|
||||||
Quota,
|
Quota,
|
||||||
QuotaDistribution,
|
QuotaDistribution,
|
||||||
Organization,
|
Organization
|
||||||
QuotaPriceCalculationItems,
|
|
||||||
QuotaFinalPriceTypes
|
|
||||||
)
|
)
|
||||||
from apps.pos_device.models import Device, StakeHolderShareAmount
|
|
||||||
import typing
|
|
||||||
|
|
||||||
|
|
||||||
def pos_organizations_sharing_information(
|
def pos_organizations_sharing_information(
|
||||||
@@ -95,3 +94,14 @@ def agency_organization_pos_info(
|
|||||||
})
|
})
|
||||||
|
|
||||||
return pos_sharing_list
|
return pos_sharing_list
|
||||||
|
|
||||||
|
|
||||||
|
def get_organization_by_stake_holder(id: int = None, stake_holder: StakeHolders = None) -> typing.Any:
|
||||||
|
""" get organization object by stake holder """
|
||||||
|
|
||||||
|
if id:
|
||||||
|
stake_holder = StakeHolders.objects.get(id=id)
|
||||||
|
organization = get_organization_by_stake_holder(stake_holder=stake_holder)
|
||||||
|
return organization
|
||||||
|
organization = stake_holder.assignment.client.organization
|
||||||
|
return organization
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ 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
|
||||||
@@ -376,12 +377,17 @@ class StakeHolderShareAmountViewSet(SoftDeleteMixin, viewsets.ModelViewSet, Dyna
|
|||||||
|
|
||||||
data = request.data.copy()
|
data = request.data.copy()
|
||||||
|
|
||||||
|
# set registering organization
|
||||||
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
|
||||||
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