44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
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)
|