add purchace limitations system for rancher - add incentive plans to rancher entries data

This commit is contained in:
2025-08-26 12:18:10 +03:30
parent b5dfcebafe
commit c0b6b8ddca
12 changed files with 142 additions and 14 deletions

View File

@@ -1,11 +1,12 @@
from datetime import timedelta
from apps.pos_device.web.api.v1.serilaizers import device as device_serializer
from apps.authentication.exceptions import OrganizationBankAccountException
from apps.authorization.api.v1.serializers import UserRelationSerializer
from apps.pos_device.web.api.v1.viewsets.client import POSClientViewSet
from apps.authentication.api.v1.api import (
UserViewSet,
Organization,
BankAccountInformation,
OrganizationSerializer
)
from apps.core.mixins.search_mixin import DynamicSearchMixin
@@ -176,10 +177,17 @@ class DeviceAssignmentViewSet(viewsets.ModelViewSet):
# if client will be an organization
if request.data['client_data']['is_organization']:
# check if organization have bank account or raise exception
if not BankAccountInformation.objects.filter(
organization_id=request.data['client_data']['organization']
).exists():
raise OrganizationBankAccountException()
# check if organization is a client before
client = pos_models.POSClient.objects.filter(
organization_id=request.data['client_data']['organization']
)
if client.exists():
request.data.update({'client': client.first().id})
@@ -276,6 +284,13 @@ class StakeHoldersViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
stakeholders_data = []
for stakeholder in request.data['stakeholders']:
# check if organization have bank account or raise exception
if not BankAccountInformation.objects.filter(
organization_id=stakeholder['organization']
).exists():
raise OrganizationBankAccountException()
serializer = self.serializer_class(data=stakeholder)
if serializer.is_valid():
serializer.save()