update
This commit is contained in:
parent
20f8093fe5
commit
c4f42d9958
@ -288,7 +288,7 @@ class CarFinanceForm(forms.ModelForm):
|
|||||||
class CarLocationForm(forms.ModelForm):
|
class CarLocationForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CarLocation
|
model = CarLocation
|
||||||
fields = ["car", "showroom", "description"]
|
fields = ["showroom", "description"]
|
||||||
widgets = {
|
widgets = {
|
||||||
"description": forms.Textarea(attrs={"rows": 2, "class": "form-control"}),
|
"description": forms.Textarea(attrs={"rows": 2, "class": "form-control"}),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -239,6 +239,11 @@ urlpatterns = [
|
|||||||
views.CarLocationCreateView.as_view(),
|
views.CarLocationCreateView.as_view(),
|
||||||
name="add_car_location",
|
name="add_car_location",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"cars/<int:car_pk>/location/<int:pk>/update",
|
||||||
|
views.CarLocationUpdateView.as_view(),
|
||||||
|
name="update_car_location",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"cars/<int:pk>/location/update/",
|
"cars/<int:pk>/location/update/",
|
||||||
views.CarTransferCreateView.as_view(),
|
views.CarTransferCreateView.as_view(),
|
||||||
|
|||||||
@ -1020,31 +1020,27 @@ class CarLocationCreateView(LoginRequiredMixin,PermissionRequiredMixin,CreateVie
|
|||||||
dealer = get_user_type(self.request)
|
dealer = get_user_type(self.request)
|
||||||
form.instance.owner = dealer
|
form.instance.owner = dealer
|
||||||
form.save()
|
form.save()
|
||||||
messages.success(self.request, "Car saved successfully.")
|
messages.success(self.request, "Location saved successfully.")
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class CarLocationUpdateView(LoginRequiredMixin,UpdateView):
|
class CarLocationUpdateView(LoginRequiredMixin,PermissionRequiredMixin,UpdateView):
|
||||||
model = models.CarLocation
|
model = models.CarLocation
|
||||||
form_class = forms.CarLocationForm
|
form_class = forms.CarLocationForm
|
||||||
template_name = "inventory/car_location_form.html"
|
template_name = "inventory/car_location_form.html"
|
||||||
|
permission_required = ['inventory.update_carlocation']
|
||||||
|
|
||||||
def get_form(self, form_class=None):
|
# def get_initial(self):
|
||||||
form = super().get_form(form_class)
|
# initial = super().get_initial()
|
||||||
form.fields["showroom"].queryset = models.Dealer.objects.all()
|
# initial["car"] = get_object_or_404(models.Car, pk=self.kwargs["car_pk"])
|
||||||
form.fields["car"].queryset = models.Car.objects.filter(pk=self.kwargs["car_pk"])
|
# return initial
|
||||||
return form
|
|
||||||
|
|
||||||
def get_initial(self):
|
|
||||||
initial = super().get_initial()
|
|
||||||
initial["car"] = get_object_or_404(models.Car, pk=self.kwargs["car_pk"])
|
|
||||||
initial["showroom"] = get_object_or_404(models.CarLocation, pk=self.kwargs["pk"])
|
|
||||||
return initial
|
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.from_dealer = get_user_type(self.request)
|
form.instance.car = get_object_or_404(models.Car, pk=self.kwargs["car_pk"])
|
||||||
form.instance.car.status = "transfer"
|
dealer = get_user_type(self.request)
|
||||||
form.instance.car.save()
|
form.instance.owner = dealer
|
||||||
|
form.save()
|
||||||
|
messages.success(self.request, "Location updated successfully.")
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
|||||||
@ -160,7 +160,7 @@
|
|||||||
<td>
|
<td>
|
||||||
{% if car.finances and not car.get_transfer %}
|
{% if car.finances and not car.get_transfer %}
|
||||||
{% if car.location %} {% if car.location.is_owner_showroom %} {% trans 'Our Showroom' %} {% else %} {{ car.location.showroom.get_local_name }} {% endif %}
|
{% if car.location %} {% if car.location.is_owner_showroom %} {% trans 'Our Showroom' %} {% else %} {{ car.location.showroom.get_local_name }} {% endif %}
|
||||||
<a href="{% url 'transfer' car.pk %}" class="btn btn-phoenix-danger btn-sm">
|
<a href="{% url 'update_car_location' car.pk car.location.pk%}" class="btn btn-phoenix-danger btn-sm">
|
||||||
{% trans "transfer"|capfirst %}
|
{% trans "transfer"|capfirst %}
|
||||||
</a>
|
</a>
|
||||||
{% else %} {% trans "No location available." %}
|
{% else %} {% trans "No location available." %}
|
||||||
@ -177,6 +177,9 @@
|
|||||||
{% if not car.get_transfer %}
|
{% if not car.get_transfer %}
|
||||||
{% if perms.inventory.change_car %}
|
{% if perms.inventory.change_car %}
|
||||||
<a href="{% url 'car_update' car.pk %}" class="btn btn-phoenix-warning btn-sm mt-1">{% trans "Edit" %}</a>
|
<a href="{% url 'car_update' car.pk %}" class="btn btn-phoenix-warning btn-sm mt-1">{% trans "Edit" %}</a>
|
||||||
|
<a href="{% url 'transfer' car.pk %}" class="btn btn-phoenix-danger btn-sm">
|
||||||
|
{% trans "Sell to another dealer"|capfirst %}
|
||||||
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="badge bg-danger">{% trans "Cannot Edit, Car in Transfer." %}</span>
|
<span class="badge bg-danger">{% trans "Cannot Edit, Car in Transfer." %}</span>
|
||||||
|
|||||||
@ -4,11 +4,6 @@
|
|||||||
{% block title %}{% trans "Manage Car Location" %}{% endblock %}
|
{% block title %}{% trans "Manage Car Location" %}{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
{% if carlocation.exists %}
|
|
||||||
<p class="fw-bold">{% trans 'Transfer' %}</p>
|
|
||||||
{% else %}
|
|
||||||
<p class="fw-bold">{% trans 'Add' %}</p>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<h3 class="mb-3">{% trans "Manage Car Location" %}</h3>
|
<h3 class="mb-3">{% trans "Manage Car Location" %}</h3>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user