update customer and organization & staffmember
This commit is contained in:
parent
21089f8995
commit
a96b1131d3
@ -130,22 +130,17 @@ class DealerForm(forms.ModelForm):
|
|||||||
|
|
||||||
class CustomerForm(forms.Form):
|
class CustomerForm(forms.Form):
|
||||||
first_name = forms.CharField()
|
first_name = forms.CharField()
|
||||||
middle_name = forms.CharField()
|
|
||||||
last_name = forms.CharField()
|
last_name = forms.CharField()
|
||||||
national_id = forms.CharField(max_length=10)
|
|
||||||
email = forms.EmailField()
|
|
||||||
phone_number = PhoneNumberField(region="SA")
|
|
||||||
address = forms.CharField()
|
|
||||||
|
|
||||||
|
|
||||||
class OrganizationForm(forms.Form):
|
|
||||||
name = forms.CharField()
|
|
||||||
arabic_name = forms.CharField()
|
arabic_name = forms.CharField()
|
||||||
email = forms.EmailField()
|
email = forms.EmailField()
|
||||||
phone_number = PhoneNumberField(region="SA")
|
phone_number = PhoneNumberField(region="SA")
|
||||||
crn = forms.CharField()
|
national_id = forms.CharField(max_length=10,required=False)
|
||||||
vrn = forms.CharField()
|
crn = forms.CharField(required=False)
|
||||||
|
vrn = forms.CharField(required=False)
|
||||||
address = forms.CharField()
|
address = forms.CharField()
|
||||||
|
|
||||||
|
|
||||||
|
class OrganizationForm(CustomerForm):
|
||||||
contact_person = forms.CharField(required=False)
|
contact_person = forms.CharField(required=False)
|
||||||
logo = forms.ImageField(required=False)
|
logo = forms.ImageField(required=False)
|
||||||
|
|
||||||
@ -741,6 +736,8 @@ class LeadForm(forms.ModelForm):
|
|||||||
"address",
|
"address",
|
||||||
"id_car_make",
|
"id_car_make",
|
||||||
"id_car_model",
|
"id_car_model",
|
||||||
|
"crn",
|
||||||
|
"vrn",
|
||||||
"year",
|
"year",
|
||||||
"source",
|
"source",
|
||||||
"channel",
|
"channel",
|
||||||
|
|||||||
23
inventory/migrations/0053_lead_crn_lead_vrn.py
Normal file
23
inventory/migrations/0053_lead_crn_lead_vrn.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 4.2.17 on 2025-03-01 21:22
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('inventory', '0052_lead_lead_type'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lead',
|
||||||
|
name='crn',
|
||||||
|
field=models.CharField(blank=True, max_length=10, null=True, unique=True, verbose_name='Commercial Registration Number'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lead',
|
||||||
|
name='vrn',
|
||||||
|
field=models.CharField(blank=True, max_length=15, null=True, unique=True, verbose_name='VAT Registration Number'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -957,6 +957,9 @@ class Staff(models.Model, LocalizedNameMixin):
|
|||||||
|
|
||||||
objects = StaffUserManager()
|
objects = StaffUserManager()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def email(self):
|
||||||
|
return self.staff_member.user.email
|
||||||
@property
|
@property
|
||||||
def user(self):
|
def user(self):
|
||||||
return self.staff_member.user
|
return self.staff_member.user
|
||||||
@ -1197,6 +1200,12 @@ class Lead(models.Model):
|
|||||||
channel = models.CharField(
|
channel = models.CharField(
|
||||||
max_length=50, choices=Channel.choices, verbose_name=_("Channel")
|
max_length=50, choices=Channel.choices, verbose_name=_("Channel")
|
||||||
)
|
)
|
||||||
|
crn = models.CharField(
|
||||||
|
max_length=10, unique=True, verbose_name=_("Commercial Registration Number"), blank=True, null=True
|
||||||
|
)
|
||||||
|
vrn = models.CharField(
|
||||||
|
max_length=15, unique=True, verbose_name=_("VAT Registration Number"), blank=True, null=True
|
||||||
|
)
|
||||||
address = models.CharField(max_length=50, verbose_name=_("address"))
|
address = models.CharField(max_length=50, verbose_name=_("address"))
|
||||||
staff = models.ForeignKey(
|
staff = models.ForeignKey(
|
||||||
Staff,
|
Staff,
|
||||||
@ -1251,7 +1260,7 @@ class Lead(models.Model):
|
|||||||
@property
|
@property
|
||||||
def full_name(self):
|
def full_name(self):
|
||||||
return f"{self.first_name} {self.last_name}"
|
return f"{self.first_name} {self.last_name}"
|
||||||
def convert_to_customer(self,entity):
|
def convert_to_customer(self,entity,lead):
|
||||||
customer = entity.get_customers().filter(email=self.email).first()
|
customer = entity.get_customers().filter(email=self.email).first()
|
||||||
if entity and not customer:
|
if entity and not customer:
|
||||||
customer = entity.create_customer(
|
customer = entity.create_customer(
|
||||||
@ -1265,7 +1274,10 @@ class Lead(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
customer.additional_info.update({"info":self.to_dict()})
|
customer.additional_info.update({"info":self.to_dict()})
|
||||||
customer.additional_info.update({"type":"customer"})
|
if lead.lead_type == "organization":
|
||||||
|
customer.additional_info.update({"type":"organization"})
|
||||||
|
else:
|
||||||
|
customer.additional_info.update({"type":"customer"})
|
||||||
customer.save()
|
customer.save()
|
||||||
self.customer = customer
|
self.customer = customer
|
||||||
self.status = Status.QUALIFIED
|
self.status = Status.QUALIFIED
|
||||||
|
|||||||
@ -207,7 +207,7 @@ def dealer_signup(request, *args, **kwargs):
|
|||||||
user = User.objects.create(username=email, email=email)
|
user = User.objects.create(username=email, email=email)
|
||||||
user.set_password(password)
|
user.set_password(password)
|
||||||
user.save()
|
user.save()
|
||||||
|
StaffMember.objects.create(user=user)
|
||||||
models.Dealer.objects.create(
|
models.Dealer.objects.create(
|
||||||
user=user,
|
user=user,
|
||||||
name=name,
|
name=name,
|
||||||
@ -309,7 +309,6 @@ class HomeView(TemplateView):
|
|||||||
"total_selling_price": 0,
|
"total_selling_price": 0,
|
||||||
"total_profit": 0,
|
"total_profit": 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
class TestView(TemplateView):
|
class TestView(TemplateView):
|
||||||
@ -1303,7 +1302,6 @@ def CustomerCreateView(request):
|
|||||||
# Create customer name
|
# Create customer name
|
||||||
customer_name = (
|
customer_name = (
|
||||||
f"{form.cleaned_data['first_name']} "
|
f"{form.cleaned_data['first_name']} "
|
||||||
f"{form.cleaned_data['middle_name']} "
|
|
||||||
f"{form.cleaned_data['last_name']}"
|
f"{form.cleaned_data['last_name']}"
|
||||||
)
|
)
|
||||||
customer_dict = { x: request.POST[x] for x in request.POST if x != "csrfmiddlewaretoken"}
|
customer_dict = { x: request.POST[x] for x in request.POST if x != "csrfmiddlewaretoken"}
|
||||||
@ -1346,8 +1344,6 @@ def CustomerUpdateView(request, pk):
|
|||||||
customer_name = (
|
customer_name = (
|
||||||
customer_dict["first_name"]
|
customer_dict["first_name"]
|
||||||
+ " "
|
+ " "
|
||||||
+ customer_dict["middle_name"]
|
|
||||||
+ " "
|
|
||||||
+ customer_dict["last_name"]
|
+ customer_dict["last_name"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1705,10 +1701,11 @@ def OrganizationCreateView(request):
|
|||||||
x: request.POST[x] for x in request.POST if x != "csrfmiddlewaretoken"
|
x: request.POST[x] for x in request.POST if x != "csrfmiddlewaretoken"
|
||||||
}
|
}
|
||||||
dealer = get_user_type(request)
|
dealer = get_user_type(request)
|
||||||
|
name = organization_dict["first_name"] + " " + organization_dict["last_name"]
|
||||||
instance = dealer.entity.create_customer(
|
customer = dealer.entity.create_customer(
|
||||||
|
commit=False,
|
||||||
customer_model_kwargs={
|
customer_model_kwargs={
|
||||||
"customer_name": organization_dict["name"],
|
"customer_name": name,
|
||||||
"address_1": organization_dict["address"],
|
"address_1": organization_dict["address"],
|
||||||
"phone": organization_dict["phone_number"],
|
"phone": organization_dict["phone_number"],
|
||||||
"email": organization_dict["email"],
|
"email": organization_dict["email"],
|
||||||
@ -1720,10 +1717,10 @@ def OrganizationCreateView(request):
|
|||||||
file_url = default_storage.url(file_name)
|
file_url = default_storage.url(file_name)
|
||||||
|
|
||||||
organization_dict["logo"] = file_url
|
organization_dict["logo"] = file_url
|
||||||
organization_dict["pk"] = str(instance.pk)
|
organization_dict["pk"] = str(customer.pk)
|
||||||
instance.additional_info["organization_info"] = organization_dict
|
customer.additional_info.update({"customer_info": organization_dict})
|
||||||
instance.additional_info["type"] = "organization"
|
customer.additional_info.update({"type": "organization"})
|
||||||
instance.save()
|
customer.save()
|
||||||
messages.success(request, _("Organization created successfully."))
|
messages.success(request, _("Organization created successfully."))
|
||||||
return redirect("organization_list")
|
return redirect("organization_list")
|
||||||
else:
|
else:
|
||||||
@ -1742,9 +1739,10 @@ def OrganizationUpdateView(request,pk):
|
|||||||
dealer = get_user_type(request)
|
dealer = get_user_type(request)
|
||||||
|
|
||||||
instance = dealer.entity.get_customers().get(
|
instance = dealer.entity.get_customers().get(
|
||||||
pk=organization.additional_info["organization_info"]["pk"]
|
pk=organization.additional_info["customer_info"]["pk"]
|
||||||
)
|
)
|
||||||
instance.customer_name = organization_dict["name"]
|
name = organization_dict["first_name"] + " " + organization_dict["last_name"]
|
||||||
|
instance.customer_name = name
|
||||||
instance.address_1 = organization_dict["address"]
|
instance.address_1 = organization_dict["address"]
|
||||||
instance.phone = organization_dict["phone_number"]
|
instance.phone = organization_dict["phone_number"]
|
||||||
instance.email = organization_dict["email"]
|
instance.email = organization_dict["email"]
|
||||||
@ -1755,17 +1753,17 @@ def OrganizationUpdateView(request,pk):
|
|||||||
file_url = default_storage.url(file_name)
|
file_url = default_storage.url(file_name)
|
||||||
organization_dict["logo"] = file_url
|
organization_dict["logo"] = file_url
|
||||||
else:
|
else:
|
||||||
organization_dict["logo"] = organization.additional_info["organization_info"]["logo"]
|
organization_dict["logo"] = organization.additional_info["customer_info"]["logo"]
|
||||||
|
|
||||||
organization_dict["pk"] = str(instance.pk)
|
organization_dict["pk"] = str(instance.pk)
|
||||||
instance.additional_info["organization_info"] = organization_dict
|
instance.additional_info["customer_info"] = organization_dict
|
||||||
instance.additional_info["type"] = "organization"
|
instance.additional_info["type"] = "organization"
|
||||||
instance.save()
|
instance.save()
|
||||||
messages.success(request, _("Organization created successfully."))
|
messages.success(request, _("Organization created successfully."))
|
||||||
return redirect("organization_list")
|
return redirect("organization_list")
|
||||||
else:
|
else:
|
||||||
form = forms.OrganizationForm(
|
form = forms.OrganizationForm(
|
||||||
initial=organization.additional_info["organization_info"] or {}
|
initial=organization.additional_info["customer_info"] or {}
|
||||||
)
|
)
|
||||||
# form.fields.pop("logo", None)
|
# form.fields.pop("logo", None)
|
||||||
return render(request, "organizations/organization_form.html", {"form": form})
|
return render(request, "organizations/organization_form.html", {"form": form})
|
||||||
@ -2725,6 +2723,8 @@ def lead_create(request):
|
|||||||
"address": instance.address,
|
"address": instance.address,
|
||||||
"phone_number": str(instance.phone_number),
|
"phone_number": str(instance.phone_number),
|
||||||
"email": instance.email,
|
"email": instance.email,
|
||||||
|
"crn": form.cleaned_data["crn"],
|
||||||
|
"vrn": form.cleaned_data["vrn"],
|
||||||
}
|
}
|
||||||
customer.additional_info.update({"customer_info": customer_info })
|
customer.additional_info.update({"customer_info": customer_info })
|
||||||
customer.additional_info.update({"type":"lead"})
|
customer.additional_info.update({"type":"lead"})
|
||||||
@ -2836,7 +2836,7 @@ def lead_convert(request, pk):
|
|||||||
if hasattr(lead, "opportunity"):
|
if hasattr(lead, "opportunity"):
|
||||||
messages.error(request, "Lead is already converted to customer.")
|
messages.error(request, "Lead is already converted to customer.")
|
||||||
else:
|
else:
|
||||||
customer = lead.convert_to_customer(dealer.entity)
|
customer = lead.convert_to_customer(dealer.entity,lead)
|
||||||
models.Opportunity.objects.create(dealer=dealer,customer=customer,lead=lead,probability=50,stage=models.Stage.PROSPECT,staff=lead.staff,status=models.Status.QUALIFIED)
|
models.Opportunity.objects.create(dealer=dealer,customer=customer,lead=lead,probability=50,stage=models.Stage.PROSPECT,staff=lead.staff,status=models.Status.QUALIFIED)
|
||||||
messages.success(request, "Lead converted to customer successfully!")
|
messages.success(request, "Lead converted to customer successfully!")
|
||||||
return redirect("lead_list")
|
return redirect("lead_list")
|
||||||
|
|||||||
@ -5,10 +5,10 @@
|
|||||||
<div class="row my-4">
|
<div class="row my-4">
|
||||||
<h2>{{ organization.get_local_name }}</h2>
|
<h2>{{ organization.get_local_name }}</h2>
|
||||||
<ul class="list-group mb-4">
|
<ul class="list-group mb-4">
|
||||||
<li class="list-group-item"><strong>{% trans "CRN" %}:</strong> {{ organization.additional_info.organization_info.crn }}</li>
|
<li class="list-group-item"><strong>{% trans "CRN" %}:</strong> {{ organization.additional_info.customer_info.crn }}</li>
|
||||||
<li class="list-group-item"><strong>{% trans "VRN" %}:</strong> {{ organization.additional_info.organization_info.vrn }}</li>
|
<li class="list-group-item"><strong>{% trans "VRN" %}:</strong> {{ organization.additional_info.customer_info.vrn }}</li>
|
||||||
<li class="list-group-item"><strong>{% trans "Phone" %}:</strong> {{ organization.additional_info.organization_info.phone_number }}</li>
|
<li class="list-group-item"><strong>{% trans "Phone" %}:</strong> {{ organization.additional_info.customer_info.phone_number }}</li>
|
||||||
<li class="list-group-item"><strong>{% trans "Address" %}:</strong> {{ organization.additional_info.organization_info.address }}</li>
|
<li class="list-group-item"><strong>{% trans "Address" %}:</strong> {{ organization.additional_info.customer_info.address }}</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<a href="{% url 'organization_update' organization.pk %}" class="btn btn-sm btn-warning me-2">{% trans "Edit" %}</a>
|
<a href="{% url 'organization_update' organization.pk %}" class="btn btn-sm btn-warning me-2">{% trans "Edit" %}</a>
|
||||||
|
|||||||
@ -107,8 +107,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="email align-middle white-space-nowrap fw-semibold ps-4 border-end border-translucent">{{ org.additional_info.organization_info.crn }}</td>
|
<td class="email align-middle white-space-nowrap fw-semibold ps-4 border-end border-translucent">{{ org.additional_info.customer_info.crn }}</td>
|
||||||
<td class="phone align-middle white-space-nowrap fw-semibold ps-4 border-end border-translucent">{{ org.additional_info.organization_info.vrn }}</td>
|
<td class="phone align-middle white-space-nowrap fw-semibold ps-4 border-end border-translucent">{{ org.additional_info.customer_info.vrn }}</td>
|
||||||
<td class="phone align-middle white-space-nowrap ps-4 border-end border-translucent fw-semibold text-body-highlight">
|
<td class="phone align-middle white-space-nowrap ps-4 border-end border-translucent fw-semibold text-body-highlight">
|
||||||
<a class="text-body-highlight" href="tel:{{ org.phone }}">{{ org.phone }}</a>
|
<a class="text-body-highlight" href="tel:{{ org.phone }}">{{ org.phone }}</a>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user