update on the notification
This commit is contained in:
parent
73ae641ddb
commit
2bb0dea9fa
@ -2202,6 +2202,9 @@ class Vendor(models.Model, LocalizedNameMixin):
|
|||||||
max_length=255, unique=True, verbose_name=_("Slug"), null=True, blank=True
|
max_length=255, unique=True, verbose_name=_("Slug"), null=True, blank=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse("vendor_detail", kwargs={"dealer_slug":self.dealer.slug,"pk": self.pk})
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.slug:
|
if not self.slug:
|
||||||
base_slug = slugify(self.name)
|
base_slug = slugify(self.name)
|
||||||
|
|||||||
@ -921,3 +921,63 @@ def car_created_notification(sender, instance, created, **kwargs):
|
|||||||
<a href="{instance.get_absolute_url()}" target="_blank">View</a>
|
<a href="{instance.get_absolute_url()}" target="_blank">View</a>
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
@receiver(post_save, sender=PurchaseOrderModel)
|
||||||
|
def po_fullfilled_notification(sender, instance, created, **kwargs):
|
||||||
|
if instance.is_fulfilled():
|
||||||
|
dealer = models.Dealer.objects.get(entity=instance.entity)
|
||||||
|
recipients = models.CustomGroup.objects.filter(dealer=instance.dealer,name="Accountant").first().group.user_set.all()
|
||||||
|
for recipient in recipients:
|
||||||
|
models.Notification.objects.create(
|
||||||
|
user=recipient,
|
||||||
|
message=f"""
|
||||||
|
New Purchase Order has been added.
|
||||||
|
<a href="{reverse('purchase_order_detail',kwargs={'dealer_slug':dealer.slug,'pk':instance.pk})}" target="_blank">View</a>
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
@receiver(post_save, sender=models.Vendor)
|
||||||
|
def vendor_created_notification(sender, instance, created, **kwargs):
|
||||||
|
if created:
|
||||||
|
recipients = models.CustomGroup.objects.filter(dealer=instance.dealer,name="Inventory").first().group.user_set.excludeall()
|
||||||
|
|
||||||
|
for recipient in recipients:
|
||||||
|
models.Notification.objects.create(
|
||||||
|
user=recipient,
|
||||||
|
message=f"""
|
||||||
|
New Vendor {instance.name} has been added to dealer {instance.dealer.name}.
|
||||||
|
<a href="{instance.get_absolute_url()}" target="_blank">View</a>
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
|
@receiver(post_save, sender=models.SaleOrder)
|
||||||
|
def sale_order_created_notification(sender, instance, created, **kwargs):
|
||||||
|
if created:
|
||||||
|
recipients = models.CustomGroup.objects.filter(dealer=instance.dealer,name="Accountant").first().group.user_set.exclude(email=instance.dealer.user.email)
|
||||||
|
|
||||||
|
for recipient in recipients:
|
||||||
|
models.Notification.objects.create(
|
||||||
|
user=recipient,
|
||||||
|
message=f"""
|
||||||
|
New Sale Order has been added for estimate:{instance.estimate}.
|
||||||
|
<a href="{reverse('estimate_detail',kwargs={'dealer_slug':instance.dealer.slug,'pk':instance.pk})}" target="_blank">View</a>
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
@receiver(post_save, sender=models.Lead)
|
||||||
|
def lead_created_notification(sender, instance, created, **kwargs):
|
||||||
|
if created:
|
||||||
|
models.Notification.objects.create(
|
||||||
|
user=instance.staff.user,
|
||||||
|
message=f"""
|
||||||
|
New Lead has been added.
|
||||||
|
<a href="{reverse('lead_detail',kwargs={'dealer_slug':instance.dealer.slug,'slug':instance.slug})}" target="_blank">View</a>
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
@receiver(post_save, sender=models.Lead)
|
||||||
|
def lead_created_notification(sender, instance, created, **kwargs):
|
||||||
|
if created:
|
||||||
|
models.Notification.objects.create(
|
||||||
|
user=instance.staff.user,
|
||||||
|
message=f"""
|
||||||
|
New Lead has been added.
|
||||||
|
<a href="{reverse('lead_detail',kwargs={'dealer_slug':instance.dealer.slug,'slug':instance.slug})}" target="_blank">View</a>
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
|||||||
@ -208,7 +208,7 @@ urlpatterns = [
|
|||||||
path("notifications/fetch/", views.fetch_notifications, name="fetch_notifications"),
|
path("notifications/fetch/", views.fetch_notifications, name="fetch_notifications"),
|
||||||
|
|
||||||
path(
|
path(
|
||||||
"/notifications/",
|
"notifications/",
|
||||||
views.NotificationListView.as_view(),
|
views.NotificationListView.as_view(),
|
||||||
name="notifications_history",
|
name="notifications_history",
|
||||||
),
|
),
|
||||||
|
|||||||
@ -5616,6 +5616,10 @@ def lead_transfer(request,dealer_slug, slug):
|
|||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
lead.staff = form.cleaned_data["transfer_to"]
|
lead.staff = form.cleaned_data["transfer_to"]
|
||||||
lead.save()
|
lead.save()
|
||||||
|
models.Notification.objects.create(
|
||||||
|
user=lead.staff.user,
|
||||||
|
message=f"You have been assigned a new lead: {lead.full_name}.",
|
||||||
|
)
|
||||||
messages.success(request, _("Lead transferred successfully"))
|
messages.success(request, _("Lead transferred successfully"))
|
||||||
else:
|
else:
|
||||||
messages.error(request, f"Invalid form data: {str(form.errors)}")
|
messages.error(request, f"Invalid form data: {str(form.errors)}")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user