more clean and fixes
This commit is contained in:
parent
f0f9dfc65e
commit
4fea4e43eb
@ -24,6 +24,7 @@ admin.site.register(models.CarReservation)
|
|||||||
admin.site.register(models.Organization)
|
admin.site.register(models.Organization)
|
||||||
admin.site.register(models.Representative)
|
admin.site.register(models.Representative)
|
||||||
admin.site.register(models.CarTrim)
|
admin.site.register(models.CarTrim)
|
||||||
|
admin.site.register(models.AdditionalServices)
|
||||||
|
|
||||||
@admin.register(models.CarMake)
|
@admin.register(models.CarMake)
|
||||||
class CarMakeAdmin(admin.ModelAdmin):
|
class CarMakeAdmin(admin.ModelAdmin):
|
||||||
|
|||||||
@ -17,7 +17,8 @@ from .models import (
|
|||||||
CarLocation,
|
CarLocation,
|
||||||
Organization,
|
Organization,
|
||||||
Representative,
|
Representative,
|
||||||
SaleQuotationCar
|
SaleQuotationCar,
|
||||||
|
AdditionalServices
|
||||||
|
|
||||||
)
|
)
|
||||||
from django.forms import ModelMultipleChoiceField
|
from django.forms import ModelMultipleChoiceField
|
||||||
@ -112,11 +113,24 @@ class CarUpdateForm(forms.ModelForm, AddClassMixin):
|
|||||||
|
|
||||||
|
|
||||||
class CarFinanceForm(AddClassMixin, forms.ModelForm):
|
class CarFinanceForm(AddClassMixin, forms.ModelForm):
|
||||||
|
additional_finances = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=AdditionalServices.objects.all(),
|
||||||
|
widget=forms.CheckboxSelectMultiple(attrs={'class': 'form-check-input'}),
|
||||||
|
required=False
|
||||||
|
)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CarFinance
|
model = CarFinance
|
||||||
exclude = ['car', 'profit_margin', 'vat_amount', 'total', 'vat_rate','additional_services']
|
exclude = ['car', 'additional_finances','profit_margin', 'vat_amount', 'total', 'vat_rate','additional_services']
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
if self.instance.pk:
|
||||||
|
self.fields['additional_finances'].initial = self.instance.additional_services.all()
|
||||||
|
def save(self, commit=True):
|
||||||
|
instance = super().save()
|
||||||
|
instance.additional_services.set(self.cleaned_data['additional_finances'])
|
||||||
|
instance.save()
|
||||||
|
return instance
|
||||||
|
|
||||||
class CarLocationForm(forms.ModelForm):
|
class CarLocationForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.17 on 2024-12-19 09:21
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('inventory', '0036_remove_car_additional_services_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='carfinance',
|
||||||
|
name='additional_services',
|
||||||
|
field=models.ManyToManyField(related_name='additional_finances', to='inventory.additionalservices'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
# Generated by Django 4.2.17 on 2024-12-19 09:33
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('inventory', '0037_alter_carfinance_additional_services'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='carfinance',
|
||||||
|
name='administration_fee',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='carfinance',
|
||||||
|
name='custom_card_fee',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='carfinance',
|
||||||
|
name='profit_margin',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='carfinance',
|
||||||
|
name='registration_fee',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='carfinance',
|
||||||
|
name='transportation_fee',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='carfinance',
|
||||||
|
name='vat_amount',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='carfinance',
|
||||||
|
name='additional_services',
|
||||||
|
field=models.ManyToManyField(blank=True, null=True, related_name='additional_finances', to='inventory.additionalservices'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.17 on 2024-12-19 09:33
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('inventory', '0038_remove_carfinance_administration_fee_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='carfinance',
|
||||||
|
name='additional_services',
|
||||||
|
field=models.ManyToManyField(blank=True, related_name='additional_finances', to='inventory.additionalservices'),
|
||||||
|
),
|
||||||
|
]
|
||||||
19
inventory/migrations/0040_additionalservices_display_name.py
Normal file
19
inventory/migrations/0040_additionalservices_display_name.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.17 on 2024-12-19 12:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('inventory', '0039_alter_carfinance_additional_services'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='additionalservices',
|
||||||
|
name='display_name',
|
||||||
|
field=models.CharField(default=1, max_length=255, verbose_name='Display Name'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -1,6 +1,7 @@
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
|
from django.db.models import Sum, F, Count
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db.models.signals import pre_save, post_save
|
from django.db.models.signals import pre_save, post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
@ -143,6 +144,7 @@ class DEALER_TYPES(models.TextChoices):
|
|||||||
|
|
||||||
class AdditionalServices(models.Model):
|
class AdditionalServices(models.Model):
|
||||||
name = models.CharField(max_length=255, verbose_name=_("Name"))
|
name = models.CharField(max_length=255, verbose_name=_("Name"))
|
||||||
|
display_name = models.CharField(max_length=255, verbose_name=_("Display Name"))
|
||||||
description = models.TextField(verbose_name=_("Description"))
|
description = models.TextField(verbose_name=_("Description"))
|
||||||
price = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Price"))
|
price = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Price"))
|
||||||
|
|
||||||
@ -151,7 +153,7 @@ class AdditionalServices(models.Model):
|
|||||||
verbose_name_plural = _("Additional Services")
|
verbose_name_plural = _("Additional Services")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name + " - " + str(self.price)
|
||||||
|
|
||||||
class Car(models.Model):
|
class Car(models.Model):
|
||||||
vin = models.CharField(max_length=17, unique=True, verbose_name=_("VIN"))
|
vin = models.CharField(max_length=17, unique=True, verbose_name=_("VIN"))
|
||||||
@ -274,28 +276,28 @@ class CarReservation(models.Model):
|
|||||||
|
|
||||||
# Car Finance Model
|
# Car Finance Model
|
||||||
class CarFinance(models.Model):
|
class CarFinance(models.Model):
|
||||||
additional_services = models.ManyToManyField(AdditionalServices, related_name="cars")
|
additional_services = models.ManyToManyField(AdditionalServices, related_name="additional_finances",blank=True)
|
||||||
car = models.OneToOneField(Car, on_delete=models.CASCADE, related_name='finances')
|
car = models.OneToOneField(Car, on_delete=models.CASCADE, related_name='finances')
|
||||||
cost_price = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Cost Price"))
|
cost_price = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Cost Price"))
|
||||||
selling_price = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Selling Price"))
|
selling_price = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Selling Price"))
|
||||||
profit_margin = models.DecimalField(max_digits=14,
|
|
||||||
decimal_places=2,
|
|
||||||
verbose_name=_("Profit Margin"),
|
|
||||||
editable=False)
|
|
||||||
vat_amount = models.DecimalField(max_digits=14,
|
|
||||||
decimal_places=2,
|
|
||||||
verbose_name=_("Vat Amount"),
|
|
||||||
editable=False,default=Decimal('0.00'))
|
|
||||||
discount_amount = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Discount Amount"),
|
discount_amount = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Discount Amount"),
|
||||||
default=Decimal('0.00'))
|
default=Decimal('0.00'))
|
||||||
registration_fee = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Registration Fee"),
|
# profit_margin = models.DecimalField(max_digits=14,
|
||||||
default=Decimal('0.00'))
|
# decimal_places=2,
|
||||||
administration_fee = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Administration Fee"),
|
# verbose_name=_("Profit Margin"),
|
||||||
default=Decimal('0.00'))
|
# editable=False)
|
||||||
transportation_fee = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Transportation Fee"),
|
# vat_amount = models.DecimalField(max_digits=14,
|
||||||
default=Decimal('0.00'))
|
# decimal_places=2,
|
||||||
custom_card_fee = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Custom Card Fee"),
|
# verbose_name=_("Vat Amount"),
|
||||||
default=Decimal('0.00'))
|
# editable=False,default=Decimal('0.00'))
|
||||||
|
# registration_fee = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Registration Fee"),
|
||||||
|
# default=Decimal('0.00'))
|
||||||
|
# administration_fee = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Administration Fee"),
|
||||||
|
# default=Decimal('0.00'))
|
||||||
|
# transportation_fee = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Transportation Fee"),
|
||||||
|
# default=Decimal('0.00'))
|
||||||
|
# custom_card_fee = models.DecimalField(max_digits=14, decimal_places=2, verbose_name=_("Custom Card Fee"),
|
||||||
|
# default=Decimal('0.00'))
|
||||||
@property
|
@property
|
||||||
def total(self):
|
def total(self):
|
||||||
"""Calculate the total amount including VAT."""
|
"""Calculate the total amount including VAT."""
|
||||||
@ -304,15 +306,15 @@ class CarFinance(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Car: {self.car}, Selling Price: {self.selling_price}"
|
return f"Car: {self.car}, Selling Price: {self.selling_price}"
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
# def save(self, *args, **kwargs):
|
||||||
self.full_clean()
|
# self.full_clean()
|
||||||
try:
|
# try:
|
||||||
price_after_discount = self.selling_price - self.discount_amount
|
# price_after_discount = self.selling_price - self.discount_amount
|
||||||
self.profit_margin = price_after_discount - self.cost_price
|
# self.profit_margin = price_after_discount - self.cost_price
|
||||||
self.vat_amount = settings.VAT_RATE
|
# self.vat_amount = settings.VAT_RATE
|
||||||
except InvalidOperation as e:
|
# except InvalidOperation as e:
|
||||||
raise ValidationError(_("Invalid decimal operation: %s") % str(e))
|
# raise ValidationError(_("Invalid decimal operation: %s") % str(e))
|
||||||
super().save(*args, **kwargs)
|
# super().save(*args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Car Financial Details")
|
verbose_name = _("Car Financial Details")
|
||||||
@ -669,6 +671,13 @@ class SaleQuotation(models.Model):
|
|||||||
total_quantity = self.quotation_cars.aggregate(total=Sum('quantity'))['total']
|
total_quantity = self.quotation_cars.aggregate(total=Sum('quantity'))['total']
|
||||||
return total_quantity or 0
|
return total_quantity or 0
|
||||||
|
|
||||||
|
# @property
|
||||||
|
# def total(self):
|
||||||
|
# total = self.quotation_cars.aggregate(total_price=Sum(F('car__finances__selling_price') * F('quantity')))
|
||||||
|
# if total:
|
||||||
|
# return float(total["total_price"]) * 0.15 + float(total["total_price"])
|
||||||
|
# return 0
|
||||||
|
|
||||||
def confirm(self):
|
def confirm(self):
|
||||||
"""Confirm the quotation and lock financial details."""
|
"""Confirm the quotation and lock financial details."""
|
||||||
if self.status != "DRAFT":
|
if self.status != "DRAFT":
|
||||||
@ -700,7 +709,10 @@ class SaleQuotationCar(models.Model):
|
|||||||
verbose_name=_("Car")
|
verbose_name=_("Car")
|
||||||
)
|
)
|
||||||
quantity = models.PositiveIntegerField(default=1, verbose_name=_("Quantity"))
|
quantity = models.PositiveIntegerField(default=1, verbose_name=_("Quantity"))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def finance(self):
|
||||||
|
return self.car.finances
|
||||||
@property
|
@property
|
||||||
def financial_details(self):
|
def financial_details(self):
|
||||||
"""
|
"""
|
||||||
@ -721,14 +733,14 @@ class SaleQuotationCar(models.Model):
|
|||||||
# "total_amount": car_finance.total,
|
# "total_amount": car_finance.total,
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
# @property
|
||||||
def total_price(self):
|
# def total(self):
|
||||||
"""
|
# """
|
||||||
Calculate total price dynamically based on quantity and selling price.
|
# Calculate total price dynamically based on quantity and selling price.
|
||||||
"""
|
# """
|
||||||
if not self.car.finances:
|
# if not self.car.finances:
|
||||||
return Decimal("0.00")
|
# return Decimal("0.00")
|
||||||
return self.car.finances.selling_price * self.quantity
|
# return self.car.finances.selling_price * self.quantity
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.car} - Quotation #{self.quotation.id}"
|
return f"{self.car} - Quotation #{self.quotation.id}"
|
||||||
|
|||||||
@ -1,26 +1,36 @@
|
|||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from inventory import models
|
||||||
|
|
||||||
def calculate_vat(value):
|
def calculate_vat(value):
|
||||||
"""Helper to calculate VAT dynamically for a given value."""
|
"""Helper to calculate VAT dynamically for a given value."""
|
||||||
vat_rate = getattr(settings, 'VAT_RATE', Decimal('0.15')) # Default VAT rate
|
vat_rate = getattr(settings, 'VAT_RATE', Decimal('0.15')) # Default VAT rate
|
||||||
return (value * vat_rate).quantize(Decimal('0.01'))
|
return (value * vat_rate).quantize(Decimal('0.01'))
|
||||||
def get_financial_value(instance,attribute,vat=False):
|
# def get_financial_value(instance,attribute,vat=False):
|
||||||
|
# if vat:
|
||||||
|
# return calculate_vat(getattr(instance, attribute, Decimal('0.00')) if instance else Decimal('0.00'))
|
||||||
|
# return getattr(instance, attribute, Decimal('0.00')) if instance else Decimal('0.00')
|
||||||
|
|
||||||
|
def get_financial_value(name,vat=False):
|
||||||
|
val = models.AdditionalServices.objects.filter(name=name).first()
|
||||||
|
if not val:
|
||||||
|
return 0
|
||||||
if vat:
|
if vat:
|
||||||
return calculate_vat(getattr(instance, attribute, Decimal('0.00')) if instance else Decimal('0.00'))
|
return (val.price * settings.VAT_RATE).quantize(Decimal('0.01'))
|
||||||
return getattr(instance, attribute, Decimal('0.00')) if instance else Decimal('0.00')
|
return val.price
|
||||||
|
|
||||||
|
|
||||||
def get_total_financials(instance,vat=False):
|
def get_total_financials(instance,vat=False):
|
||||||
price_after_discount = get_financial_value(instance,"selling_price",vat) - get_financial_value(instance,"discount_amount",vat)
|
# price_after_discount = get_financial_value(instance,"selling_price",vat) - get_financial_value(instance,"discount_amount",vat)
|
||||||
subtotal = (
|
# subtotal = (
|
||||||
price_after_discount +
|
# price_after_discount +
|
||||||
get_financial_value(instance,"registration_fee") +
|
# get_financial_value("registration_fee") +
|
||||||
get_financial_value(instance,"administration_fee",vat) +
|
# get_financial_value("administration_fee",vat) +
|
||||||
get_financial_value(instance,"transportation_fee",vat) +
|
# get_financial_value("transportation_fee",vat) +
|
||||||
get_financial_value(instance,"custom_card_fee",vat))
|
# get_financial_value("custom_card_fee",vat))
|
||||||
|
|
||||||
return subtotal
|
return 1000
|
||||||
|
|
||||||
def get_total(instance):
|
def get_total(instance):
|
||||||
total = get_total_financials(instance)
|
total = get_total_financials(instance)
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import requests
|
import requests
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from inventory import models
|
||||||
from inventory.utilities.financials import get_financial_value
|
from inventory.utilities.financials import get_financial_value
|
||||||
|
|
||||||
|
|
||||||
@ -32,48 +32,20 @@ def localize_some_words():
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_calculations(quotation):
|
||||||
def get_calculations(instance,quotation):
|
|
||||||
context = {}
|
context = {}
|
||||||
context['vat_rate'] = settings.VAT_RATE
|
qc_len = quotation.quotation_cars.count()
|
||||||
context['total_sales_before_vat'] = sum(item.car.finances.selling_price * item.quantity for item in quotation.quotation_cars.all())
|
cars = [x.car for x in quotation.quotation_cars.all()]
|
||||||
context['vat_amount'] = sum(item.car.finances.vat_amount * item.quantity for item in quotation.quotation_cars.all())
|
finances = models.CarFinance.objects.filter(car__in=cars)
|
||||||
context['total_sales_after_vat'] = context['total_sales_before_vat'] + context['vat_amount']
|
|
||||||
|
|
||||||
# Additional Costs
|
|
||||||
total_quantity = quotation.total_quantity
|
|
||||||
context['administration_fee'] = sum(item.car.finances.administration_fee for item in quotation.quotation_cars.all())
|
|
||||||
context['transportation_fee'] = sum(item.car.finances.transportation_fee for item in quotation.quotation_cars.all())
|
|
||||||
context['custom_card_fee'] = sum(item.car.finances.custom_card_fee for item in quotation.quotation_cars.all())
|
|
||||||
context['registration_fee'] = sum(item.car.finances.registration_fee for item in quotation.quotation_cars.all())
|
|
||||||
context['administration_fee_vat'] = sum(get_financial_value(item.car.finances,"administration_fee",True) for item in quotation.quotation_cars.all())
|
|
||||||
context['transportation_fee_vat'] = sum(get_financial_value(item.car.finances,"transportation_fee",True) for item in quotation.quotation_cars.all())
|
|
||||||
context['custom_card_fee_vat'] = sum(get_financial_value(item.car.finances,"custom_card_fee",True) for item in quotation.quotation_cars.all())
|
|
||||||
context['administration_fee_total'] = sum(item.car.finances.administration_fee + context['administration_fee_vat'] for item in quotation.quotation_cars.all())
|
|
||||||
context['transportation_fee_total'] = sum(item.car.finances.transportation_fee + context['transportation_fee_vat'] for item in quotation.quotation_cars.all())
|
|
||||||
context['custom_card_fee_total'] = sum(item.car.finances.custom_card_fee + context['custom_card_fee_vat'] for item in quotation.quotation_cars.all())
|
|
||||||
context['registration_fee_total'] = sum(item.car.finances.registration_fee * total_quantity for item in quotation.quotation_cars.all())
|
|
||||||
|
|
||||||
return context
|
services = models.AdditionalServices.objects.filter(additional_finances__in=finances).all()
|
||||||
# def get_calculations(quotation):
|
data = [{"name":x.name,"price":x.price,"total_price":x.price * qc_len,"vated":float(x.price) * 0.15 * float(qc_len),"total_price_vat":float(x.price) + (float(x.price) * 0.15 * float(qc_len))} for x in services]
|
||||||
# context = {}
|
context["services"] = data
|
||||||
# context['vat_rate'] = settings.VAT_RATE
|
context["total_cost"] = 0
|
||||||
# context['total_sales_before_vat'] = sum(item.car.selling_price * item.quantity for item in quotation.quotation_cars.all())
|
context["total_vat"] = 0
|
||||||
# context['vat_amount'] = sum(item.car.vat_amount * item.quantity for item in quotation.quotation_cars.all())
|
context["total_cost_vat"] = 0
|
||||||
# context['total_sales_after_vat'] = context['total_sales_before_vat'] + context['vat_amount']
|
for k in context["services"]:
|
||||||
|
context["total_cost"] += k["total_price"]
|
||||||
# # Additional Costs
|
context["total_vat"] += k["vated"]
|
||||||
# total_quantity = quotation.total_quantity
|
context["total_cost_vat"] = float(context["total_cost"])+float(context["total_vat"])
|
||||||
# context['administration_fee'] = sum(item.car.administration_fee for item in quotation.quotation_cars.all())
|
return context
|
||||||
# context['transportation_fee'] = sum(item.car.transportation_fee for item in quotation.quotation_cars.all())
|
|
||||||
# context['custom_card_fee'] = sum(item.car.custom_card_fee for item in quotation.quotation_cars.all())
|
|
||||||
# context['registration_fee'] = sum(item.car.registration_fee for item in quotation.quotation_cars.all())
|
|
||||||
# context['administration_fee_vat'] = sum(item.car.administration_fee_vat for item in quotation.quotation_cars.all())
|
|
||||||
# context['transportation_fee_vat'] = sum(item.car.transportation_fee_vat for item in quotation.quotation_cars.all())
|
|
||||||
# context['custom_card_fee_vat'] = sum(item.car.custom_card_fee_vat for item in quotation.quotation_cars.all())
|
|
||||||
# context['administration_fee_total'] = sum(item.car.administration_fee + context['administration_fee_vat'] for item in quotation.quotation_cars.all())
|
|
||||||
# context['transportation_fee_total'] = sum(item.car.transportation_fee + context['transportation_fee_vat'] for item in quotation.quotation_cars.all())
|
|
||||||
# context['custom_card_fee_total'] = sum(item.car.custom_card_fee + context['custom_card_fee_vat'] for item in quotation.quotation_cars.all())
|
|
||||||
# context['registration_fee_total'] = sum(item.car.registration_fee * total_quantity for item in quotation.quotation_cars.all())
|
|
||||||
|
|
||||||
# return context
|
|
||||||
@ -28,7 +28,7 @@ from django.contrib import messages
|
|||||||
from django.db.models import Sum, F, Count
|
from django.db.models import Sum, F, Count
|
||||||
|
|
||||||
from inventory.mixins import AddDealerInstanceMixin
|
from inventory.mixins import AddDealerInstanceMixin
|
||||||
from inventory.utils import get_calculations
|
|
||||||
from .services import elm, decodevin,get_make,get_model,normalize_name
|
from .services import elm, decodevin,get_make,get_model,normalize_name
|
||||||
from .services import elm, decodevin, get_make, get_model, normalize_name, get_ledger_data
|
from .services import elm, decodevin, get_make, get_model, normalize_name, get_ledger_data
|
||||||
from . import models, forms
|
from . import models, forms
|
||||||
@ -38,7 +38,7 @@ from django.contrib.auth.decorators import user_passes_test
|
|||||||
from django.contrib.messages.views import SuccessMessageMixin
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from .utils import get_calculations
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -405,6 +405,11 @@ class CarFinanceUpdateView(LoginRequiredMixin,SuccessMessageMixin, UpdateView):
|
|||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('car_detail', kwargs={'pk': self.object.car.pk})
|
return reverse('car_detail', kwargs={'pk': self.object.car.pk})
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super().get_form_kwargs()
|
||||||
|
kwargs['instance'] = self.get_object()
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class CarUpdateView(LoginRequiredMixin, SuccessMessageMixin,UpdateView):
|
class CarUpdateView(LoginRequiredMixin, SuccessMessageMixin,UpdateView):
|
||||||
@ -708,9 +713,8 @@ class QuotationDetailView(LoginRequiredMixin,PermissionRequiredMixin, DetailView
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
quotation = self.object
|
quotation = self.object
|
||||||
|
|
||||||
# context_result = get_calculations(quotation)
|
context_result = get_calculations(quotation)
|
||||||
context_result = get_calculations(self.object,quotation)
|
|
||||||
context.update(context_result)
|
context.update(context_result)
|
||||||
|
|
||||||
return context
|
return context
|
||||||
@ -767,8 +771,8 @@ class UserListView(LoginRequiredMixin,PermissionRequiredMixin, ListView):
|
|||||||
class UserDetailView(LoginRequiredMixin,PermissionRequiredMixin, DetailView):
|
class UserDetailView(LoginRequiredMixin,PermissionRequiredMixin, DetailView):
|
||||||
model = models.Dealer
|
model = models.Dealer
|
||||||
template_name = "users/user_detail.html"
|
template_name = "users/user_detail.html"
|
||||||
context_object_name = "user"
|
context_object_name = "user_"
|
||||||
permission_required = ('inventory.view_dealer',)
|
permission_required = ('inventory.view_dealer',)
|
||||||
|
|
||||||
class UserCreateView(LoginRequiredMixin,PermissionRequiredMixin,SuccessMessageMixin,AddDealerInstanceMixin, CreateView):
|
class UserCreateView(LoginRequiredMixin,PermissionRequiredMixin,SuccessMessageMixin,AddDealerInstanceMixin, CreateView):
|
||||||
model = models.Dealer
|
model = models.Dealer
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="collapse navbar-collapse" id="headerNav">
|
<div class="collapse navbar-collapse" id="headerNav">
|
||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
{% if user.is_authenticated and user.dealer.pk %}
|
{% if user.is_authenticated and user.dealer.pk %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
{% block home %}<a class="nav-link" href="{% url 'landing_page' %}">{% trans 'home' %}</a>{% endblock %}
|
{% block home %}<a class="nav-link" href="{% url 'landing_page' %}">{% trans 'home' %}</a>{% endblock %}
|
||||||
|
|||||||
@ -62,7 +62,7 @@
|
|||||||
<div class="modal-dialog modal-lg modal-dialog-scrollable">
|
<div class="modal-dialog modal-lg modal-dialog-scrollable">
|
||||||
<div class="modal-content glossy-modal">
|
<div class="modal-content glossy-modal">
|
||||||
<div class="modal-header bg-primary text-light">
|
<div class="modal-header bg-primary text-light">
|
||||||
<h5 class="modal-title" id="specificationsModalLabel">
|
<h5 class="modal-title" id="specificationsModalLabel">
|
||||||
{% trans 'specifications'|upper %}
|
{% trans 'specifications'|upper %}
|
||||||
</h5>
|
</h5>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
@ -227,27 +227,23 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "Selling Price" %}</th>
|
<th>{% trans "Selling Price" %}</th>
|
||||||
<td>{{ car.finances.selling_price }}</td>
|
<td>{{ car.finances.selling_price }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td><small class="ms-5">{% trans "Administration Fee" %}</small></td>
|
|
||||||
<td><small>{{ car.finances.administration_fee }}</small></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><small class="ms-5">{% trans "Registration Fee" %}</small></td>
|
|
||||||
<td><small>{{ car.finances.registration_fee }}</small></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><small class="ms-5">{% trans "Transportation Fee" %}</small></td>
|
|
||||||
<td><small>{{ car.finances.transportation_fee }}</small></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><small class="ms-5">{% trans "Custom Card Fee" %}</small></td>
|
|
||||||
<td><small>{{ car.finances.custom_card_fee }}</small></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "Discount Amount" %}</th>
|
<th>{% trans "Discount Amount" %}</th>
|
||||||
<td>{{ car.finances.discount_amount }} -</td>
|
<td>{{ car.finances.discount_amount }} -</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans "Additional Fee" %}</th>
|
||||||
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% if car.finances.additional_services.first.pk %}
|
||||||
|
{% for service in car.finances.additional_services.all %}
|
||||||
|
<tr>
|
||||||
|
<td><small class="ms-5">{{service.name}}</small></td>
|
||||||
|
<td><small>{{ service.price }}</small></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "VAT Amount" %}</th>
|
<th>{% trans "VAT Amount" %}</th>
|
||||||
<td>{{ car.finances.vat_amount }}</td>
|
<td>{{ car.finances.vat_amount }}</td>
|
||||||
|
|||||||
@ -74,8 +74,8 @@
|
|||||||
<td>{{ item.car.year }}</td>
|
<td>{{ item.car.year }}</td>
|
||||||
<td>{{ item.quantity }}</td>
|
<td>{{ item.quantity }}</td>
|
||||||
<td>{{ item.car.finances.selling_price }}</td>
|
<td>{{ item.car.finances.selling_price }}</td>
|
||||||
<td>{{ item.car.vat_amount }}</td>
|
<td>{{ 0.15 }}</td>
|
||||||
<td>{{ item.car.total }}</td>
|
<td>{{ item.total }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -96,35 +96,26 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "Additions" %}</th>
|
<th>{% trans "Additions" %}</th>
|
||||||
<th>{% trans "Cost" %}</th>
|
<th>{% trans "Cost" %}</th>
|
||||||
<th>{% trans "VAT" %}</th>
|
<th>{% trans "VAT %" %}</th>
|
||||||
<th>{% trans "Total Cost with VAT" %}</th>
|
<th>{% trans "Total Cost with VAT" %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
{% for service in services %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans "Administration Fee" %}</td>
|
<td>{{service.name}}</td>
|
||||||
<td>{{ administration_fee }}</td>
|
<td>{{ service.price }}</td>
|
||||||
<td>{{ administration_fee_vat }}</td>
|
<td>{{ service.vated }}</td>
|
||||||
<td>{{ administration_fee_total }}</td>
|
<td>{{ service.total_price_vat }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans "Transportation Fee" %}</td>
|
<td></td>
|
||||||
<td>{{ transportation_fee }}</td>
|
<td>{{ total_cost }}</td>
|
||||||
<td>{{ transportation_fee_vat }}</td>
|
<td>{{ total_vat }}</td>
|
||||||
<td>{{ transportation_fee_total }}</td>
|
<td>{{ total_cost_vat }}</td>
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>{% trans "Custom Card Fee" %}</td>
|
|
||||||
<td>{{ custom_card_fee }}</td>
|
|
||||||
<td>{{ custom_card_fee_vat }}</td>
|
|
||||||
<td>{{ custom_card_fee_total }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>{% trans "Registration Fee (No VAT)" %}</td>
|
|
||||||
<td>{{ registration_fee }}</td>
|
|
||||||
<td>{% trans "N/A" %}</td>
|
|
||||||
<td>{{ registration_fee_total }}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% load static %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block title %}{{ _("View Customer") }}{% endblock title %}
|
{% block title %}{{ _("View Customer") }}{% endblock title %}
|
||||||
@ -27,7 +28,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<a type="button"
|
<a type="button"
|
||||||
class="btn btn-sm btn-danger"
|
class="btn btn-sm btn-danger"
|
||||||
href="{% url 'user_delete' user.id %}">
|
href="{% url 'user_delete' user_.id %}">
|
||||||
{% trans 'Yes' %}
|
{% trans 'Yes' %}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@ -42,19 +43,19 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<p><strong>{{ _("Name") }}:</strong> {{ user.name }}</p>
|
<p><strong>{{ _("Name") }}:</strong> {{ user_.name }}</p>
|
||||||
<p><strong>{{ _("Arabic Name") }}:</strong> {{ user.arabic_name }}</p>
|
<p><strong>{{ _("Arabic Name") }}:</strong> {{ user_.arabic_name }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<p><strong>{{ _("Phone Number") }}:</strong> {{ user.phone_number }}</p>
|
<p><strong>{{ _("Phone Number") }}:</strong> {{ user_.phone_number }}</p>
|
||||||
<p><strong>{{ _("Address") }}:</strong> {{ user.address }}</p>
|
<p><strong>{{ _("Address") }}:</strong> {{ user_.address }}</p>
|
||||||
<p><strong>{{ _("Role") }}:</strong> {{ user.dealer_type }}</p>
|
<p><strong>{{ _("Role") }}:</strong> {{ user_.dealer_type }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer d-flex ">
|
<div class="card-footer d-flex ">
|
||||||
<a class="btn btn-sm btn-primary me-1" href="{% url 'user_update' user.id %}">
|
<a class="btn btn-sm btn-primary me-1" href="{% url 'user_update' user_.id %}">
|
||||||
<!--<i class="bi bi-pencil-square"></i> -->
|
<!--<i class="bi bi-pencil-square"></i> -->
|
||||||
{{ _("Edit") }}
|
{{ _("Edit") }}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@ -10,8 +10,7 @@
|
|||||||
<div class="d-flex flex-column flex-sm-grow-1 ms-sm-14 p-4">
|
<div class="d-flex flex-column flex-sm-grow-1 ms-sm-14 p-4">
|
||||||
<main class="d-grid gap-4 p-1">
|
<main class="d-grid gap-4 p-1">
|
||||||
<div class="row g-4">
|
<div class="row g-4">
|
||||||
<div class="col-lg-6 col-xl-12">
|
<div class="col-lg-6 col-xl-12">
|
||||||
|
|
||||||
<div class="container-fluid p-2">
|
<div class="container-fluid p-2">
|
||||||
<form method="get">
|
<form method="get">
|
||||||
<div class="input-group input-group-sm">
|
<div class="input-group input-group-sm">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user