fix inventory balanve & remaining - import provider name in device serializer
This commit is contained in:
@@ -218,6 +218,12 @@ class OrganizationViewSet(ModelViewSet, DynamicSearchMixin):
|
|||||||
descendants.extend(self.get_all_org_child(child))
|
descendants.extend(self.get_all_org_child(child))
|
||||||
return descendants
|
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
|
@transaction.atomic
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ class PageViewSet(viewsets.ModelViewSet):
|
|||||||
filter_backends = [filters.SearchFilter]
|
filter_backends = [filters.SearchFilter]
|
||||||
search_fields = ['name', 'code']
|
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(
|
@action(
|
||||||
methods=['delete'],
|
methods=['delete'],
|
||||||
detail=True,
|
detail=True,
|
||||||
|
|||||||
@@ -13,6 +13,14 @@ class DeviceSerializer(ModelSerializer):
|
|||||||
model = pos_models.Device
|
model = pos_models.Device
|
||||||
fields = '__all__'
|
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 DeviceVersionSerializer(ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -35,7 +35,13 @@ def remaining_distribution_weight(instance: QuotaDistribution):
|
|||||||
total_children_weight = instance.children.aggregate(
|
total_children_weight = instance.children.aggregate(
|
||||||
total=Sum('weight')
|
total=Sum('weight')
|
||||||
)['total'] or 0
|
)['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.distributed = total_children_weight
|
||||||
instance._from_signal = True
|
instance._from_signal = True
|
||||||
instance.save(update_fields=['remaining_weight', 'distributed'])
|
instance.save(update_fields=['remaining_weight', 'distributed'])
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ def warehouse_sold_and_balance(quota_distribution):
|
|||||||
@receiver(post_delete, sender=InventoryEntry)
|
@receiver(post_delete, sender=InventoryEntry)
|
||||||
def update_distribution_warehouse_entry(sender, instance, **kwargs):
|
def update_distribution_warehouse_entry(sender, instance, **kwargs):
|
||||||
calculate_warehouse_entry(instance.distribution)
|
calculate_warehouse_entry(instance.distribution)
|
||||||
|
warehouse_sold_and_balance(instance.distribution)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=InventoryQuotaSaleTransaction)
|
@receiver(post_save, sender=InventoryQuotaSaleTransaction)
|
||||||
|
|||||||
Reference in New Issue
Block a user