From b6ef262c33806b93c6b44ddad1dcdcbadc415b1e Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Thu, 7 Aug 2025 14:51:19 +0330 Subject: [PATCH] fix inventory balanve & remaining - import provider name in device serializer --- apps/authentication/api/v1/api.py | 6 ++++++ apps/authorization/api/v1/api.py | 6 ++++++ apps/pos_device/web/api/v1/serilaizers/device.py | 8 ++++++++ apps/product/signals.py | 8 +++++++- apps/warehouse/signals.py | 1 + 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/authentication/api/v1/api.py b/apps/authentication/api/v1/api.py index 762641b..e114baf 100644 --- a/apps/authentication/api/v1/api.py +++ b/apps/authentication/api/v1/api.py @@ -218,6 +218,12 @@ class OrganizationViewSet(ModelViewSet, DynamicSearchMixin): descendants.extend(self.get_all_org_child(child)) return descendants + def list(self, request, *args, **kwargs): + """ all organization """ + + serializer = self.serializer_class(self.queryset.order_by('-create_date'), many=True) + return Response(serializer.data, status=status.HTTP_200_OK) + @transaction.atomic def create(self, request, *args, **kwargs): """ diff --git a/apps/authorization/api/v1/api.py b/apps/authorization/api/v1/api.py index 1687864..7490e39 100644 --- a/apps/authorization/api/v1/api.py +++ b/apps/authorization/api/v1/api.py @@ -38,6 +38,12 @@ class PageViewSet(viewsets.ModelViewSet): filter_backends = [filters.SearchFilter] search_fields = ['name', 'code'] + def list(self, request, *args, **kwargs): + """ all pages """ + + serializer = self.serializer_class(self.queryset.order_by('-create_date'), many=True) + return Response(serializer.data, status=status.HTTP_200_OK) + @action( methods=['delete'], detail=True, diff --git a/apps/pos_device/web/api/v1/serilaizers/device.py b/apps/pos_device/web/api/v1/serilaizers/device.py index e97102b..56013ed 100644 --- a/apps/pos_device/web/api/v1/serilaizers/device.py +++ b/apps/pos_device/web/api/v1/serilaizers/device.py @@ -13,6 +13,14 @@ class DeviceSerializer(ModelSerializer): model = pos_models.Device fields = '__all__' + def to_representation(self, instance): + """ custom output of serializer """ + representation = super().to_representation(instance) + + representation['company'] = {'name': instance.company.name_fa} + + return representation + class DeviceVersionSerializer(ModelSerializer): class Meta: diff --git a/apps/product/signals.py b/apps/product/signals.py index de5fdf5..e97061f 100644 --- a/apps/product/signals.py +++ b/apps/product/signals.py @@ -35,7 +35,13 @@ def remaining_distribution_weight(instance: QuotaDistribution): total_children_weight = instance.children.aggregate( total=Sum('weight') )['total'] or 0 - instance.remaining_weight = instance.weight - total_children_weight + + # total warehouse inventory entry + total_entry = instance.inventory_entry.aggregate( + total=Sum('weight') + )['total'] or 0 + + instance.remaining_weight = instance.weight - total_children_weight - total_entry instance.distributed = total_children_weight instance._from_signal = True instance.save(update_fields=['remaining_weight', 'distributed']) diff --git a/apps/warehouse/signals.py b/apps/warehouse/signals.py index 725d2eb..95692df 100644 --- a/apps/warehouse/signals.py +++ b/apps/warehouse/signals.py @@ -28,6 +28,7 @@ def warehouse_sold_and_balance(quota_distribution): @receiver(post_delete, sender=InventoryEntry) def update_distribution_warehouse_entry(sender, instance, **kwargs): calculate_warehouse_entry(instance.distribution) + warehouse_sold_and_balance(instance.distribution) @receiver(post_save, sender=InventoryQuotaSaleTransaction)