diff --git a/.DS_Store b/.DS_Store index 7f72e1c8..5ea1a564 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/haikalbot/chatbot_logic.py b/haikalbot/chatbot_logic.py index 6b9cd7aa..a624046c 100644 --- a/haikalbot/chatbot_logic.py +++ b/haikalbot/chatbot_logic.py @@ -20,10 +20,10 @@ def get_gpt4_response(user_input, dealer): dealer = dealer client = OpenAI(api_key=settings.OPENAI_API_KEY) - if "سيارة في المخزون" in user_input.lower(): - # cars = user_input.split("how many cars")[-1].strip() - car_data = fetch_data(dealer) - user_input += f" Relevant car data: {car_data}" + # if "سيارة في المخزون" in user_input.lower(): + # # cars = user_input.split("how many cars")[-1].strip() + # car_data = fetch_data(dealer) + # user_input += f" Relevant car data: {car_data}" try: completion = client.chat.completions.create( model="gpt-4o", diff --git a/inventory/__pycache__/forms.cpython-311.pyc b/inventory/__pycache__/forms.cpython-311.pyc index a774c93a..af713c28 100644 Binary files a/inventory/__pycache__/forms.cpython-311.pyc and b/inventory/__pycache__/forms.cpython-311.pyc differ diff --git a/inventory/__pycache__/models.cpython-311.pyc b/inventory/__pycache__/models.cpython-311.pyc index 7cc30553..566de19a 100644 Binary files a/inventory/__pycache__/models.cpython-311.pyc and b/inventory/__pycache__/models.cpython-311.pyc differ diff --git a/inventory/__pycache__/services.cpython-311.pyc b/inventory/__pycache__/services.cpython-311.pyc index 22d5ef2a..f700a2fa 100644 Binary files a/inventory/__pycache__/services.cpython-311.pyc and b/inventory/__pycache__/services.cpython-311.pyc differ diff --git a/inventory/__pycache__/views.cpython-311.pyc b/inventory/__pycache__/views.cpython-311.pyc index 4a3ef42f..2328e211 100644 Binary files a/inventory/__pycache__/views.cpython-311.pyc and b/inventory/__pycache__/views.cpython-311.pyc differ diff --git a/inventory/forms.py b/inventory/forms.py index a0b78a2b..0f786bc0 100644 --- a/inventory/forms.py +++ b/inventory/forms.py @@ -567,7 +567,7 @@ class EmailForm(forms.Form): from_email = forms.EmailField() to_email = forms.EmailField(label="To") -class LeadForm(forms.ModelForm): +class LeadCreateForm(forms.ModelForm): class Meta: model = Lead fields = ['title', @@ -588,7 +588,6 @@ class LeadForm(forms.ModelForm): ] def __init__(self, *args, **kwargs): - dealer = kwargs.pop("dealer", None) super().__init__(*args, **kwargs) if "id_car_make" in self.fields: @@ -597,6 +596,34 @@ class LeadForm(forms.ModelForm): (obj.id_car_make, obj.get_local_name()) for obj in queryset ] +class LeadUpdateForm(forms.ModelForm): + class Meta: + model = Lead + fields = ['title', + 'first_name', + 'last_name', + 'email', + 'phone_number', + 'city', + 'salary', + 'obligations', + 'id_car_make', + 'id_car_model', + 'year', + 'source', + 'channel', + 'assigned', + 'priority', + ] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + if "id_car_make" in self.fields: + queryset = self.fields["id_car_make"].queryset.filter(is_sa_import=True) + self.fields["id_car_make"].choices = [ + (obj.id_car_make, obj.get_local_name()) for obj in queryset + ] class NoteForm(forms.ModelForm): diff --git a/inventory/models.py b/inventory/models.py index c6a8330e..66dff338 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -707,7 +707,7 @@ class Staff(models.Model, LocalizedNameMixin): permissions = [] def __str__(self): - return f"{self.name} - {self.get_staff_type_display()}" + return f"{self.name}" class Sources(models.TextChoices): diff --git a/inventory/services.py b/inventory/services.py index 1ec259e9..75bfbd15 100644 --- a/inventory/services.py +++ b/inventory/services.py @@ -36,8 +36,8 @@ def decodevin(vin): if result:=decode_vin(vin): return result - elif result:=decode_vin_haikalna(vin): - return result + # elif result:=decode_vin_haikalna(vin): + # return result elif result:=elm(vin): return result diff --git a/inventory/views.py b/inventory/views.py index d0f60a61..901046bd 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -2380,14 +2380,16 @@ class LeadDetailView(DetailView): context['status_history'] = models.LeadStatusHistory.objects.filter(lead=self.object) return context -class LeadCreateView(CreateView): +class LeadCreateView(CreateView, SuccessMessageMixin, LoginRequiredMixin): model = models.Lead - form_class = forms.LeadForm - template_name = 'crm/leads/lead_form.html' + form_class = forms.LeadCreateForm + template_name = 'crm/leads/lead_create_form.html' success_message = "Lead created successfully!" success_url = reverse_lazy('lead_list') + def form_valid(self, form): + print("Form data:", form.cleaned_data) # Debug form data dealer = get_user_type(self.request) form.instance.dealer = dealer return super().form_valid(form) @@ -2395,8 +2397,8 @@ class LeadCreateView(CreateView): class LeadUpdateView(UpdateView): model = models.Lead - form_class = forms.LeadForm - template_name = 'crm/leads/lead_form.html' + form_class = forms.LeadUpdateForm + template_name = 'crm/leads/lead_update_form.html' success_url = reverse_lazy('lead_list') class LeadDeleteView(DeleteView): @@ -2450,7 +2452,10 @@ class OpportunityCreateView(CreateView): def form_valid(self, form): dealer = get_user_type(self.request) form.instance.dealer = dealer - form.instance.staff = dealer.staff + staff = self.request.user.staff + print(dealer) + print(staff) + form.instance.staff = staff return super().form_valid(form) def get_success_url(self): @@ -2510,13 +2515,13 @@ def delete_opportunity(request, pk): class NotificationListView(LoginRequiredMixin, ListView): model = models.Notification - template_name = "notifications_history.html" + template_name = "crm/notifications_history.html" context_object_name = "notifications" paginate_by = 10 def get_queryset(self): return models.Notification.objects.filter(user=self.request.user).order_by( - "-created_at" + "-created" ) @@ -2533,12 +2538,12 @@ def mark_notification_as_read(request, pk): def fetch_notifications(request): notifications = models.Notification.objects.filter( user=request.user, is_read=False - ).order_by("-created_at") + ).order_by("-created") notifications_data = [ { "id": notification.id, "message": notification.message, - "created_at": notification.created_at.strftime("%Y-%m-%d %H:%M:%S"), + "created": notification.created.strftime("%Y-%m-%d %H:%M:%S"), } for notification in notifications ] diff --git a/static/.DS_Store b/static/.DS_Store index 3da6e0b4..7ad22426 100644 Binary files a/static/.DS_Store and b/static/.DS_Store differ diff --git a/static/flags/.DS_Store b/static/flags/.DS_Store index 0db71a55..d9765d1c 100644 Binary files a/static/flags/.DS_Store and b/static/flags/.DS_Store differ diff --git a/templates/.DS_Store b/templates/.DS_Store index e94952cd..e787b8c0 100644 Binary files a/templates/.DS_Store and b/templates/.DS_Store differ diff --git a/templates/crm/.DS_Store b/templates/crm/.DS_Store new file mode 100644 index 00000000..61e33263 Binary files /dev/null and b/templates/crm/.DS_Store differ diff --git a/templates/crm/leads/lead_create_form.html b/templates/crm/leads/lead_create_form.html new file mode 100644 index 00000000..4cd1f04a --- /dev/null +++ b/templates/crm/leads/lead_create_form.html @@ -0,0 +1,388 @@ +{% extends "base.html" %} +{% load i18n static %} + +{% block content %} +
+
+

