import device in notification structure
This commit is contained in:
20
apps/notification/migrations/0002_notification_device.py
Normal file
20
apps/notification/migrations/0002_notification_device.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-10-07 05:35
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('notification', '0001_initial'),
|
||||||
|
('pos_device', '0075_posfreeproducts_company_fee'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='notification',
|
||||||
|
name='device',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notifications', to='pos_device.device'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from apps.core.models import BaseModel
|
from apps.core.models import BaseModel
|
||||||
from apps.authentication.models import Organization
|
from apps.authentication.models import Organization
|
||||||
|
from apps.pos_device.models import Device
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
@@ -10,7 +11,12 @@ class Notification(BaseModel):
|
|||||||
('transaction', 'Transaction'),
|
('transaction', 'Transaction'),
|
||||||
('system', 'System'),
|
('system', 'System'),
|
||||||
)
|
)
|
||||||
|
device = models.ForeignKey(
|
||||||
|
Device,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='notifications',
|
||||||
|
null=True
|
||||||
|
)
|
||||||
organization = models.ForeignKey(
|
organization = models.ForeignKey(
|
||||||
Organization,
|
Organization,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ class NotificationViewSet(SoftDeleteMixin, POSDeviceMixin, DynamicSearchMixin, v
|
|||||||
""" show all notification of device """
|
""" show all notification of device """
|
||||||
|
|
||||||
organization = self.get_device_organization()
|
organization = self.get_device_organization()
|
||||||
|
device = self.get_pos_device()
|
||||||
|
|
||||||
queryset = self.queryset.filter(
|
queryset = self.queryset.filter(
|
||||||
|
device=device,
|
||||||
organization=organization,
|
organization=organization,
|
||||||
delivered=False,
|
delivered=False,
|
||||||
is_read=False
|
is_read=False
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from django.db.models.signals import post_save
|
|||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from apps.warehouse.models import InventoryEntry
|
from apps.warehouse.models import InventoryEntry
|
||||||
from apps.warehouse.models import product_models
|
from apps.warehouse.models import product_models
|
||||||
|
from apps.pos_device.models import Device
|
||||||
from .models import Notification
|
from .models import Notification
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
@@ -15,7 +16,10 @@ def create_inventory_entry_notification(sender, instance, created, **kwargs):
|
|||||||
|
|
||||||
def _create_notification():
|
def _create_notification():
|
||||||
# create notification for organization on pos device
|
# create notification for organization on pos device
|
||||||
|
devices = Device.objects.filter(assignment__client__organization=instance.organization)
|
||||||
|
for device in devices:
|
||||||
Notification.objects.create(
|
Notification.objects.create(
|
||||||
|
device=device,
|
||||||
organization=instance.organization,
|
organization=instance.organization,
|
||||||
title=f" {instance.distribution.distribution_id} ورودی جدید به انبار از توزیع با کد ", # noqa
|
title=f" {instance.distribution.distribution_id} ورودی جدید به انبار از توزیع با کد ", # noqa
|
||||||
message=f' مقدار {instance.distribution.weight} کیلوگرم' # noqa
|
message=f' مقدار {instance.distribution.weight} کیلوگرم' # noqa
|
||||||
@@ -27,12 +31,17 @@ def create_inventory_entry_notification(sender, instance, created, **kwargs):
|
|||||||
|
|
||||||
@receiver(post_save, sender=product_models.QuotaDistribution) # noqa
|
@receiver(post_save, sender=product_models.QuotaDistribution) # noqa
|
||||||
def create_quota_distribution_notification(sender, instance, created, **kwargs):
|
def create_quota_distribution_notification(sender, instance, created, **kwargs):
|
||||||
|
""" Create notification for organization for quota distribution creation """
|
||||||
|
|
||||||
if not created:
|
if not created:
|
||||||
return
|
return
|
||||||
|
|
||||||
def _create_notification():
|
def _create_notification():
|
||||||
# create notification for organization on pos device
|
# create notification for organization on pos device
|
||||||
|
devices = Device.objects.filter(assignment__client__organization=instance.organization)
|
||||||
|
for device in devices:
|
||||||
Notification.objects.create(
|
Notification.objects.create(
|
||||||
|
device=device,
|
||||||
organization=instance.assigned_organization,
|
organization=instance.assigned_organization,
|
||||||
title=f" {instance.quota.quota_id} توزیع جدید به شما از سهمیه با کد ", # noqa
|
title=f" {instance.quota.quota_id} توزیع جدید به شما از سهمیه با کد ", # noqa
|
||||||
message=f' مقدار {instance.weight} کیلوگرم' # noqa
|
message=f' مقدار {instance.weight} کیلوگرم' # noqa
|
||||||
|
|||||||
Reference in New Issue
Block a user