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