+ {% if form.instance.pk %} + {{ _("Edit Lead") }} + {% else %} + {{ _("Add New Lead") }} + {% endif %} +

+
+ +
+ +
+ {% csrf_token %} + + +
+
+ + +
+ {{ form.title.errors }} +
+ + +
+
+ + +
+ {{ form.first_name.errors }} +
+ + +
+
+ + +
+ {{ form.last_name.errors }} +
+ + +
+
+ + +
+ {{ form.email.errors }} +
+ + +
+
+ + +
+ {{ form.phone_number.errors }} +
+ + +
+
+ + +
+ {{ form.salary.errors }} +
+ + +
+
+ + +
+ {{ form.obligations.errors }} +
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ {{ form.year.errors }} +
+ + +
+
+ + +
+ {{ form.source.errors }} +
+ + +
+
+ + +
+ {{ form.channel.errors }} +
+ + +
+
+ + +
+ {{ form.assigned.errors }} +
+ + +
+
+ + +
+ {{ form.priority.errors }} +
+ + +
+ + + {{ _("Cancel") }} + +
+
+
+
+ + +{% endblock %} \ No newline at end of file diff --git a/templates/crm/leads/lead_detail.html b/templates/crm/leads/lead_detail.html index 48affa57..3c9d8f72 100644 --- a/templates/crm/leads/lead_detail.html +++ b/templates/crm/leads/lead_detail.html @@ -2,8 +2,8 @@ {% load i18n static %} {% block content %} -
-
+ +
@@ -12,17 +12,9 @@
- +
- - - - +
@@ -31,10 +23,10 @@
-
+

