add some new data to device login data, first part of broker to stake holders assignment
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from apps.authentication.api.v1.serializers.jwt import CustomizedTokenObtainPairSerializer
|
from apps.authentication.api.v1.serializers.jwt import CustomizedTokenObtainPairSerializer
|
||||||
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from rest_framework.decorators import action, permission_classes
|
from rest_framework.decorators import action, permission_classes
|
||||||
from apps.authentication import permissions as auth_permissions
|
from apps.authentication import permissions as auth_permissions
|
||||||
from apps.authentication.api.v1.serializers.serializer import (
|
from apps.authentication.api.v1.serializers.serializer import (
|
||||||
@@ -45,7 +46,7 @@ class CustomizedTokenObtainPairView(TokenObtainPairView):
|
|||||||
serializer_class = CustomizedTokenObtainPairSerializer
|
serializer_class = CustomizedTokenObtainPairSerializer
|
||||||
|
|
||||||
|
|
||||||
class UserViewSet(ModelViewSet):
|
class UserViewSet(ModelViewSet, SoftDeleteMixin):
|
||||||
""" Crud operations for user model """
|
""" Crud operations for user model """
|
||||||
queryset = User.objects.all()
|
queryset = User.objects.all()
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
@@ -167,7 +168,7 @@ class UserViewSet(ModelViewSet):
|
|||||||
return Response(serializer.data, status.HTTP_200_OK)
|
return Response(serializer.data, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class CityViewSet(ModelViewSet):
|
class CityViewSet(ModelViewSet, SoftDeleteMixin):
|
||||||
""" Crud operations for city model """ #
|
""" Crud operations for city model """ #
|
||||||
queryset = City.objects.all()
|
queryset = City.objects.all()
|
||||||
serializer_class = CitySerializer
|
serializer_class = CitySerializer
|
||||||
@@ -183,19 +184,19 @@ class CityViewSet(ModelViewSet):
|
|||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class ProvinceViewSet(ModelViewSet):
|
class ProvinceViewSet(ModelViewSet, SoftDeleteMixin):
|
||||||
""" Crud operations for province model """ #
|
""" Crud operations for province model """ #
|
||||||
queryset = Province.objects.all()
|
queryset = Province.objects.all()
|
||||||
serializer_class = ProvinceSerializer
|
serializer_class = ProvinceSerializer
|
||||||
|
|
||||||
|
|
||||||
class OrganizationTypeViewSet(ModelViewSet):
|
class OrganizationTypeViewSet(ModelViewSet, SoftDeleteMixin):
|
||||||
""" Crud operations for Organization Type model """ #
|
""" Crud operations for Organization Type model """ #
|
||||||
queryset = OrganizationType.objects.all()
|
queryset = OrganizationType.objects.all()
|
||||||
serializer_class = OrganizationTypeSerializer
|
serializer_class = OrganizationTypeSerializer
|
||||||
|
|
||||||
|
|
||||||
class OrganizationViewSet(ModelViewSet, DynamicSearchMixin):
|
class OrganizationViewSet(ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
||||||
""" Crud operations for organization model """ #
|
""" Crud operations for organization model """ #
|
||||||
queryset = Organization.objects.all()
|
queryset = Organization.objects.all()
|
||||||
serializer_class = OrganizationSerializer
|
serializer_class = OrganizationSerializer
|
||||||
@@ -336,7 +337,7 @@ class OrganizationViewSet(ModelViewSet, DynamicSearchMixin):
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class BankAccountViewSet(ModelViewSet):
|
class BankAccountViewSet(ModelViewSet, SoftDeleteMixin):
|
||||||
""" Crud operations for bank account model """ #
|
""" Crud operations for bank account model """ #
|
||||||
queryset = BankAccountInformation.objects.all()
|
queryset = BankAccountInformation.objects.all()
|
||||||
serializer_class = BankAccountSerializer
|
serializer_class = BankAccountSerializer
|
||||||
@@ -357,7 +358,7 @@ class BankAccountViewSet(ModelViewSet):
|
|||||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
|
|
||||||
class GeneralOTPViewSet(ModelViewSet):
|
class GeneralOTPViewSet(ModelViewSet, SoftDeleteMixin):
|
||||||
""" general OTP user authorization """
|
""" general OTP user authorization """
|
||||||
|
|
||||||
user_relations_queryset = authorize_view.UserRelations.objects.all()
|
user_relations_queryset = authorize_view.UserRelations.objects.all()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from rest_framework_simplejwt.authentication import JWTAuthentication
|
from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||||
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||||
from apps.core.pagination import CustomPageNumberPagination
|
from apps.core.pagination import CustomPageNumberPagination
|
||||||
from apps.core.exceptions import ConflictException
|
from apps.core.exceptions import ConflictException
|
||||||
@@ -23,14 +24,14 @@ from rest_framework import filters
|
|||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
|
|
||||||
class RoleViewSet(viewsets.ModelViewSet):
|
class RoleViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" Crud Operations For User Roles """
|
""" Crud Operations For User Roles """
|
||||||
|
|
||||||
queryset = Role.objects.all()
|
queryset = Role.objects.all()
|
||||||
serializer_class = RoleSerializer
|
serializer_class = RoleSerializer
|
||||||
|
|
||||||
|
|
||||||
class PageViewSet(viewsets.ModelViewSet):
|
class PageViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" add website pages to system to set permission on it """
|
""" add website pages to system to set permission on it """
|
||||||
|
|
||||||
queryset = Page.objects.all()
|
queryset = Page.objects.all()
|
||||||
@@ -66,7 +67,7 @@ class PageViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class PermissionViewSet(viewsets.ModelViewSet):
|
class PermissionViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" Crud Operations for Permissions """
|
""" Crud Operations for Permissions """
|
||||||
|
|
||||||
queryset = Permissions.objects.all()
|
queryset = Permissions.objects.all()
|
||||||
@@ -96,7 +97,7 @@ class PermissionViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
class UserRelationViewSet(viewsets.ModelViewSet):
|
class UserRelationViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" Crud Operations for User Relations """
|
""" Crud Operations for User Relations """
|
||||||
|
|
||||||
queryset = UserRelations.objects.all()
|
queryset = UserRelations.objects.all()
|
||||||
|
|||||||
12
apps/core/manager.py
Normal file
12
apps/core/manager.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class SoftDeleteManager(models.Manager):
|
||||||
|
""" manager for get all records with trash=False in whole project """
|
||||||
|
def get_queryset(self):
|
||||||
|
return super().get_queryset().filter(trash=False)
|
||||||
|
|
||||||
|
def all_with_deleted(self):
|
||||||
|
""" get all records, also deleted ones """
|
||||||
|
return super().get_queryset().all()
|
||||||
|
|
||||||
14
apps/core/mixins/soft_delete_mixin.py
Normal file
14
apps/core/mixins/soft_delete_mixin.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from rest_framework import status
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
|
||||||
|
class SoftDeleteMixin:
|
||||||
|
def destroy(self, request, *args, **kwargs):
|
||||||
|
""" override destroy -> soft delete """
|
||||||
|
|
||||||
|
instance = self.get_object() # noqa
|
||||||
|
instance.soft_delete()
|
||||||
|
return Response(
|
||||||
|
{"detail": "رکورد با موفقیت حذف شد (Soft Delete)."},
|
||||||
|
status=status.HTTP_200_OK
|
||||||
|
)
|
||||||
@@ -2,6 +2,7 @@ from django.db import models
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from crum import get_current_user
|
from crum import get_current_user
|
||||||
from django.contrib.auth.models import AnonymousUser
|
from django.contrib.auth.models import AnonymousUser
|
||||||
|
from .manager import SoftDeleteManager
|
||||||
|
|
||||||
|
|
||||||
class BaseModel(models.Model):
|
class BaseModel(models.Model):
|
||||||
@@ -24,6 +25,12 @@ class BaseModel(models.Model):
|
|||||||
creator_info = models.CharField(max_length=100, null=True)
|
creator_info = models.CharField(max_length=100, null=True)
|
||||||
modifier_info = models.CharField(max_length=100, null=True)
|
modifier_info = models.CharField(max_length=100, null=True)
|
||||||
trash = models.BooleanField(default=False)
|
trash = models.BooleanField(default=False)
|
||||||
|
objects = SoftDeleteManager() # filter all records with trash=False
|
||||||
|
all_objects = SoftDeleteManager().all_with_deleted() # get all records
|
||||||
|
|
||||||
|
def soft_delete(self):
|
||||||
|
self.trash = True
|
||||||
|
self.save(update_fields=['trash'])
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
from apps.herd.web.api.v1.serializers import HerdSerializer, RancherSerializer
|
from apps.herd.web.api.v1.serializers import HerdSerializer, RancherSerializer
|
||||||
|
from apps.livestock.web.api.v1.serializers import LiveStockSerializer
|
||||||
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||||
from apps.authentication.api.v1.api import UserViewSet
|
from apps.authentication.api.v1.api import UserViewSet
|
||||||
from apps.livestock.web.api.v1.serializers import LiveStockSerializer
|
|
||||||
from common.helpers import get_organization_by_user
|
from common.helpers import get_organization_by_user
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
@@ -13,7 +14,7 @@ from django.db import transaction
|
|||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
|
|
||||||
class HerdViewSet(viewsets.ModelViewSet):
|
class HerdViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" Herd ViewSet """
|
""" Herd ViewSet """
|
||||||
queryset = Herd.objects.all()
|
queryset = Herd.objects.all()
|
||||||
serializer_class = HerdSerializer
|
serializer_class = HerdSerializer
|
||||||
@@ -115,7 +116,7 @@ class HerdViewSet(viewsets.ModelViewSet):
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
||||||
queryset = Rancher.objects.all()
|
queryset = Rancher.objects.all()
|
||||||
serializer_class = RancherSerializer
|
serializer_class = RancherSerializer
|
||||||
search_fields = [
|
search_fields = [
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from apps.livestock import models as livestock_models
|
from apps.livestock import models as livestock_models
|
||||||
from apps.tag.web.api.v1.api import TagViewSet
|
from apps.tag.web.api.v1.api import TagViewSet
|
||||||
@@ -23,7 +24,7 @@ def delete(queryset, pk):
|
|||||||
obj.delete()
|
obj.delete()
|
||||||
|
|
||||||
|
|
||||||
class LiveStockViewSet(viewsets.ModelViewSet): # noqa
|
class LiveStockViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
||||||
queryset = livestock_models.LiveStock.objects.all()
|
queryset = livestock_models.LiveStock.objects.all()
|
||||||
serializer_class = livestock_serializers.LiveStockSerializer
|
serializer_class = livestock_serializers.LiveStockSerializer
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ class LiveStockViewSet(viewsets.ModelViewSet): # noqa
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class LiveStockTypeViewSet(viewsets.ModelViewSet):
|
class LiveStockTypeViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = livestock_models.LiveStockType.objects.all()
|
queryset = livestock_models.LiveStockType.objects.all()
|
||||||
serializer_class = livestock_serializers.LiveStockTypeSerializer
|
serializer_class = livestock_serializers.LiveStockTypeSerializer
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ class LiveStockTypeViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class LiveStockUseTypeViewSet(viewsets.ModelViewSet):
|
class LiveStockUseTypeViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = livestock_models.LiveStockUseType.objects.all()
|
queryset = livestock_models.LiveStockUseType.objects.all()
|
||||||
serializer_class = livestock_serializers.LiveStockUseTypeSerializer
|
serializer_class = livestock_serializers.LiveStockUseTypeSerializer
|
||||||
|
|
||||||
@@ -131,7 +132,7 @@ class LiveStockUseTypeViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class LiveStockSpeciesViewSet(viewsets.ModelViewSet):
|
class LiveStockSpeciesViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = livestock_models.LiveStockSpecies.objects.all()
|
queryset = livestock_models.LiveStockSpecies.objects.all()
|
||||||
serializer_class = livestock_serializers.LiveStockSpeciesSerializer
|
serializer_class = livestock_serializers.LiveStockSpeciesSerializer
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-08-27 12:36
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pos_device', '0063_alter_device_serial'),
|
||||||
|
('product', '0069_quota_group'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='BrokerStakeHolderAssignment',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('create_date', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('modify_date', models.DateTimeField(auto_now=True)),
|
||||||
|
('creator_info', models.CharField(max_length=100, null=True)),
|
||||||
|
('modifier_info', models.CharField(max_length=100, null=True)),
|
||||||
|
('trash', models.BooleanField(default=False)),
|
||||||
|
('broker', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='stake_brok_assignment', to='product.broker')),
|
||||||
|
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_createddby', to=settings.AUTH_USER_MODEL)),
|
||||||
|
('device', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='stake_brok_assigment', to='pos_device.device')),
|
||||||
|
('modified_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_modifiedby', to=settings.AUTH_USER_MODEL)),
|
||||||
|
('stake_holder', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='stake_brok_assignment', to='pos_device.stakeholders')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -2,6 +2,7 @@ import random
|
|||||||
import string
|
import string
|
||||||
|
|
||||||
from apps.authentication.models import Organization
|
from apps.authentication.models import Organization
|
||||||
|
from apps.product.models import Broker
|
||||||
from apps.product.models import Product
|
from apps.product.models import Product
|
||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
from apps.authorization.models import UserRelations
|
from apps.authorization.models import UserRelations
|
||||||
@@ -294,3 +295,29 @@ class POSFreeProducts(BaseModel):
|
|||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
return super(POSFreeProducts, self).save(*args, **kwargs)
|
return super(POSFreeProducts, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class BrokerStakeHolderAssignment(BaseModel):
|
||||||
|
device = models.ForeignKey(
|
||||||
|
Device,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name="stake_brok_assigment",
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
stake_holder = models.ForeignKey(
|
||||||
|
StakeHolders,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='stake_brok_assignment',
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
broker = models.ForeignKey(
|
||||||
|
Broker,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='stake_brok_assignment',
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
return super(BrokerStakeHolderAssignment, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -82,8 +82,9 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
|||||||
"message": "login success - session activated",
|
"message": "login success - session activated",
|
||||||
"device_identity": device.device_identity,
|
"device_identity": device.device_identity,
|
||||||
"serial": device.serial,
|
"serial": device.serial,
|
||||||
|
"password": device.password,
|
||||||
"provider": organization.name,
|
"provider": organization.name,
|
||||||
"provider_users": get_users_of_organization(organization),
|
"provider_tell": '0214021',
|
||||||
"device_owner": device_owner_org,
|
"device_owner": device_owner_org,
|
||||||
"device_owner_users": get_users_of_organization(device_owner_org)
|
"device_owner_users": get_users_of_organization(device_owner_org)
|
||||||
}, status=status.HTTP_200_OK)
|
}, status=status.HTTP_200_OK)
|
||||||
@@ -91,9 +92,10 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
|||||||
return Response({
|
return Response({
|
||||||
"message": "device pre registered - unauthorized",
|
"message": "device pre registered - unauthorized",
|
||||||
"device_identity": device.device_identity,
|
"device_identity": device.device_identity,
|
||||||
|
"password": device.password,
|
||||||
"serial": device.serial,
|
"serial": device.serial,
|
||||||
"provider": organization.name,
|
"provider": organization.name,
|
||||||
"provider_users": get_users_of_organization(organization),
|
"provider_tell": '0214021',
|
||||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||||
|
|
||||||
pre_device = pos_models.Device.objects.create(
|
pre_device = pos_models.Device.objects.create(
|
||||||
@@ -106,8 +108,9 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
|||||||
return Response({
|
return Response({
|
||||||
"message": "device pre-registered",
|
"message": "device pre-registered",
|
||||||
"device_identity": pre_device.device_identity,
|
"device_identity": pre_device.device_identity,
|
||||||
|
"password": device.password,
|
||||||
"provider": organization.name,
|
"provider": organization.name,
|
||||||
"provider_users": get_users_of_organization(organization),
|
"provider_tell": '0214021',
|
||||||
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
|
|||||||
@@ -86,3 +86,9 @@ class StakeHoldersSerializer(ModelSerializer):
|
|||||||
).data
|
).data
|
||||||
|
|
||||||
return representation
|
return representation
|
||||||
|
|
||||||
|
|
||||||
|
class BrokerStakeHolderAssignSerializer(ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = pos_models.BrokerStakeHolderAssignment
|
||||||
|
fields = '__all__'
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ router.register(r'provider', device_views.ProviderCompanyViewSet, basename='prov
|
|||||||
router.register(r'device', device_views.DeviceViewSet, basename='device')
|
router.register(r'device', device_views.DeviceViewSet, basename='device')
|
||||||
router.register(r'device_assignment', device_views.DeviceAssignmentViewSet, basename='device_assignment')
|
router.register(r'device_assignment', device_views.DeviceAssignmentViewSet, basename='device_assignment')
|
||||||
router.register(r'stake_holders', device_views.StakeHoldersViewSet, basename='stake_holders')
|
router.register(r'stake_holders', device_views.StakeHoldersViewSet, basename='stake_holders')
|
||||||
|
router.register(r'broker_stake_assign', device_views.BrokerStakeHolderAssignViewSet, basename='broker_stake_assign')
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('v1/pos/', include(router.urls))
|
path('v1/pos/', include(router.urls))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from apps.pos_device.web.api.v1.serilaizers import client as client_serializer
|
from apps.pos_device.web.api.v1.serilaizers import client as client_serializer
|
||||||
|
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 rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from common.tools import CustomOperations
|
from common.tools import CustomOperations
|
||||||
@@ -6,7 +7,7 @@ from rest_framework import viewsets
|
|||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
|
|
||||||
class POSClientViewSet(viewsets.ModelViewSet):
|
class POSClientViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = pos_models.POSClient.objects.all()
|
queryset = pos_models.POSClient.objects.all()
|
||||||
serializer_class = client_serializer.POSClientSerializer
|
serializer_class = client_serializer.POSClientSerializer
|
||||||
|
|
||||||
@@ -59,11 +60,11 @@ class POSClientViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
|
|
||||||
class POSClientAttributeViewSet(viewsets.ModelViewSet):
|
class POSClientAttributeViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = pos_models.POSClientAttribute.objects.all()
|
queryset = pos_models.POSClientAttribute.objects.all()
|
||||||
serializer_class = client_serializer.POSClientAttributeSerializer
|
serializer_class = client_serializer.POSClientAttributeSerializer
|
||||||
|
|
||||||
|
|
||||||
class POSClientAttributeValueViewSet(viewsets.ModelViewSet):
|
class POSClientAttributeValueViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = pos_models.POSClientAttributeValue.objects.all()
|
queryset = pos_models.POSClientAttributeValue.objects.all()
|
||||||
serializer_class = client_serializer.POSClientAttributeValueSerializer
|
serializer_class = client_serializer.POSClientAttributeValueSerializer
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from apps.pos_device.web.api.v1.serilaizers import device as device_serializer
|
|||||||
from apps.authentication.exceptions import OrganizationBankAccountException
|
from apps.authentication.exceptions import OrganizationBankAccountException
|
||||||
from apps.authorization.api.v1.serializers import UserRelationSerializer
|
from apps.authorization.api.v1.serializers import UserRelationSerializer
|
||||||
from apps.pos_device.web.api.v1.viewsets.client import POSClientViewSet
|
from apps.pos_device.web.api.v1.viewsets.client import POSClientViewSet
|
||||||
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from apps.authentication.api.v1.api import (
|
from apps.authentication.api.v1.api import (
|
||||||
Organization,
|
Organization,
|
||||||
BankAccountInformation,
|
BankAccountInformation,
|
||||||
@@ -25,7 +26,7 @@ from django.db import transaction
|
|||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
|
|
||||||
class ProviderCompanyViewSet(viewsets.ModelViewSet): # noqa
|
class ProviderCompanyViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
||||||
queryset = pos_models.ProviderCompany.objects.all()
|
queryset = pos_models.ProviderCompany.objects.all()
|
||||||
serializer_class = device_serializer.ProviderCompanySerializer
|
serializer_class = device_serializer.ProviderCompanySerializer
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ class ProviderCompanyViewSet(viewsets.ModelViewSet): # noqa
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class DeviceViewSet(viewsets.ModelViewSet, AdminFilterMixin):
|
class DeviceViewSet(viewsets.ModelViewSet, AdminFilterMixin, SoftDeleteMixin):
|
||||||
queryset = pos_models.Device.objects.all()
|
queryset = pos_models.Device.objects.all()
|
||||||
serializer_class = device_serializer.DeviceSerializer
|
serializer_class = device_serializer.DeviceSerializer
|
||||||
|
|
||||||
@@ -151,17 +152,17 @@ class DeviceViewSet(viewsets.ModelViewSet, AdminFilterMixin):
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class DeviceVersionViewSet(viewsets.ModelViewSet):
|
class DeviceVersionViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = pos_models.DeviceVersion.objects.all()
|
queryset = pos_models.DeviceVersion.objects.all()
|
||||||
serializer_class = device_serializer.DeviceVersionSerializer
|
serializer_class = device_serializer.DeviceVersionSerializer
|
||||||
|
|
||||||
|
|
||||||
class SessionViewSet(viewsets.ModelViewSet): # noqa
|
class SessionViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
||||||
queryset = pos_models.Sessions.objects.all()
|
queryset = pos_models.Sessions.objects.all()
|
||||||
serializer_class = device_serializer.SessionSerializer
|
serializer_class = device_serializer.SessionSerializer
|
||||||
|
|
||||||
|
|
||||||
class DeviceAssignmentViewSet(viewsets.ModelViewSet):
|
class DeviceAssignmentViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = pos_models.DeviceAssignment.objects.all()
|
queryset = pos_models.DeviceAssignment.objects.all()
|
||||||
serializer_class = device_serializer.DeviceAssignmentSerializer
|
serializer_class = device_serializer.DeviceAssignmentSerializer
|
||||||
|
|
||||||
@@ -274,7 +275,7 @@ class DeviceAssignmentViewSet(viewsets.ModelViewSet):
|
|||||||
raise APIException('Non Object Error', code=403)
|
raise APIException('Non Object Error', code=403)
|
||||||
|
|
||||||
|
|
||||||
class StakeHoldersViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
class StakeHoldersViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
||||||
queryset = pos_models.StakeHolders.objects.all()
|
queryset = pos_models.StakeHolders.objects.all()
|
||||||
serializer_class = device_serializer.StakeHoldersSerializer
|
serializer_class = device_serializer.StakeHoldersSerializer
|
||||||
|
|
||||||
@@ -317,3 +318,8 @@ class StakeHoldersViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
|||||||
if page is not None:
|
if page is not None:
|
||||||
serializer = self.get_serializer(page, many=True)
|
serializer = self.get_serializer(page, many=True)
|
||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
|
class BrokerStakeHolderAssignViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
||||||
|
queryset = pos_models.BrokerStakeHolderAssignment.objects.all()
|
||||||
|
serializer_class = device_serializer.BrokerStakeHolderAssignSerializer
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from apps.product.web.api.v1.serializers import product_serializers as product_serializers
|
from apps.product.web.api.v1.serializers import product_serializers as product_serializers
|
||||||
from apps.product.web.api.v1.serializers import quota_serializers
|
from apps.product.web.api.v1.serializers import quota_serializers
|
||||||
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from common.helpers import get_organization_by_user
|
from common.helpers import get_organization_by_user
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
from apps.product import models as product_models
|
from apps.product import models as product_models
|
||||||
@@ -26,7 +27,7 @@ def delete(queryset, pk):
|
|||||||
obj.delete()
|
obj.delete()
|
||||||
|
|
||||||
|
|
||||||
class ProductCategoryViewSet(viewsets.ModelViewSet):
|
class ProductCategoryViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = product_models.ProductCategory.objects.all()
|
queryset = product_models.ProductCategory.objects.all()
|
||||||
serializer_class = product_serializers.ProductCategorySerializer
|
serializer_class = product_serializers.ProductCategorySerializer
|
||||||
filter_backends = [filters.SearchFilter]
|
filter_backends = [filters.SearchFilter]
|
||||||
@@ -64,7 +65,7 @@ class ProductCategoryViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class ProductViewSet(viewsets.ModelViewSet):
|
class ProductViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = product_models.Product.objects.all()
|
queryset = product_models.Product.objects.all()
|
||||||
serializer_class = product_serializers.ProductSerializer
|
serializer_class = product_serializers.ProductSerializer
|
||||||
filter_backends = [filters.SearchFilter]
|
filter_backends = [filters.SearchFilter]
|
||||||
@@ -143,7 +144,7 @@ class ProductViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class ProductStatsViewSet(viewsets.ModelViewSet):
|
class ProductStatsViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" product statistics by its quotas """
|
""" product statistics by its quotas """
|
||||||
|
|
||||||
queryset = product_models.ProductStats.objects.all()
|
queryset = product_models.ProductStats.objects.all()
|
||||||
@@ -174,7 +175,7 @@ class ProductStatsViewSet(viewsets.ModelViewSet):
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
class AttributeViewSet(viewsets.ModelViewSet):
|
class AttributeViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" attributes of reference product """ #
|
""" attributes of reference product """ #
|
||||||
|
|
||||||
queryset = product_models.Attribute.objects.select_related('product').all()
|
queryset = product_models.Attribute.objects.select_related('product').all()
|
||||||
@@ -232,7 +233,7 @@ class AttributeViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class AttributeValueViewSet(viewsets.ModelViewSet):
|
class AttributeValueViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" apis for attribute values of child products """ # noqa
|
""" apis for attribute values of child products """ # noqa
|
||||||
|
|
||||||
queryset = product_models.AttributeValue.objects.all()
|
queryset = product_models.AttributeValue.objects.all()
|
||||||
@@ -270,7 +271,7 @@ class AttributeValueViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class BrokerViewSet(viewsets.ModelViewSet):
|
class BrokerViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" apis of product brokers """ # noqa
|
""" apis of product brokers """ # noqa
|
||||||
|
|
||||||
queryset = product_models.Broker.objects.all()
|
queryset = product_models.Broker.objects.all()
|
||||||
@@ -310,7 +311,7 @@ class BrokerViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class SaleUnitViewSet(viewsets.ModelViewSet):
|
class SaleUnitViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" apis of unit of sale for products """ # noqa
|
""" apis of unit of sale for products """ # noqa
|
||||||
|
|
||||||
queryset = product_models.SaleUnit.objects.all()
|
queryset = product_models.SaleUnit.objects.all()
|
||||||
@@ -350,7 +351,7 @@ class SaleUnitViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class IncentivePlanViewSet(viewsets.ModelViewSet): # noqa
|
class IncentivePlanViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
||||||
""" apis for incentive plan """
|
""" apis for incentive plan """
|
||||||
|
|
||||||
queryset = product_models.IncentivePlan.objects.all()
|
queryset = product_models.IncentivePlan.objects.all()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from apps.product.web.api.v1.serializers import quota_distribution_serializers
|
from apps.product.web.api.v1.serializers import quota_distribution_serializers
|
||||||
from apps.product.services.services import get_products_in_warehouse
|
from apps.product.services.services import get_products_in_warehouse
|
||||||
from apps.product.web.api.v1.serializers import quota_serializers
|
from apps.product.web.api.v1.serializers import quota_serializers
|
||||||
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from apps.product.exceptions import QuotaExpiredTimeException
|
from apps.product.exceptions import QuotaExpiredTimeException
|
||||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||||
from apps.core.pagination import CustomPageNumberPagination
|
from apps.core.pagination import CustomPageNumberPagination
|
||||||
@@ -31,7 +32,7 @@ def delete(queryset, pk):
|
|||||||
obj.delete()
|
obj.delete()
|
||||||
|
|
||||||
|
|
||||||
class QuotaViewSet(viewsets.ModelViewSet, DynamicSearchMixin): # noqa
|
class QuotaViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin): # noqa
|
||||||
""" apis for product quota """
|
""" apis for product quota """
|
||||||
|
|
||||||
queryset = product_models.Quota.objects.all()
|
queryset = product_models.Quota.objects.all()
|
||||||
@@ -453,7 +454,7 @@ class QuotaViewSet(viewsets.ModelViewSet, DynamicSearchMixin): # noqa
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class QuotaIncentiveAssignmentViewSet(viewsets.ModelViewSet): # noqa
|
class QuotaIncentiveAssignmentViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
||||||
""" apis for incentive assignment """
|
""" apis for incentive assignment """
|
||||||
|
|
||||||
queryset = product_models.QuotaIncentiveAssignment.objects.all()
|
queryset = product_models.QuotaIncentiveAssignment.objects.all()
|
||||||
@@ -491,7 +492,7 @@ class QuotaIncentiveAssignmentViewSet(viewsets.ModelViewSet): # noqa
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class QuotaBrokerValueViewSet(viewsets.ModelViewSet): # noqa
|
class QuotaBrokerValueViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
||||||
""" apis for quota broker value """
|
""" apis for quota broker value """
|
||||||
|
|
||||||
queryset = product_models.QuotaBrokerValue.objects.all()
|
queryset = product_models.QuotaBrokerValue.objects.all()
|
||||||
@@ -529,7 +530,7 @@ class QuotaBrokerValueViewSet(viewsets.ModelViewSet): # noqa
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class QuotaLiveStockAllocationViewSet(viewsets.ModelViewSet):
|
class QuotaLiveStockAllocationViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
""" apis for quota livestock allocation """
|
""" apis for quota livestock allocation """
|
||||||
|
|
||||||
queryset = product_models.QuotaLivestockAllocation.objects.all()
|
queryset = product_models.QuotaLivestockAllocation.objects.all()
|
||||||
@@ -567,7 +568,7 @@ class QuotaLiveStockAllocationViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class QuotaLiveStockAgeLimitation(viewsets.ModelViewSet):
|
class QuotaLiveStockAgeLimitation(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = product_models.QuotaLiveStockAgeLimitation.objects.all() # noqa
|
queryset = product_models.QuotaLiveStockAgeLimitation.objects.all() # noqa
|
||||||
serializer_class = quota_serializers.QuotaLiveStockAgeLimitationSerializer
|
serializer_class = quota_serializers.QuotaLiveStockAgeLimitationSerializer
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from apps.product.web.api.v1.serializers import quota_distribution_serializers as distribution_serializers
|
from apps.product.web.api.v1.serializers import quota_distribution_serializers as distribution_serializers
|
||||||
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||||
from apps.core.pagination import CustomPageNumberPagination
|
from apps.core.pagination import CustomPageNumberPagination
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
@@ -26,7 +27,7 @@ def delete(queryset, pk):
|
|||||||
obj.delete()
|
obj.delete()
|
||||||
|
|
||||||
|
|
||||||
class QuotaDistributionViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
class QuotaDistributionViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
||||||
""" quota distribution apis """
|
""" quota distribution apis """
|
||||||
|
|
||||||
queryset = product_models.QuotaDistribution.objects.all()
|
queryset = product_models.QuotaDistribution.objects.all()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from apps.warehouse.web.api.v1 import serializers as warehouse_serializers
|
from apps.warehouse.web.api.v1 import serializers as warehouse_serializers
|
||||||
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||||
from apps.warehouse import models as warehouse_models
|
from apps.warehouse import models as warehouse_models
|
||||||
from common.helpers import get_organization_by_user
|
from common.helpers import get_organization_by_user
|
||||||
@@ -12,7 +13,7 @@ from rest_framework import status
|
|||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
||||||
queryset = warehouse_models.InventoryEntry.objects.all()
|
queryset = warehouse_models.InventoryEntry.objects.all()
|
||||||
serializer_class = warehouse_serializers.InventoryEntrySerializer
|
serializer_class = warehouse_serializers.InventoryEntrySerializer
|
||||||
# filter_backends = [filters.SearchFilter]
|
# filter_backends = [filters.SearchFilter]
|
||||||
@@ -119,7 +120,7 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet):
|
class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||||
queryset = warehouse_models.InventoryQuotaSaleTransaction.objects.all()
|
queryset = warehouse_models.InventoryQuotaSaleTransaction.objects.all()
|
||||||
serializer_class = warehouse_serializers.InventoryQuotaSaleTransactionSerializer
|
serializer_class = warehouse_serializers.InventoryQuotaSaleTransactionSerializer
|
||||||
filter_backends = [filters.SearchFilter]
|
filter_backends = [filters.SearchFilter]
|
||||||
|
|||||||
Reference in New Issue
Block a user