notification deployment - v3
This commit is contained in:
@@ -26,11 +26,12 @@ class NotificationViewSet(SoftDeleteMixin, POSDeviceMixin, DynamicSearchMixin, v
|
||||
is_read=False
|
||||
)
|
||||
|
||||
# set notifications delivered status to true
|
||||
# queryset.update(delivered=True)
|
||||
|
||||
# paginate & response
|
||||
page = self.paginate_queryset(queryset)
|
||||
|
||||
# set notifications delivered status to true
|
||||
queryset.update(delivered=True)
|
||||
|
||||
if page is not None:
|
||||
serializer = self.get_serializer(page, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from apps.warehouse.models import InventoryEntry
|
||||
from apps.warehouse.models import product_models
|
||||
from .models import Notification
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
@receiver(post_save, sender=InventoryEntry)
|
||||
def create_inventory_entry_notification(sender, instance, created, **kwargs):
|
||||
""" Create notification for organization after inventory entry creation """
|
||||
|
||||
if not created:
|
||||
return
|
||||
|
||||
def _create_notification():
|
||||
# create notification for organization on pos device
|
||||
Notification.objects.create(
|
||||
organization=instance.organization,
|
||||
title=f" {inventory_entry.distribution.distribution_id} ورودی جدید به انبار از توزیع با کد ", # noqa
|
||||
message=f' مقدار {inventory_entry.distribution.weight} کیلوگرم' # noqa
|
||||
f' از توزیع با کد {inventory_entry.distribution.distribution_id} به انبار ورود خورده است ', # noqa
|
||||
type='inventory',
|
||||
)
|
||||
|
||||
transaction.on_commit(_create_notification)
|
||||
|
||||
@receiver(post_save, sender=product_models.QuotaDistribution) # noqa
|
||||
def create_quota_distribution_notification(sender, instance, created, **kwargs):
|
||||
if not created:
|
||||
return
|
||||
|
||||
def _create_notification():
|
||||
# create notification for organization on pos device
|
||||
Notification.objects.create(
|
||||
organization=instance.assigned_organization,
|
||||
title=f" {distribution.quota.quota_id} توزیع جدید به شما از سهمیه با کد ", # noqa
|
||||
message=f' مقدار {distribution.weight} کیلوگرم' # noqa
|
||||
f' از سهمیه با کد {distribution.quota.quota_id} به شما توزیع شده است ', # noqa
|
||||
type='inventory',
|
||||
)
|
||||
|
||||
transaction.on_commit(_create_notification)
|
||||
|
||||
@@ -64,14 +64,6 @@ class QuotaDistributionViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSe
|
||||
if serializer.is_valid():
|
||||
distribution = serializer.save()
|
||||
|
||||
# create notification for organization on pos device
|
||||
Notification.objects.create(
|
||||
organization=organization,
|
||||
title=f" {distribution.quota.quota_id} توزیع جدید به شما از سهمیه با کد ", # noqa
|
||||
message=f' مقدار {distribution.weight} کیلوگرم' # noqa
|
||||
f' از سهمیه با کد {distribution.quota.quota_id} به شما توزیع شده است ', # noqa
|
||||
type='inventory',
|
||||
)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
|
||||
@@ -62,25 +62,17 @@ class InventoryEntryViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearc
|
||||
'organization': organization.id,
|
||||
'balance': inventory_balance
|
||||
})
|
||||
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
if serializer.is_valid():
|
||||
inventory_entry = serializer.save()
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
# upload document for confirmation entry
|
||||
if 'document' in request.data.keys():
|
||||
self.upload_confirmation_document(request, inventory=inventory_entry.id)
|
||||
inventory_entry = serializer.save()
|
||||
|
||||
# create notification for organization on pos device
|
||||
Notification.objects.create(
|
||||
organization=organization,
|
||||
title=f" {inventory_entry.distribution.distribution_id} ورودی جدید به انبار از توزیع با کد ", # noqa
|
||||
message=f' مقدار {inventory_entry.distribution.weight} کیلوگرم' # noqa
|
||||
f' از توزیع با کد {inventory_entry.distribution.distribution_id} به انبار ورود خورده است ', # noqa
|
||||
type='inventory',
|
||||
)
|
||||
# upload document for confirmation entry
|
||||
if 'document' in request.data.keys():
|
||||
self.upload_confirmation_document(request, inventory=inventory_entry.id)
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
@transaction.atomic
|
||||
def update(self, request, pk=None, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user