{{ _("Lead Details")}}

- +
@@ -127,7 +119,7 @@
-
+
@@ -238,12 +230,12 @@
- Quary about purchased soccer socks + Quary about purchased soccer socks
jackson@mail.com
Jackson Pollock Dec 29, 2021 10:23 am - Call + Call sent @@ -252,12 +244,12 @@
- How to take the headache out of Order + How to take the headache out of Order
ansolo45@mail.com
Ansolo Lazinatov Dec 27, 2021 3:27 pm - Call + Call delivered @@ -266,12 +258,12 @@
- The Arnold Schwarzenegger of Order + The Arnold Schwarzenegger of Order
ansolo45@mail.com
Ansolo Lazinatov Dec 24, 2021 10:44 am - Call + Call Bounce @@ -280,12 +272,12 @@
- My order is not being taken + My order is not being taken
jackson@mail.com
Jackson Pollock Dec 19, 2021 4:55 pm - Call + Call Spam @@ -294,12 +286,12 @@
- Shipment is missing + Shipment is missing
jackson@mail.com
Jackson Pollock Dec 19, 2021 2:43 pm - Call + Call sent @@ -308,12 +300,12 @@
- How can I order something urgently? + How can I order something urgently?
ansolo45@mail.com
Jackson Pollock Dec 19, 2021 2:43 pm - Call + Call Delivered @@ -322,12 +314,12 @@
- How the delicacy of the products will be handled? + How the delicacy of the products will be handled?
ansolo45@mail.com
Ansolo Lazinatov Dec 16, 2021 5:18 pm - Call + Call bounced @@ -335,7 +327,7 @@
-

View allView Less +

View allView Less
@@ -370,12 +362,12 @@
- Quary about purchased soccer socks + Quary about purchased soccer socks
jackson@mail.com
Jackson Pollock Dec 29, 2021 10:23 am - Call + Call sent @@ -384,12 +376,12 @@
- How to take the headache out of Order + How to take the headache out of Order
ansolo45@mail.com
Ansolo Lazinatov Dec 27, 2021 3:27 pm - Call + Call delivered @@ -398,12 +390,12 @@ - The Arnold Schwarzenegger of Order + The Arnold Schwarzenegger of Order
ansolo45@mail.com
Ansolo Lazinatov Dec 24, 2021 10:44 am - Call + Call Bounce @@ -412,12 +404,12 @@ - My order is not being taken + My order is not being taken
jackson@mail.com
Jackson Pollock Dec 19, 2021 4:55 pm - Call + Call Spam @@ -426,12 +418,12 @@ - Shipment is missing + Shipment is missing
jackson@mail.com
Jackson Pollock Dec 19, 2021 2:43 pm - Call + Call sent @@ -439,7 +431,7 @@
-

View allView Less +

