fix - transaction & show users with my organization except me

This commit is contained in:
2025-11-01 14:20:27 +03:30
parent 0f6e1ecd28
commit f8320b6e44
4 changed files with 50 additions and 12 deletions

View File

@@ -36,7 +36,9 @@ class BaseViewSet(RegionFilterMixin, viewsets.ModelViewSet):
model_name = queryset.model.__name__.lower() model_name = queryset.model.__name__.lower()
if model_name == 'userrelations': # noqa 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': elif model_name == 'organization':
queryset = queryset.filter(id__in=[org.id for org in child_orgs]) queryset = queryset.filter(id__in=[org.id for org in child_orgs])

View File

@@ -1,12 +1,14 @@
import string
import random import random
import string
from django.db import models
from apps.authentication.models import User, Organization 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.pos_device.models import POSFreeProducts
from apps.product import models as product_models 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): class InventoryEntry(BaseModel):
@@ -130,7 +132,7 @@ class InventoryQuotaSaleTransaction(BaseModel):
@property @property
def total_weight(self): def total_weight(self):
""" summation of total sold product weight """ """ 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): def __str__(self):
return f"Inventory Sale: {self.transaction_id}-{self.quota_distribution.distribution_id}" return f"Inventory Sale: {self.transaction_id}-{self.quota_distribution.distribution_id}"

View File

@@ -6,6 +6,7 @@ from rest_framework import viewsets, filters
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.response import Response from rest_framework.response import Response
from apps.core.api import BaseViewSet
from apps.core.mixins.search_mixin import DynamicSearchMixin from apps.core.mixins.search_mixin import DynamicSearchMixin
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
from apps.warehouse import models as warehouse_models 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) 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() queryset = warehouse_models.InventoryQuotaSaleTransaction.objects.all()
serializer_class = warehouse_serializers.InventoryQuotaSaleTransactionSerializer 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() queryset = warehouse_models.InventoryQuotaSaleItem.objects.all()
serializer_class = warehouse_serializers.InventoryQuotaSaleItemSerializer serializer_class = warehouse_serializers.InventoryQuotaSaleItemSerializer
filter_backends = [filters.SearchFilter] 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',
]

View File

@@ -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: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: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: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.