From 0f6e1ecd28cdb35228169a4a78bca732e99b3beb Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sat, 1 Nov 2025 11:45:56 +0330 Subject: [PATCH] fix - permission search by name & some view(serializer) of transaction --- apps/authorization/api/v1/api.py | 2 +- apps/warehouse/web/api/v1/api.py | 32 ++++++++++++------- apps/warehouse/web/api/v1/serializers.py | 40 ++++++------------------ logs/django_requests.log | 5 +++ 4 files changed, 36 insertions(+), 43 deletions(-) diff --git a/apps/authorization/api/v1/api.py b/apps/authorization/api/v1/api.py index 0dd04cb..0b0d567 100644 --- a/apps/authorization/api/v1/api.py +++ b/apps/authorization/api/v1/api.py @@ -94,7 +94,7 @@ class PermissionViewSet(SoftDeleteMixin, viewsets.ModelViewSet): queryset = Permissions.objects.all() serializer_class = PermissionSerializer filter_backends = [filters.SearchFilter] - search_fields = ['page__name', ] + search_fields = ['page__name', 'name'] def list(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset().order_by('-modify_date')) # noqa diff --git a/apps/warehouse/web/api/v1/api.py b/apps/warehouse/web/api/v1/api.py index 0d22072..e3fc351 100644 --- a/apps/warehouse/web/api/v1/api.py +++ b/apps/warehouse/web/api/v1/api.py @@ -1,17 +1,18 @@ -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.warehouse import models as warehouse_models -from common.helpers import get_organization_by_user -from apps.notification.models import Notification -from common.generics import base64_to_image_file -from common.liara_tools import upload_to_liara -from rest_framework.decorators import action -from rest_framework.response import Response -from rest_framework import viewsets, filters +import typing + from django.db import transaction from rest_framework import status -import typing +from rest_framework import viewsets, filters +from rest_framework.decorators import action +from rest_framework.response import Response + +from apps.core.mixins.search_mixin import DynamicSearchMixin +from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin +from apps.warehouse import models as warehouse_models +from apps.warehouse.web.api.v1 import serializers as warehouse_serializers +from common.generics import base64_to_image_file +from common.helpers import get_organization_by_user +from common.liara_tools import upload_to_liara class InventoryEntryViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin): @@ -128,3 +129,10 @@ class InventoryQuotaSaleTransactionViewSet(SoftDeleteMixin, viewsets.ModelViewSe serializer_class = warehouse_serializers.InventoryQuotaSaleTransactionSerializer filter_backends = [filters.SearchFilter] search_fields = [''] + + +class InventoryQuotaSaleItemViewSet(SoftDeleteMixin, viewsets.ModelViewSet): + queryset = warehouse_models.InventoryQuotaSaleItem.objects.all() + serializer_class = warehouse_serializers.InventoryQuotaSaleItemSerializer + filter_backends = [filters.SearchFilter] + search_fields = [''] diff --git a/apps/warehouse/web/api/v1/serializers.py b/apps/warehouse/web/api/v1/serializers.py index d6907b5..118f0fc 100644 --- a/apps/warehouse/web/api/v1/serializers.py +++ b/apps/warehouse/web/api/v1/serializers.py @@ -1,12 +1,11 @@ -from apps.warehouse.exceptions import ( - InventoryEntryWeightException, - TotalInventorySaleException -) +from django.db import models +from rest_framework import serializers + from apps.product.exceptions import QuotaExpiredTimeException from apps.warehouse import models as warehouse_models -from apps.authorization.models import UserRelations -from rest_framework import serializers -from django.db import models +from apps.warehouse.exceptions import ( + InventoryEntryWeightException +) class InventoryEntrySerializer(serializers.ModelSerializer): @@ -91,29 +90,10 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer): inventory_entry = attrs['inventory_entry'] distribution = attrs['quota_distribution'] - total_sale_weight = inventory_entry.inventory_sales.aggregate( - total=models.Sum('weight') - )['total'] or 0 - - if total_sale_weight + attrs['weight'] > distribution.warehouse_balance: - raise TotalInventorySaleException() - return attrs - def create(self, validated_data): - """ Custom create & set some parameters like seller & buyer """ - - distribution = validated_data['quota_distribution'] - seller_organization = distribution.assigned_organization - - user = self.context['request'].user - buyer_user = user - seller_user = validated_data['inventory_entry'].created_by - - return warehouse_models.InventoryQuotaSaleTransaction.objects.create( - seller_organization=seller_organization, - seller_user=seller_user, - buyer_user=buyer_user, - **validated_data - ) +class InventoryQuotaSaleItemSerializer(serializers.ModelSerializer): + class Meta: + model = warehouse_models.InventoryQuotaSaleItem + fields = '__all__' diff --git a/logs/django_requests.log b/logs/django_requests.log index 9a633ad..183252c 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -618,3 +618,8 @@ AssertionError: .validate() should return the validated data [2025-11-01 11:23:37,709] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/page/?search=pos_accouns HTTP/1.1" 200 581 [2025-11-01 11:25:55,672] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\api.py changed, reloading. [2025-11-01 11:25:58,353] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-01 11:36:23,914] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\api.py changed, reloading. +[2025-11-01 11:36:30,200] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-01 11:43:40,398] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\warehouse\web\api\v1\serializers.py changed, reloading. +[2025-11-01 11:43:42,806] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-01 11:45:10,527] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\warehouse\web\api\v1\api.py changed, reloading.