From f8320b6e4412dfe039e7338e7a190d69cb748da8 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sat, 1 Nov 2025 14:20:27 +0330 Subject: [PATCH] fix - transaction & show users with my organization except me --- apps/core/api.py | 4 +++- apps/warehouse/models.py | 14 +++++++------ apps/warehouse/web/api/v1/api.py | 36 +++++++++++++++++++++++++++----- logs/django_requests.log | 8 +++++++ 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/apps/core/api.py b/apps/core/api.py index 76ece9b..22e3a4e 100644 --- a/apps/core/api.py +++ b/apps/core/api.py @@ -36,7 +36,9 @@ class BaseViewSet(RegionFilterMixin, viewsets.ModelViewSet): model_name = queryset.model.__name__.lower() if model_name == 'userrelations': # noqa - queryset = (queryset.filter(organization__in=child_orgs)) + # add all users with my organization except my user + child_orgs.append(org) + queryset = (queryset.filter(organization__in=child_orgs).exclude(user=user)) elif model_name == 'organization': queryset = queryset.filter(id__in=[org.id for org in child_orgs]) diff --git a/apps/warehouse/models.py b/apps/warehouse/models.py index 6cb9964..1b8fa81 100644 --- a/apps/warehouse/models.py +++ b/apps/warehouse/models.py @@ -1,12 +1,14 @@ -import string import random +import string + +from django.db import models + from apps.authentication.models import User, Organization +from apps.core.models import BaseModel +from apps.herd.models import Rancher +from apps.pos_device.models import Device from apps.pos_device.models import POSFreeProducts from apps.product import models as product_models -from apps.pos_device.models import Device -from apps.herd.models import Rancher -from apps.core.models import BaseModel -from django.db import models class InventoryEntry(BaseModel): @@ -130,7 +132,7 @@ class InventoryQuotaSaleTransaction(BaseModel): @property def total_weight(self): """ summation of total sold product weight """ - return sum(item.weight for item in self.items.all) + return sum(item.weight for item in self.items.all) # noqa def __str__(self): return f"Inventory Sale: {self.transaction_id}-{self.quota_distribution.distribution_id}" diff --git a/apps/warehouse/web/api/v1/api.py b/apps/warehouse/web/api/v1/api.py index e3fc351..6bbbe2e 100644 --- a/apps/warehouse/web/api/v1/api.py +++ b/apps/warehouse/web/api/v1/api.py @@ -6,6 +6,7 @@ from rest_framework import viewsets, filters from rest_framework.decorators import action from rest_framework.response import Response +from apps.core.api import BaseViewSet 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 @@ -124,15 +125,40 @@ class InventoryEntryViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearc return self.get_paginated_response(serializer.data) -class InventoryQuotaSaleTransactionViewSet(SoftDeleteMixin, viewsets.ModelViewSet): +class InventoryQuotaSaleTransactionViewSet(SoftDeleteMixin, DynamicSearchMixin, BaseViewSet, viewsets.ModelViewSet): queryset = warehouse_models.InventoryQuotaSaleTransaction.objects.all() serializer_class = warehouse_serializers.InventoryQuotaSaleTransactionSerializer - filter_backends = [filters.SearchFilter] - search_fields = [''] + search_fields = [ + 'rancher_fullname', 'rancher_mobile', 'pos_device__device_identity', + 'pos_device__acceptor', 'pos_device__terminal', 'pos_device__serial', + 'items__gov_product__name', 'items__free_product__name', 'items__name', + 'items__item_type', 'items__unit', 'transaction_id', 'seller_organization__name', + 'quota_distribution__distribution_id', 'weight', 'delivery_address', 'transaction_price', + 'price_paid', 'price_type', 'product_type', 'transactions_number', 'transaction_status', + 'transaction_status_code', 'ref_num', 'terminal', 'payer_cart', 'transaction_date', + ] + + def list(self, request, *args, **kwargs): + """ + list of transactions + filter by: search, all, my_transactions + """ + queryset = self.filter_query(self.get_queryset()) -class InventoryQuotaSaleItemViewSet(SoftDeleteMixin, viewsets.ModelViewSet): +class InventoryQuotaSaleItemViewSet(SoftDeleteMixin, BaseViewSet, viewsets.ModelViewSet): queryset = warehouse_models.InventoryQuotaSaleItem.objects.all() serializer_class = warehouse_serializers.InventoryQuotaSaleItemSerializer filter_backends = [filters.SearchFilter] - search_fields = [''] + search_fields = [ + 'transaction', + 'quota_distribution', + 'gov_product', + 'free_product', + 'name', + 'price_type', + 'delivery_type', + 'paid_type', + 'item_type', + 'unit', + ] diff --git a/logs/django_requests.log b/logs/django_requests.log index 183252c..012f1e2 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -623,3 +623,11 @@ AssertionError: .validate() should return the validated data [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. +[2025-11-01 11:45:12,204] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-01 12:31:40,159] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\warehouse\models.py changed, reloading. +[2025-11-01 12:31:42,342] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-01 12:31:50,362] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\warehouse\web\api\v1\api.py changed, reloading. +[2025-11-01 12:31:52,452] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-01 13:57:55,398] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\warehouse\web\api\v1\api.py changed, reloading. +[2025-11-01 13:58:02,091] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-01 14:19:59,373] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\core\api.py changed, reloading.