View allView Less
@@ -474,12 +466,12 @@
- Quary about purchased soccer socks + Quary about purchased soccer socks
jackson@mail.com
Jackson Pollock Dec 29, 2021 10:23 am - Call + Call sent @@ -488,12 +480,12 @@
- How to take the headache out of Order + How to take the headache out of Order
ansolo45@mail.com
Ansolo Lazinatov Dec 27, 2021 3:27 pm - Call + Call delivered @@ -502,12 +494,12 @@ - The Arnold Schwarzenegger of Order + The Arnold Schwarzenegger of Order
ansolo45@mail.com
Ansolo Lazinatov Dec 24, 2021 10:44 am - Call + Call Bounce @@ -516,12 +508,12 @@ - My order is not being taken + My order is not being taken
jackson@mail.com
Jackson Pollock Dec 19, 2021 4:55 pm - Call + Call Spam @@ -529,7 +521,7 @@
-

View allView Less +

View allView Less
diff --git a/templates/crm/leads/lead_list.html b/templates/crm/leads/lead_list.html index b6bce936..62dc71a6 100644 --- a/templates/crm/leads/lead_list.html +++ b/templates/crm/leads/lead_list.html @@ -3,7 +3,7 @@ {% block title %}{{ _('Leads')|capfirst }}{% endblock title %} {% block content %} -
+

{{ _("Leads")|capfirst }}

diff --git a/templates/crm/leads/lead_form.html b/templates/crm/leads/lead_update_form.html similarity index 82% rename from templates/crm/leads/lead_form.html rename to templates/crm/leads/lead_update_form.html index ba49f116..3adc6662 100644 --- a/templates/crm/leads/lead_form.html +++ b/templates/crm/leads/lead_update_form.html @@ -2,12 +2,13 @@ {% load i18n static%} {% block content %} +

{% if form.instance.pk %}{{ _("Edit Lead") }}{% else %}{{ _("Add New Lead") }}{% endif %}

-
+ {% csrf_token %}
@@ -79,7 +80,7 @@
- {% for value, label in form.id_car_make.field.choices %} {% endfor %} @@ -92,12 +93,12 @@
- {% for value, label in form.id_car_model.field.choices %} {% endfor %} - +
{{ form.id_car_model.errors }}
@@ -162,16 +163,16 @@
{{ form.priority.errors }}
- -
- + {{ _("Cancel") }}
+ + + // Ensure the form submits normally + document.querySelector("form").addEventListener("submit", (event) => { + // Do not call event.preventDefault() here unless you handle form submission manually + console.log("Form submitted normally"); // Debugging + }); +}); + + {% endblock %} \ No newline at end of file diff --git a/templates/notifications.html b/templates/crm/notifications.html similarity index 100% rename from templates/notifications.html rename to templates/crm/notifications.html diff --git a/templates/notifications_history.html b/templates/crm/notifications_history.html similarity index 94% rename from templates/notifications_history.html rename to templates/crm/notifications_history.html index f6156ff0..d7eb831b 100644 --- a/templates/notifications_history.html +++ b/templates/crm/notifications_history.html @@ -13,11 +13,11 @@

{{ _("System")}}:

{% if not notification.is_read %} -

{{ notification.message }} {{ notification.created_at|timesince }}

+

{{ notification.message }} {{ notification.created|timesince }}

{% else %} -

{{ notification.message }} {{ notification.created_at|timesince }}

+

{{ notification.message }} {{ notification.created|timesince }}

{% endif %} -

{{ notification.created_at }}

+

{{ notification.created }}

-
+
diff --git a/templates/haikalbot/chatbot.html b/templates/haikalbot/chatbot.html index 12f2f196..6a267232 100644 --- a/templates/haikalbot/chatbot.html +++ b/templates/haikalbot/chatbot.html @@ -51,7 +51,7 @@ function getCookie(name) { return cookieValue; } - const csrfToken = getCookie('token'); + const csrfToken = getCookie('csrftoken'); async function sendMessage() { diff --git a/templates/header.html b/templates/header.html index 17f8a2d3..a3091b95 100644 --- a/templates/header.html +++ b/templates/header.html @@ -250,7 +250,7 @@