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 %} +
{{ 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 }}