fix-my devices - import new mixin of visible orgs
This commit is contained in:
@@ -3,6 +3,7 @@ VISIBILITY_MAP = {
|
||||
'organization': 'id',
|
||||
'quota': ['registerer_organization', 'assigned_organizations'],
|
||||
'quotastats': ['quota__registerer_organization', 'quota__assigned_organizations'],
|
||||
'productstats': 'organization',
|
||||
'quotadistribution': ['assigner_organization', 'assigned_organization'],
|
||||
'inventoryentry': 'organization',
|
||||
'inventoryquotasaletransaction': 'organization',
|
||||
|
||||
@@ -18,6 +18,7 @@ from apps.authentication.api.v1.api import (
|
||||
from apps.authentication.exceptions import OrganizationBankAccountException
|
||||
from apps.authorization.api.v1.serializers import UserRelationSerializer
|
||||
from apps.authorization.models import UserRelations
|
||||
from apps.core.api import BaseViewSet
|
||||
from apps.core.mixins.admin_mixin import AdminFilterMixin
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||
@@ -65,7 +66,7 @@ class ProviderCompanyViewSet(SoftDeleteMixin, viewsets.ModelViewSet): # noqa
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
class DeviceViewSet(SoftDeleteMixin, viewsets.ModelViewSet, AdminFilterMixin):
|
||||
class DeviceViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, AdminFilterMixin):
|
||||
queryset = pos_models.Device.objects.all()
|
||||
serializer_class = device_serializer.DeviceSerializer
|
||||
|
||||
@@ -94,9 +95,11 @@ class DeviceViewSet(SoftDeleteMixin, viewsets.ModelViewSet, AdminFilterMixin):
|
||||
@transaction.atomic
|
||||
def my_devices(self, request):
|
||||
""" list of company devices """
|
||||
|
||||
organization = get_organization_by_user(request.user)
|
||||
# using admin filter mixin to get query
|
||||
devices = self.get_query(self.queryset)
|
||||
devices = self.get_query(self.get_queryset(
|
||||
visibility_by_org_scope=True
|
||||
) if organization.free_visibility_by_scope else self.get_queryset())
|
||||
|
||||
# paginate devices
|
||||
page = self.paginate_queryset(devices)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.0 on 2025-11-02 12:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0080_quotafinalpricetypes_quotapricecalculationitems'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='historicalquotadistribution',
|
||||
name='description',
|
||||
field=models.TextField(blank=True, max_length=1000, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='quotadistribution',
|
||||
name='description',
|
||||
field=models.TextField(blank=True, max_length=1000, null=True),
|
||||
),
|
||||
]
|
||||
@@ -1,19 +1,21 @@
|
||||
import datetime
|
||||
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.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from common.helpers import get_organization_by_user
|
||||
from rest_framework.exceptions import APIException
|
||||
from apps.product import models as product_models
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework import viewsets, filters
|
||||
from common.tools import CustomOperations
|
||||
from rest_framework import status
|
||||
from datetime import datetime
|
||||
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from datetime import datetime
|
||||
from rest_framework import status
|
||||
from rest_framework import viewsets, filters
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.exceptions import APIException
|
||||
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.product import models as product_models
|
||||
from apps.product.web.api.v1.serializers import product_serializers as product_serializers
|
||||
from apps.product.web.api.v1.serializers import quota_serializers
|
||||
from common.helpers import get_organization_by_user
|
||||
|
||||
|
||||
def trash(queryset, pk): # noqa
|
||||
@@ -146,7 +148,7 @@ class ProductViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin)
|
||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
|
||||
class ProductStatsViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
class ProductStatsViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
""" product statistics by its quotas """
|
||||
|
||||
queryset = product_models.ProductStats.objects.all()
|
||||
@@ -164,9 +166,11 @@ class ProductStatsViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchM
|
||||
|
||||
try:
|
||||
organization = get_organization_by_user(request.user)
|
||||
product_stats = self.queryset.filter(organization=organization).order_by('-modify_date')
|
||||
product_stats = self.get_queryset(
|
||||
visibility_by_org_scope=True
|
||||
) if organization.free_visibility_by_scope else self.get_queryset()
|
||||
|
||||
page = self.paginate_queryset(product_stats) # noqa
|
||||
page = self.paginate_queryset(product_stats.order_by('-modify_date')) # noqa
|
||||
if page is not None:
|
||||
serializer = self.get_serializer(page, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
@@ -690,3 +690,7 @@ AssertionError: .validate() should return the validated data
|
||||
[2025-11-02 15:33:11,579] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\product\web\api\v1\serializers\quota_distribution_serializers.py changed, reloading.
|
||||
[2025-11-02 15:33:14,976] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-11-02 15:42:30,151] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\product\models.py changed, reloading.
|
||||
[2025-11-02 15:42:32,210] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-11-02 16:38:11,296] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\product\web\api\v1\viewsets\product_api.py changed, reloading.
|
||||
[2025-11-02 16:38:16,320] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-11-02 17:05:50,482] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\pos_device\web\api\v1\viewsets\device.py changed, reloading.
|
||||
|
||||
Reference in New Issue
Block a user