rancher incentive quota usage - pos product search
This commit is contained in:
@@ -46,7 +46,7 @@ class CustomizedTokenObtainPairView(TokenObtainPairView):
|
|||||||
serializer_class = CustomizedTokenObtainPairSerializer
|
serializer_class = CustomizedTokenObtainPairSerializer
|
||||||
|
|
||||||
|
|
||||||
class UserViewSet(ModelViewSet, SoftDeleteMixin):
|
class UserViewSet(SoftDeleteMixin, ModelViewSet):
|
||||||
""" Crud operations for user model """
|
""" Crud operations for user model """
|
||||||
queryset = User.objects.all()
|
queryset = User.objects.all()
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
@@ -168,7 +168,7 @@ class UserViewSet(ModelViewSet, SoftDeleteMixin):
|
|||||||
return Response(serializer.data, status.HTTP_200_OK)
|
return Response(serializer.data, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class CityViewSet(ModelViewSet, SoftDeleteMixin):
|
class CityViewSet(SoftDeleteMixin, ModelViewSet):
|
||||||
""" Crud operations for city model """ #
|
""" Crud operations for city model """ #
|
||||||
queryset = City.objects.all()
|
queryset = City.objects.all()
|
||||||
serializer_class = CitySerializer
|
serializer_class = CitySerializer
|
||||||
@@ -184,19 +184,19 @@ class CityViewSet(ModelViewSet, SoftDeleteMixin):
|
|||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class ProvinceViewSet(ModelViewSet, SoftDeleteMixin):
|
class ProvinceViewSet(SoftDeleteMixin, ModelViewSet):
|
||||||
""" 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, SoftDeleteMixin):
|
class OrganizationTypeViewSet(SoftDeleteMixin, ModelViewSet):
|
||||||
""" 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, SoftDeleteMixin):
|
class OrganizationViewSet(SoftDeleteMixin, ModelViewSet, DynamicSearchMixin):
|
||||||
""" Crud operations for organization model """ #
|
""" Crud operations for organization model """ #
|
||||||
queryset = Organization.objects.all()
|
queryset = Organization.objects.all()
|
||||||
serializer_class = OrganizationSerializer
|
serializer_class = OrganizationSerializer
|
||||||
@@ -337,7 +337,7 @@ class OrganizationViewSet(ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class BankAccountViewSet(ModelViewSet, SoftDeleteMixin):
|
class BankAccountViewSet(SoftDeleteMixin, ModelViewSet):
|
||||||
""" 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
|
||||||
@@ -358,7 +358,7 @@ class BankAccountViewSet(ModelViewSet, SoftDeleteMixin):
|
|||||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
|
|
||||||
class GeneralOTPViewSet(ModelViewSet, SoftDeleteMixin):
|
class GeneralOTPViewSet(SoftDeleteMixin, ModelViewSet):
|
||||||
""" general OTP user authorization """
|
""" general OTP user authorization """
|
||||||
|
|
||||||
user_relations_queryset = authorize_view.UserRelations.objects.all()
|
user_relations_queryset = authorize_view.UserRelations.objects.all()
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ from rest_framework import filters
|
|||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
|
|
||||||
class RoleViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
class RoleViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
""" 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, SoftDeleteMixin):
|
class PageViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
""" 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()
|
||||||
@@ -67,7 +67,7 @@ class PageViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class PermissionViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
class PermissionViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
""" Crud Operations for Permissions """
|
""" Crud Operations for Permissions """
|
||||||
|
|
||||||
queryset = Permissions.objects.all()
|
queryset = Permissions.objects.all()
|
||||||
@@ -97,7 +97,7 @@ class PermissionViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
|||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
class UserRelationViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
class UserRelationViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
""" Crud Operations for User Relations """
|
""" Crud Operations for User Relations """
|
||||||
|
|
||||||
queryset = UserRelations.objects.all()
|
queryset = UserRelations.objects.all()
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ class SoftDeleteMixin:
|
|||||||
""" override destroy -> soft delete """
|
""" override destroy -> soft delete """
|
||||||
|
|
||||||
instance = self.get_object() # noqa
|
instance = self.get_object() # noqa
|
||||||
|
print("soft delete mixin")
|
||||||
instance.soft_delete()
|
instance.soft_delete()
|
||||||
return Response(
|
return Response(
|
||||||
{"detail": "رکورد با موفقیت حذف شد (Soft Delete)."}, # noqa
|
{"detail": "رکورد با موفقیت حذف شد (Soft Delete)."}, # noqa
|
||||||
status=status.HTTP_200_OK
|
status=status.HTTP_204_NO_CONTENT
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from rest_framework import viewsets
|
|||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
|
|
||||||
class POSClientViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
class POSClientViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
queryset = pos_models.POSClient.objects.all()
|
queryset = pos_models.POSClient.objects.all()
|
||||||
serializer_class = client_serializer.POSClientSerializer
|
serializer_class = client_serializer.POSClientSerializer
|
||||||
|
|
||||||
@@ -60,11 +60,11 @@ class POSClientViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
|||||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
|
|
||||||
class POSClientAttributeViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
class POSClientAttributeViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
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, SoftDeleteMixin):
|
class POSClientAttributeValueViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
queryset = pos_models.POSClientAttributeValue.objects.all()
|
queryset = pos_models.POSClientAttributeValue.objects.all()
|
||||||
serializer_class = client_serializer.POSClientAttributeValueSerializer
|
serializer_class = client_serializer.POSClientAttributeValueSerializer
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from django.db import transaction
|
|||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
|
|
||||||
class ProviderCompanyViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
class ProviderCompanyViewSet(SoftDeleteMixin, viewsets.ModelViewSet): # noqa
|
||||||
queryset = pos_models.ProviderCompany.objects.all()
|
queryset = pos_models.ProviderCompany.objects.all()
|
||||||
serializer_class = device_serializer.ProviderCompanySerializer
|
serializer_class = device_serializer.ProviderCompanySerializer
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ class ProviderCompanyViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class DeviceViewSet(viewsets.ModelViewSet, AdminFilterMixin, SoftDeleteMixin):
|
class DeviceViewSet(SoftDeleteMixin, viewsets.ModelViewSet, AdminFilterMixin):
|
||||||
queryset = pos_models.Device.objects.all()
|
queryset = pos_models.Device.objects.all()
|
||||||
serializer_class = device_serializer.DeviceSerializer
|
serializer_class = device_serializer.DeviceSerializer
|
||||||
|
|
||||||
@@ -154,17 +154,17 @@ class DeviceViewSet(viewsets.ModelViewSet, AdminFilterMixin, SoftDeleteMixin):
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class DeviceVersionViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
class DeviceVersionViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
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, SoftDeleteMixin): # noqa
|
class SessionViewSet(SoftDeleteMixin, viewsets.ModelViewSet): # 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, SoftDeleteMixin):
|
class DeviceAssignmentViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
queryset = pos_models.DeviceAssignment.objects.all()
|
queryset = pos_models.DeviceAssignment.objects.all()
|
||||||
serializer_class = device_serializer.DeviceAssignmentSerializer
|
serializer_class = device_serializer.DeviceAssignmentSerializer
|
||||||
|
|
||||||
@@ -293,7 +293,7 @@ class DeviceAssignmentViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
|||||||
raise APIException('Non Object Error', code=403)
|
raise APIException('Non Object Error', code=403)
|
||||||
|
|
||||||
|
|
||||||
class StakeHoldersViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
class StakeHoldersViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
queryset = pos_models.StakeHolders.objects.all()
|
queryset = pos_models.StakeHolders.objects.all()
|
||||||
serializer_class = device_serializer.StakeHoldersSerializer
|
serializer_class = device_serializer.StakeHoldersSerializer
|
||||||
|
|
||||||
@@ -361,7 +361,7 @@ class StakeHoldersViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteM
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class StakeHolderShareAmountViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
class StakeHolderShareAmountViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
queryset = pos_models.StakeHolderShareAmount.objects.select_related('quota_distribution', 'stakeholders')
|
queryset = pos_models.StakeHolderShareAmount.objects.select_related('quota_distribution', 'stakeholders')
|
||||||
serializer_class = device_serializer.StakeHolderShareAmountSerializer
|
serializer_class = device_serializer.StakeHolderShareAmountSerializer
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-09-27 05:20
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('product', '0078_quotausage'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='quotausage',
|
||||||
|
name='distribution',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='usages', to='product.quotadistribution'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='quotausage',
|
||||||
|
name='usage_type',
|
||||||
|
field=models.CharField(choices=[('base', 'BASE'), ('incentive', 'INCENTIVE')], max_length=150, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='quotausage',
|
||||||
|
name='base_quota_used',
|
||||||
|
field=models.IntegerField(default=0),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='quotausage',
|
||||||
|
name='incentive_quota_used',
|
||||||
|
field=models.IntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -494,8 +494,8 @@ class QuotaUsage(BaseModel):
|
|||||||
on_delete=models.SET_NULL
|
on_delete=models.SET_NULL
|
||||||
)
|
)
|
||||||
count = models.PositiveIntegerField()
|
count = models.PositiveIntegerField()
|
||||||
base_quota_used = models.DecimalField(max_digits=12, decimal_places=2, default=0)
|
base_quota_used = models.IntegerField(default=0)
|
||||||
incentive_quota_used = models.DecimalField(max_digits=12, decimal_places=2, default=0)
|
incentive_quota_used = models.IntegerField(default=0)
|
||||||
usage_type_choices = (
|
usage_type_choices = (
|
||||||
('base', 'BASE'),
|
('base', 'BASE'),
|
||||||
('incentive', 'INCENTIVE'),
|
('incentive', 'INCENTIVE'),
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class ProductViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDeviceMixin):
|
|||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
|
|
||||||
queryset = self.filter_query(self.get_queryset().order_by('-create_date')) # noqa
|
queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) # noqa
|
||||||
|
|
||||||
page = self.paginate_queryset(queryset)
|
page = self.paginate_queryset(queryset)
|
||||||
if page is not None:
|
if page is not None:
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ def delete(queryset, pk):
|
|||||||
obj.delete()
|
obj.delete()
|
||||||
|
|
||||||
|
|
||||||
class ProductCategoryViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin):
|
class ProductCategoryViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
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]
|
||||||
@@ -67,7 +67,7 @@ class ProductCategoryViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSear
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class ProductViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin):
|
class ProductViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
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]
|
||||||
@@ -146,7 +146,7 @@ class ProductViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin)
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class ProductStatsViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin):
|
class ProductStatsViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
""" product statistics by its quotas """
|
""" product statistics by its quotas """
|
||||||
|
|
||||||
queryset = product_models.ProductStats.objects.all()
|
queryset = product_models.ProductStats.objects.all()
|
||||||
@@ -177,7 +177,7 @@ class ProductStatsViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchM
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
class AttributeViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin):
|
class AttributeViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
""" 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()
|
||||||
@@ -235,7 +235,7 @@ class AttributeViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixi
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class AttributeValueViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin):
|
class AttributeValueViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
""" 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()
|
||||||
@@ -273,7 +273,7 @@ class AttributeValueViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearc
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class BrokerViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin):
|
class BrokerViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
""" apis of product brokers """ # noqa
|
""" apis of product brokers """ # noqa
|
||||||
|
|
||||||
queryset = product_models.Broker.objects.all()
|
queryset = product_models.Broker.objects.all()
|
||||||
@@ -313,7 +313,7 @@ class BrokerViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class SaleUnitViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin):
|
class SaleUnitViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
""" 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()
|
||||||
@@ -353,7 +353,7 @@ class SaleUnitViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class IncentivePlanViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin): # noqa
|
class IncentivePlanViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin): # noqa
|
||||||
""" apis for incentive plan """
|
""" apis for incentive plan """
|
||||||
|
|
||||||
queryset = product_models.IncentivePlan.objects.all()
|
queryset = product_models.IncentivePlan.objects.all()
|
||||||
@@ -443,7 +443,7 @@ class IncentivePlanViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearch
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class IncentivePlanRancherViewSet(viewsets.ModelViewSet, SoftDeleteMixin, DynamicSearchMixin):
|
class IncentivePlanRancherViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
queryset = product_models.IncentivePlanRancher.objects.all()
|
queryset = product_models.IncentivePlanRancher.objects.all()
|
||||||
serializer_class = product_serializers.IncentivePlanRancherSerializer
|
serializer_class = product_serializers.IncentivePlanRancherSerializer
|
||||||
search_fields = []
|
search_fields = []
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ def delete(queryset, pk):
|
|||||||
obj.delete()
|
obj.delete()
|
||||||
|
|
||||||
|
|
||||||
class QuotaViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin): # noqa
|
class QuotaViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin): # noqa
|
||||||
""" apis for product quota """
|
""" apis for product quota """
|
||||||
|
|
||||||
queryset = product_models.Quota.objects.all()
|
queryset = product_models.Quota.objects.all()
|
||||||
@@ -454,7 +454,7 @@ class QuotaViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class QuotaIncentiveAssignmentViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
class QuotaIncentiveAssignmentViewSet(SoftDeleteMixin, viewsets.ModelViewSet): # noqa
|
||||||
""" apis for incentive assignment """
|
""" apis for incentive assignment """
|
||||||
|
|
||||||
queryset = product_models.QuotaIncentiveAssignment.objects.all()
|
queryset = product_models.QuotaIncentiveAssignment.objects.all()
|
||||||
@@ -492,7 +492,7 @@ class QuotaIncentiveAssignmentViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class QuotaBrokerValueViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
class QuotaBrokerValueViewSet(SoftDeleteMixin, viewsets.ModelViewSet): # noqa
|
||||||
""" apis for quota broker value """
|
""" apis for quota broker value """
|
||||||
|
|
||||||
queryset = product_models.QuotaBrokerValue.objects.all()
|
queryset = product_models.QuotaBrokerValue.objects.all()
|
||||||
@@ -530,7 +530,7 @@ class QuotaBrokerValueViewSet(viewsets.ModelViewSet, SoftDeleteMixin): # noqa
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class QuotaLiveStockAllocationViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
class QuotaLiveStockAllocationViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
""" apis for quota livestock allocation """
|
""" apis for quota livestock allocation """
|
||||||
|
|
||||||
queryset = product_models.QuotaLivestockAllocation.objects.all()
|
queryset = product_models.QuotaLivestockAllocation.objects.all()
|
||||||
@@ -568,7 +568,7 @@ class QuotaLiveStockAllocationViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class QuotaLiveStockAgeLimitation(viewsets.ModelViewSet, SoftDeleteMixin):
|
class QuotaLiveStockAgeLimitation(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
queryset = product_models.QuotaLiveStockAgeLimitation.objects.all() # noqa
|
queryset = product_models.QuotaLiveStockAgeLimitation.objects.all() # noqa
|
||||||
serializer_class = quota_serializers.QuotaLiveStockAgeLimitationSerializer
|
serializer_class = quota_serializers.QuotaLiveStockAgeLimitationSerializer
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ def delete(queryset, pk):
|
|||||||
obj.delete()
|
obj.delete()
|
||||||
|
|
||||||
|
|
||||||
class QuotaDistributionViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
class QuotaDistributionViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
""" quota distribution apis """
|
""" quota distribution apis """
|
||||||
|
|
||||||
queryset = product_models.QuotaDistribution.objects.all()
|
queryset = product_models.QuotaDistribution.objects.all()
|
||||||
|
|||||||
@@ -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.tag import models as tag_models
|
from apps.tag import models as tag_models
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
@@ -34,7 +35,7 @@ def delete(queryset, pk):
|
|||||||
obj.delete()
|
obj.delete()
|
||||||
|
|
||||||
|
|
||||||
class TagViewSet(viewsets.ModelViewSet):
|
class TagViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
""" Tag View Set """
|
""" Tag View Set """
|
||||||
queryset = tag_models.Tag.objects.all()
|
queryset = tag_models.Tag.objects.all()
|
||||||
serializer_class = TagSerializer
|
serializer_class = TagSerializer
|
||||||
@@ -108,7 +109,7 @@ class TagViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class TagAssignmentViewSet(viewsets.ModelViewSet):
|
class TagAssignmentViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
""" assignment of tags """
|
""" assignment of tags """
|
||||||
queryset = tag_models.TagAssignment.objects.all()
|
queryset = tag_models.TagAssignment.objects.all()
|
||||||
user_relations_queryset = authorize_models.UserRelations.objects.all()
|
user_relations_queryset = authorize_models.UserRelations.objects.all()
|
||||||
@@ -270,7 +271,7 @@ class TagAssignmentViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class AllocatedTagsViewSet(viewsets.ModelViewSet):
|
class AllocatedTagsViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
queryset = tag_models.AllocatedTags.objects.all()
|
queryset = tag_models.AllocatedTags.objects.all()
|
||||||
serializer_class = AllocatedTagsSerializer
|
serializer_class = AllocatedTagsSerializer
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ from apps.warehouse.services.services import (
|
|||||||
create_pre_sale
|
create_pre_sale
|
||||||
)
|
)
|
||||||
from apps.herd.pos.api.v1.serializers import RancherSerializer
|
from apps.herd.pos.api.v1.serializers import RancherSerializer
|
||||||
from apps.product.models import QuotaDistribution, Product
|
from apps.product.models import QuotaDistribution, Product, QuotaUsage
|
||||||
from apps.warehouse import models as warehouse_models
|
from apps.warehouse import models as warehouse_models
|
||||||
|
from apps.livestock.models import LiveStockType
|
||||||
from apps.core.models import SystemConfig
|
from apps.core.models import SystemConfig
|
||||||
from django.db.transaction import atomic
|
from django.db.transaction import atomic
|
||||||
from apps.warehouse.exceptions import (
|
from apps.warehouse.exceptions import (
|
||||||
@@ -165,6 +166,44 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
|||||||
# create pre sale for distribution
|
# create pre sale for distribution
|
||||||
create_pre_sale(transaction=transaction, sale_item=item)
|
create_pre_sale(transaction=transaction, sale_item=item)
|
||||||
|
|
||||||
|
# # purchase quota usage of rancher
|
||||||
|
# if 'livestock_statistic' in item_data.keys():
|
||||||
|
# for item in item_data['livestock_statistic']:
|
||||||
|
# # get livestock by en name
|
||||||
|
# livestock_type = LiveStockType.objects.get(en_name=item['name'])
|
||||||
|
# # get usage & calculate
|
||||||
|
# usage = QuotaUsage.objects.filter(
|
||||||
|
# incentive_plan=item['id'],
|
||||||
|
# rancher=rancher,
|
||||||
|
# livestock_type=livestock_type,
|
||||||
|
# distribution=distribution
|
||||||
|
# )
|
||||||
|
# if not usage.exists():
|
||||||
|
# usage = QuotaUsage(
|
||||||
|
# rancher=rancher,
|
||||||
|
# livestock_type=livestock_type,
|
||||||
|
# distribution=distribution,
|
||||||
|
# count=item['count'],
|
||||||
|
# )
|
||||||
|
# if item['id'] != 0: # if id != 0 it means using his incentive plan
|
||||||
|
# usage.incentive_plan = item['id'],
|
||||||
|
# usage.incentive_quota_used = item['total_weight'],
|
||||||
|
# usage.usage_type = 'incentive'
|
||||||
|
# usage.save()
|
||||||
|
# else:
|
||||||
|
# usage.incentive_plan = None
|
||||||
|
# usage.base_quota_used = item['total_weight'],
|
||||||
|
# usage.usage_type = 'base'
|
||||||
|
# usage.save()
|
||||||
|
# else:
|
||||||
|
# usage = usage.first()
|
||||||
|
# if usage.usage_type == 'incentive':
|
||||||
|
# usage.incentive_quota_used += item['total_weight']
|
||||||
|
# usage.save()
|
||||||
|
# elif usage.usage_type == 'base':
|
||||||
|
# usage.base_quota_used = item['total_weight']
|
||||||
|
# usage.save()
|
||||||
|
|
||||||
transaction.transaction_price = total_price
|
transaction.transaction_price = total_price
|
||||||
transaction.save()
|
transaction.save()
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from rest_framework import status
|
|||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
class InventoryEntryViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
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]
|
||||||
@@ -120,7 +120,7 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDelet
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
class InventoryQuotaSaleTransactionViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||||
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