fix the lead create

This commit is contained in:
ismail 2025-06-30 16:49:15 +03:00
parent 6436649488
commit 09c390ca81
3 changed files with 27 additions and 50 deletions

View File

@ -1582,7 +1582,6 @@ class PermissionForm(forms.ModelForm):
"inventory.carequipment",
"inventory.interiorcolors",
"inventory.exteriorcolors",
"inventory.carreservation",
"inventory.lead",
"inventory.customgroup",
"inventory.saleorder",
@ -1591,40 +1590,18 @@ class PermissionForm(forms.ModelForm):
"inventory.schedule",
"inventory.activity",
"inventory.opportunity",
"django_ledger.estimatemodel",
"django_ledger.invoicemodel",
"django_ledger.accountmodel",
"django_ledger.chartofaccountmodel",
"django_ledger.customermodel",
"django_ledger.billmodel"
"inventory.car",
"inventory.carequipment",
"inventory.interiorcolors",
"inventory.exteriorcolors",
"inventory.carcolors",
"inventory.carlocation",
"inventory.customcard",
"inventory.carreservation"
"django_ledger.estimatemodel",
"django_ledger.invoicemodel",
"django_ledger.customermodel",
"inventory.saleorder",
"inventory.payment",
"inventory.staff",
"inventory.schedule",
"inventory.activity",
"inventory.opportunity",
"inventory.customer",
"inventory.organization",
"inventory.lead",
"inventory.salequotation",
"inventory.salequotationcar"
"inventory.carfinance",
# "inventory.salequotation",
# "inventory.salequotationcar"
"django_ledger.bankaccountmodel",
"django_ledger.chartofaccountmodel",
"django_ledger.estimatemodel",
"django_ledger.accountmodel",
"django_ledger.chartofaccountmodel",
"django_ledger.customcard",
"django_ledger.billmodel",
"django_ledger.billmodel"
"django_ledger.itemmodel",
"django_ledger.invoicemodel",
"django_ledger.vendormodel",

View File

@ -528,25 +528,25 @@ def track_lead_status_change(sender, instance, **kwargs):
pass # Ignore if the lead doesn't exist (e.g., during initial creation)
@receiver(post_save, sender=models.Lead)
def notify_assigned_staff(sender, instance, created, **kwargs):
"""
Signal handler that sends a notification to the staff member when a new lead is assigned.
This function is triggered when a Lead instance is saved. If the lead has been assigned
to a staff member, it creates a Notification object, notifying the staff member of the
new assignment.
# @receiver(post_save, sender=models.Lead)
# def notify_assigned_staff(sender, instance, created, **kwargs):
# """
# Signal handler that sends a notification to the staff member when a new lead is assigned.
# This function is triggered when a Lead instance is saved. If the lead has been assigned
# to a staff member, it creates a Notification object, notifying the staff member of the
# new assignment.
:param sender: The model class that sent the signal.
:param instance: The instance of the model that was saved.
:param created: A boolean indicating whether a new instance was created.
:param kwargs: Additional keyword arguments.
:return: None
"""
if instance.staff: # Check if the lead is assigned
models.Notification.objects.create(
user=instance.staff.staff_member.user,
message=f"You have been assigned a new lead: {instance.full_name}.",
)
# :param sender: The model class that sent the signal.
# :param instance: The instance of the model that was saved.
# :param created: A boolean indicating whether a new instance was created.
# :param kwargs: Additional keyword arguments.
# :return: None
# """
# if instance.staff: # Check if the lead is assigned
# models.Notification.objects.create(
# user=instance.staff.staff_member.user,
# message=f"You have been assigned a new lead: {instance.full_name}.",
# )
@receiver(post_save, sender=models.CarReservation)

View File

@ -5230,7 +5230,7 @@ def lead_create(request,dealer_slug):
if form.is_valid():
instance = form.save(commit=False)
instance.dealer = dealer
instance.staff = form.cleaned_data.get("staff")
# instance.staff = form.cleaned_data.get("staff")
if instance.lead_type == "customer":
customer = models.Customer.objects.filter(
@ -5302,12 +5302,12 @@ def lead_create(request,dealer_slug):
is_sa_import=True, pk__in=dealer_make_list
)
form.fields["staff"].queryset = form.fields["staff"].queryset.filter(
dealer=dealer, staff_type="sales"
dealer=dealer
)
if hasattr(request.user.staffmember, "staff"):
form.initial["staff"] = request.user.staffmember.staff
form.fields["staff"].widget.attrs["disabled"] = True
form.fields["staff"].widget = HiddenInput()
form.fields["id_car_make"].queryset = qs
form.fields["id_car_make"].choices = [
(obj.id_car_make, obj.get_local_name()) for obj in qs