diff --git a/inventory/admin.py b/inventory/admin.py
index 87c571a3..1bd2956f 100644
--- a/inventory/admin.py
+++ b/inventory/admin.py
@@ -38,7 +38,7 @@ admin.site.register(models.DealerSettings)
# admin.site.register(models.SaleQuotationCar)
admin.site.register(models.SaleOrder)
admin.site.register(models.CustomGroup)
-admin.site.register(models.CarFinance)
+# admin.site.register(models.CarFinance)
admin.site.register(models.CarColors)
admin.site.register(models.CarRegistration)
admin.site.register(models.CustomCard)
diff --git a/inventory/forms.py b/inventory/forms.py
index 4bdd23c6..b01426ea 100644
--- a/inventory/forms.py
+++ b/inventory/forms.py
@@ -32,7 +32,7 @@ from .models import (
Car,
VatRate,
CarTransfer,
- CarFinance,
+ # CarFinance,
CustomCard,
CarRegistration,
CarColors,
@@ -444,7 +444,7 @@ class CarFinanceForm(forms.ModelForm):
return cleaned_data
class Meta:
- model = CarFinance
+ model = Car
fields = ["cost_price","marked_price"]
diff --git a/inventory/models.py b/inventory/models.py
index 53dee7df..ab589f82 100644
--- a/inventory/models.py
+++ b/inventory/models.py
@@ -603,7 +603,6 @@ class AdditionalServices(models.Model, LocalizedNameMixin):
class Car(Base):
-
item_model = models.OneToOneField(
ItemModel,
models.DO_NOTHING,
@@ -668,6 +667,32 @@ class Car(Base):
default=CarStockTypeChoices.NEW,
verbose_name=_("Stock Type"),
)
+ #
+ additional_services = models.ManyToManyField(
+ AdditionalServices, related_name="additionals", blank=True,null=True
+ )
+ cost_price = models.DecimalField(
+ max_digits=14, decimal_places=2, verbose_name=_("Cost Price"),default=Decimal("0.00")
+ )
+ selling_price = models.DecimalField(
+ max_digits=14,
+ decimal_places=2,
+ verbose_name=_("Selling Price"),
+ default=Decimal("0.00"),
+ )
+ marked_price = models.DecimalField(
+ max_digits=14,
+ decimal_places=2,
+ verbose_name=_("Marked Price"),
+ default=Decimal("0.00"),
+ )
+ discount_amount = models.DecimalField(
+ max_digits=14,
+ decimal_places=2,
+ verbose_name=_("Discount Amount"),
+ default=Decimal("0.00"),
+ )
+ #
remarks = models.TextField(blank=True, null=True, verbose_name=_("Remarks"))
mileage = models.IntegerField(blank=True, null=True, verbose_name=_("Mileage"))
receiving_date = models.DateTimeField(verbose_name=_("Receiving Date"))
@@ -734,20 +759,16 @@ class Car(Base):
@property
def logo(self):
return getattr(self.id_car_make, "logo", "")
- @property
- def additional_services(self):
- return self.finances.additional_services.all()
- @property
- def total_additional_services(self):
- return sum([service.price_ for service in self.additional_services])
+ # @property
+ # def additional_services(self):
+ # return self.additional_services.all()
@property
def ready(self):
try:
return all(
[
self.colors,
- self.finances,
- self.finances.marked_price > 0,
+ self.marked_price > 0,
]
)
except Exception:
@@ -838,10 +859,51 @@ class Car(Base):
car=self, exterior=exterior, interior=interior
)
self.save()
-
@property
def logo(self):
return self.id_car_make.logo.url if self.id_car_make.logo else None
+ #
+ @property
+ def get_additional_services_amount(self):
+ return sum([Decimal(x.price_) for x in self.additional_services.all()])
+
+ def get_additional_services(self):
+ return {"services": [x for x in self.additional_services.all()],"total":self.get_additional_services_amount}
+
+ @property
+ def vat_amount(self):
+ vat = VatRate.objects.filter(dealer=self.dealer,is_active=True).first()
+ return Decimal(self.marked_price) * (vat.rate / 100)
+
+ @property
+ def total_vat(self):
+ return Decimal(self.marked_price) + Decimal(self.vat_amount)
+ # def get_discount_amount(self,estimate,user):
+ # try:
+ # instance = models.ExtraInfo.objects.get(
+ # dealer=self.dealer,
+ # content_object=estimate,
+ # related_object=user
+ # )
+ # if instance:
+ # return instance.data.get("discount",0)
+ # return 0
+ # except Exception:
+ # print("Error getting discount amount")
+ # return 0
+ # @property
+ # def total_discount(self):
+ # if self.discount_amount > 0:
+ # return self.marked_price - self.discount_amount
+ # return self.marked_price
+
+ # @property
+ # def total_vat(self):
+ # return round(self.total_discount + self.vat_amount + self.total_additionals, 2)
+
+
+
+
class CarTransfer(models.Model):
@@ -880,7 +942,7 @@ class CarTransfer(models.Model):
@property
def total_price(self):
- return self.quantity * self.car.finances.total_vat
+ return self.quantity * self.car.total_vat # TODO : check later
class Meta:
verbose_name = _("Car Transfer Log")
@@ -924,105 +986,105 @@ class CarReservation(models.Model):
# Car Finance Model
-class CarFinance(models.Model):
- additional_services = models.ManyToManyField(
- AdditionalServices, related_name="additional_finances", blank=True
- )
- 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")
- )
- selling_price = models.DecimalField(
- max_digits=14,
- decimal_places=2,
- verbose_name=_("Selling Price"),
- default=Decimal("0.00"),
- )
- marked_price = models.DecimalField(
- max_digits=14,
- decimal_places=2,
- verbose_name=_("Marked Price"),
- default=Decimal("0.00"),
- )
- discount_amount = models.DecimalField(
- max_digits=14,
- decimal_places=2,
- verbose_name=_("Discount Amount"),
- default=Decimal("0.00"),
- )
- # is_sold = models.BooleanField(default=False)
+# class CarFinance(models.Model):
+# additional_services = models.ManyToManyField(
+# AdditionalServices, related_name="additional_finances", blank=True
+# )
+# 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")
+# )
+# selling_price = models.DecimalField(
+# max_digits=14,
+# decimal_places=2,
+# verbose_name=_("Selling Price"),
+# default=Decimal("0.00"),
+# )
+# marked_price = models.DecimalField(
+# max_digits=14,
+# decimal_places=2,
+# verbose_name=_("Marked Price"),
+# default=Decimal("0.00"),
+# )
+# discount_amount = models.DecimalField(
+# max_digits=14,
+# decimal_places=2,
+# verbose_name=_("Discount Amount"),
+# default=Decimal("0.00"),
+# )
+# # is_sold = models.BooleanField(default=False)
- @property
- def total(self):
- return self.marked_price
+# @property
+# def total(self):
+# return self.marked_price
- @property
- def total_additionals_no_vat(self):
- return sum(x.price for x in self.additional_services.all())
+# @property
+# def total_additionals_no_vat(self):
+# return sum(x.price for x in self.additional_services.all())
- @property
- def total_additionals(self):
- return sum(x.price_ for x in self.additional_services.all())
+# @property
+# def total_additionals(self):
+# return sum(x.price_ for x in self.additional_services.all())
- @property
- def total_discount(self):
- if self.discount_amount > 0:
- return self.marked_price - self.discount_amount
- return self.marked_price
+# @property
+# def total_discount(self):
+# if self.discount_amount > 0:
+# return self.marked_price - self.discount_amount
+# return self.marked_price
- @property
- def total_vat(self):
- return round(self.total_discount + self.vat_amount + self.total_additionals, 2)
+# @property
+# def total_vat(self):
+# return round(self.total_discount + self.vat_amount + self.total_additionals, 2)
- @property
- def vat_amount(self):
- vat = VatRate.objects.filter(dealer=self.car.dealer, is_active=True).first()
- if vat:
- return (self.total_discount * Decimal(vat.rate)).quantize(Decimal("0.01"))
- return Decimal("0.00")
+# @property
+# def vat_amount(self):
+# vat = VatRate.objects.filter(dealer=self.car.dealer, is_active=True).first()
+# if vat:
+# return (self.total_discount * Decimal(vat.rate)).quantize(Decimal("0.01"))
+# return Decimal("0.00")
- @property
- def revenue(self):
- return self.marked_price - self.cost_price
+# @property
+# def revenue(self):
+# return self.marked_price - self.cost_price
- def to_dict(self):
- return {
- "cost_price": str(self.cost_price),
- "selling_price": str(self.selling_price),
- "marked_price": str(self.marked_price),
- "discount_amount": str(self.discount_amount),
- "total": str(self.total),
- "total_discount": str(self.total_discount),
- "total_vat": str(self.total_vat),
- "vat_amount": str(self.vat_amount),
- }
+# def to_dict(self):
+# return {
+# "cost_price": str(self.cost_price),
+# "selling_price": str(self.selling_price),
+# "marked_price": str(self.marked_price),
+# "discount_amount": str(self.discount_amount),
+# "total": str(self.total),
+# "total_discount": str(self.total_discount),
+# "total_vat": str(self.total_vat),
+# "vat_amount": str(self.vat_amount),
+# }
- def __str__(self):
- return f"Car: {self.car}, Marked Price: {self.marked_price}"
+# def __str__(self):
+# return f"Car: {self.car}, Marked Price: {self.marked_price}"
- # def save(self, *args, **kwargs):
- # self.full_clean()
- # try:
- # price_after_discount = self.selling_price - self.discount_amount
- # self.profit_margin = price_after_discount - self.cost_price
- # self.vat_amount = settings.VAT_RATE
- # except InvalidOperation as e:
- # raise ValidationError(_("Invalid decimal operation: %s") % str(e))
- # super().save(*args, **kwargs)
+# # def save(self, *args, **kwargs):
+# # self.full_clean()
+# # try:
+# # price_after_discount = self.selling_price - self.discount_amount
+# # self.profit_margin = price_after_discount - self.cost_price
+# # self.vat_amount = settings.VAT_RATE
+# # except InvalidOperation as e:
+# # raise ValidationError(_("Invalid decimal operation: %s") % str(e))
+# # super().save(*args, **kwargs)
- class Meta:
- verbose_name = _("Car Financial Details")
- verbose_name_plural = _("Car Financial Details")
- indexes = [
- models.Index(fields=["car"], name="car_finance_car_idx"),
- models.Index(fields=["cost_price"], name="car_finance_cost_price_idx"),
- models.Index(
- fields=["selling_price"], name="car_finance_selling_price_idx"
- ),
- models.Index(fields=["marked_price"], name="car_finance_marked_price_idx"),
- models.Index(fields=["discount_amount"], name="car_finance_discount_idx"),
- ]
+# class Meta:
+# verbose_name = _("Car Financial Details")
+# verbose_name_plural = _("Car Financial Details")
+# indexes = [
+# models.Index(fields=["car"], name="car_finance_car_idx"),
+# models.Index(fields=["cost_price"], name="car_finance_cost_price_idx"),
+# models.Index(
+# fields=["selling_price"], name="car_finance_selling_price_idx"
+# ),
+# models.Index(fields=["marked_price"], name="car_finance_marked_price_idx"),
+# models.Index(fields=["discount_amount"], name="car_finance_discount_idx"),
+# ]
class ExteriorColors(models.Model, LocalizedNameMixin):
@@ -2875,7 +2937,7 @@ class SaleOrder(models.Model):
@property
def price(self):
- return self.car.finances.marked_price
+ return self.car.marked_price
@property
def items(self):
diff --git a/inventory/signals.py b/inventory/signals.py
index 21947d35..aa3dbf5e 100644
--- a/inventory/signals.py
+++ b/inventory/signals.py
@@ -270,6 +270,9 @@ def create_item_model(sender, instance, created, **kwargs):
)
instance.item_model = inventory
inventory.save()
+ else:
+ instance.item_model.default_amount = instance.marked_price
+
# inventory = entity.create_item_inventory(
# name=instance.vin,
# uom_model=uom,
@@ -284,108 +287,108 @@ def create_item_model(sender, instance, created, **kwargs):
# # update price - CarFinance
-@receiver(post_save, sender=models.CarFinance)
-def update_item_model_cost(sender, instance, created, **kwargs):
- """
- Signal handler for updating an inventory item's cost and additional information
- when a CarFinance instance is saved. This function updates the corresponding
- inventory item of the car dealer's entity associated with the car's VIN by
- modifying its default amount and updating additional data fields.
+# @receiver(post_save, sender=models.CarFinance)
+# def update_item_model_cost(sender, instance, created, **kwargs):
+# """
+# Signal handler for updating an inventory item's cost and additional information
+# when a CarFinance instance is saved. This function updates the corresponding
+# inventory item of the car dealer's entity associated with the car's VIN by
+# modifying its default amount and updating additional data fields.
- :param sender: The model class that triggered the signal.
- :param instance: The instance of the CarFinance that was saved.
- :param created: A boolean indicating whether the model instance was newly created.
- :param kwargs: Additional keyword arguments passed during the signal invocation.
- :return: None
- """
- # if created and not instance.is_sold:
- # if created:
- # entity = instance.car.dealer.entity
- # coa = entity.get_default_coa()
- # inventory_account = (
- # entity.get_all_accounts()
- # .filter(name=f"Inventory:{instance.car.id_car_make.name}")
- # .first()
- # )
- # if not inventory_account:
- # inventory_account = create_make_accounts(
- # entity,
- # coa,
- # [instance.car.id_car_make],
- # "Inventory",
- # roles.ASSET_CA_INVENTORY,
- # "debit",
- # )
+# :param sender: The model class that triggered the signal.
+# :param instance: The instance of the CarFinance that was saved.
+# :param created: A boolean indicating whether the model instance was newly created.
+# :param kwargs: Additional keyword arguments passed during the signal invocation.
+# :return: None
+# """
+# # if created and not instance.is_sold:
+# # if created:
+# # entity = instance.car.dealer.entity
+# # coa = entity.get_default_coa()
+# # inventory_account = (
+# # entity.get_all_accounts()
+# # .filter(name=f"Inventory:{instance.car.id_car_make.name}")
+# # .first()
+# # )
+# # if not inventory_account:
+# # inventory_account = create_make_accounts(
+# # entity,
+# # coa,
+# # [instance.car.id_car_make],
+# # "Inventory",
+# # roles.ASSET_CA_INVENTORY,
+# # "debit",
+# # )
- # cogs = (
- # entity.get_all_accounts()
- # .filter(name=f"Cogs:{instance.car.id_car_make.name}")
- # .first()
- # )
- # if not cogs:
- # cogs = create_make_accounts(
- # entity, coa, [instance.car.id_car_make], "Cogs", roles.COGS, "debit"
- # )
- # revenue = (
- # entity.get_all_accounts()
- # .filter(name=f"Revenue:{instance.car.id_car_make.name}")
- # .first()
- # )
- # if not revenue:
- # revenue = create_make_accounts(
- # entity,
- # coa,
- # [instance.car.id_car_make],
- # "Revenue",
- # roles.ASSET_CA_RECEIVABLES,
- # "credit",
- # )
+# # cogs = (
+# # entity.get_all_accounts()
+# # .filter(name=f"Cogs:{instance.car.id_car_make.name}")
+# # .first()
+# # )
+# # if not cogs:
+# # cogs = create_make_accounts(
+# # entity, coa, [instance.car.id_car_make], "Cogs", roles.COGS, "debit"
+# # )
+# # revenue = (
+# # entity.get_all_accounts()
+# # .filter(name=f"Revenue:{instance.car.id_car_make.name}")
+# # .first()
+# # )
+# # if not revenue:
+# # revenue = create_make_accounts(
+# # entity,
+# # coa,
+# # [instance.car.id_car_make],
+# # "Revenue",
+# # roles.ASSET_CA_RECEIVABLES,
+# # "credit",
+# # )
- # cash_account = (
- # # entity.get_all_accounts()
- # # .filter(name="Cash", role=roles.ASSET_CA_CASH)
- # # .first()
- # entity.get_all_accounts()
- # .filter(role=roles.ASSET_CA_CASH, role_default=True)
- # .first()
- # )
+# # cash_account = (
+# # # entity.get_all_accounts()
+# # # .filter(name="Cash", role=roles.ASSET_CA_CASH)
+# # # .first()
+# # entity.get_all_accounts()
+# # .filter(role=roles.ASSET_CA_CASH, role_default=True)
+# # .first()
+# # )
- # ledger = LedgerModel.objects.create(
- # entity=entity, name=f"Inventory Purchase - {instance.car}"
- # )
- # je = JournalEntryModel.objects.create(
- # ledger=ledger,
- # description=f"Acquired {instance.car} for inventory",
- # )
- # TransactionModel.objects.create(
- # journal_entry=je,
- # account=inventory_account,
- # amount=Decimal(instance.cost_price),
- # tx_type="debit",
- # description="",
- # )
+# # ledger = LedgerModel.objects.create(
+# # entity=entity, name=f"Inventory Purchase - {instance.car}"
+# # )
+# # je = JournalEntryModel.objects.create(
+# # ledger=ledger,
+# # description=f"Acquired {instance.car} for inventory",
+# # )
+# # TransactionModel.objects.create(
+# # journal_entry=je,
+# # account=inventory_account,
+# # amount=Decimal(instance.cost_price),
+# # tx_type="debit",
+# # description="",
+# # )
- # TransactionModel.objects.create(
- # journal_entry=je,
- # account=cash_account,
- # amount=Decimal(instance.cost_price),
- # tx_type="credit",
- # description="",
- # )
+# # TransactionModel.objects.create(
+# # journal_entry=je,
+# # account=cash_account,
+# # amount=Decimal(instance.cost_price),
+# # tx_type="credit",
+# # description="",
+# # )
- instance.car.item_model.default_amount = instance.marked_price
- # if not isinstance(instance.car.item_model.additional_info, dict):
- # instance.car.item_model.additional_info = {}
- # instance.car.item_model.additional_info.update({"car_finance": instance.to_dict()})
- # instance.car.item_model.additional_info.update(
- # {
- # "additional_services": [
- # service.to_dict() for service in instance.additional_services.all()
- # ]
- # }
- # )
- instance.car.item_model.save()
- print(f"Inventory item updated with CarFinance data for Car: {instance.car}")
+# instance.car.item_model.default_amount = instance.marked_price
+# # if not isinstance(instance.car.item_model.additional_info, dict):
+# # instance.car.item_model.additional_info = {}
+# # instance.car.item_model.additional_info.update({"car_finance": instance.to_dict()})
+# # instance.car.item_model.additional_info.update(
+# # {
+# # "additional_services": [
+# # service.to_dict() for service in instance.additional_services.all()
+# # ]
+# # }
+# # )
+# instance.car.item_model.save()
+# print(f"Inventory item updated with CarFinance data for Car: {instance.car}")
# @receiver(pre_save, sender=models.SaleQuotation)
@@ -803,144 +806,144 @@ def create_dealer_settings(sender, instance, created, **kwargs):
# )
-def save_journal(car_finance, ledger, vendor):
- """
- Saves a journal entry pertaining to a car finance transaction for a specific ledger and vendor.
+# def save_journal(car_finance, ledger, vendor):
+# """
+# Saves a journal entry pertaining to a car finance transaction for a specific ledger and vendor.
- This function ensures that relevant accounts are updated to record financial transactions. It handles
- debiting of the inventory account and crediting of the vendor account to maintain accurate bookkeeping.
- Additionally, it creates vendor accounts dynamically if required and ties the created journal entry to
- the ledger passed as a parameter. All transactions adhere to the ledger's entity-specific Chart of
- Accounts (COA) configuration.
+# This function ensures that relevant accounts are updated to record financial transactions. It handles
+# debiting of the inventory account and crediting of the vendor account to maintain accurate bookkeeping.
+# Additionally, it creates vendor accounts dynamically if required and ties the created journal entry to
+# the ledger passed as a parameter. All transactions adhere to the ledger's entity-specific Chart of
+# Accounts (COA) configuration.
- :param car_finance: Instance of the car finance object containing details about the financed car
- and its associated costs.
- :type car_finance: `CarFinance` object
- :param ledger: Ledger instance to which the journal entry is tied. This ledger must provide
- entity-specific details, including its COA and related accounts.
- :type ledger: `Ledger` object
- :param vendor: Vendor instance representing the supplier or vendor related to the car finance
- transaction. This vendor is used to derive or create the vendor account in COA.
- :type vendor: `Vendor` object
+# :param car_finance: Instance of the car finance object containing details about the financed car
+# and its associated costs.
+# :type car_finance: `CarFinance` object
+# :param ledger: Ledger instance to which the journal entry is tied. This ledger must provide
+# entity-specific details, including its COA and related accounts.
+# :type ledger: `Ledger` object
+# :param vendor: Vendor instance representing the supplier or vendor related to the car finance
+# transaction. This vendor is used to derive or create the vendor account in COA.
+# :type vendor: `Vendor` object
- :return: None
- """
- entity = ledger.entity
- coa = entity.get_default_coa()
- journal = JournalEntryModel.objects.create(
- posted=False,
- description=f"Finances of Car:{car_finance.car.vin} for Vendor:{car_finance.car.vendor.name}",
- ledger=ledger,
- locked=False,
- origin="Payment",
- )
- ledger.additional_info["je_number"] = journal.je_number
- ledger.save()
+# :return: None
+# """
+# entity = ledger.entity
+# coa = entity.get_default_coa()
+# journal = JournalEntryModel.objects.create(
+# posted=False,
+# description=f"Finances of Car:{car_finance.car.vin} for Vendor:{car_finance.car.vendor.name}",
+# ledger=ledger,
+# locked=False,
+# origin="Payment",
+# )
+# ledger.additional_info["je_number"] = journal.je_number
+# ledger.save()
- inventory_account = (
- entity.get_default_coa_accounts().filter(role=roles.ASSET_CA_INVENTORY).first()
- )
- vendor_account = entity.get_default_coa_accounts().filter(name=vendor.name).first()
+# inventory_account = (
+# entity.get_default_coa_accounts().filter(role=roles.ASSET_CA_INVENTORY).first()
+# )
+# vendor_account = entity.get_default_coa_accounts().filter(name=vendor.name).first()
- if not vendor_account:
- last_account = (
- entity.get_all_accounts()
- .filter(role=roles.LIABILITY_CL_ACC_PAYABLE)
- .order_by("-created")
- .first()
- )
- if len(last_account.code) == 4:
- code = f"{int(last_account.code)}{1:03d}"
- elif len(last_account.code) > 4:
- code = f"{int(last_account.code) + 1}"
+# if not vendor_account:
+# last_account = (
+# entity.get_all_accounts()
+# .filter(role=roles.LIABILITY_CL_ACC_PAYABLE)
+# .order_by("-created")
+# .first()
+# )
+# if len(last_account.code) == 4:
+# code = f"{int(last_account.code)}{1:03d}"
+# elif len(last_account.code) > 4:
+# code = f"{int(last_account.code) + 1}"
- vendor_account = entity.create_account(
- name=vendor.name,
- code=code,
- role=roles.LIABILITY_CL_ACC_PAYABLE,
- coa_model=coa,
- balance_type="credit",
- active=True,
- )
- additional_services_account = (
- entity.get_default_coa_accounts()
- .filter(name="Additional Services", role=roles.COGS)
- .first()
- )
+# vendor_account = entity.create_account(
+# name=vendor.name,
+# code=code,
+# role=roles.LIABILITY_CL_ACC_PAYABLE,
+# coa_model=coa,
+# balance_type="credit",
+# active=True,
+# )
+# additional_services_account = (
+# entity.get_default_coa_accounts()
+# .filter(name="Additional Services", role=roles.COGS)
+# .first()
+# )
- # Debit Inventory Account
- TransactionModel.objects.create(
- journal_entry=journal,
- account=inventory_account,
- amount=car_finance.cost_price,
- tx_type="debit",
- )
+# # Debit Inventory Account
+# TransactionModel.objects.create(
+# journal_entry=journal,
+# account=inventory_account,
+# amount=car_finance.cost_price,
+# tx_type="debit",
+# )
- # Credit Vendor Account
- TransactionModel.objects.create(
- journal_entry=journal,
- account=vendor_account,
- amount=car_finance.cost_price,
- tx_type="credit",
- )
+# # Credit Vendor Account
+# TransactionModel.objects.create(
+# journal_entry=journal,
+# account=vendor_account,
+# amount=car_finance.cost_price,
+# tx_type="credit",
+# )
-@receiver(post_save, sender=models.CarFinance)
-def update_finance_cost(sender, instance, created, **kwargs):
- """
- Signal to handle `post_save` functionality for the `CarFinance` model. This function
- creates or updates financial records related to a car's finance details in the ledger
- associated with the car's vendor and dealer. For newly created instances, a ledger is
- created or retrieved, and the `save_journal` function is executed to log the financial
- transactions.
+# @receiver(post_save, sender=models.CarFinance)
+# def update_finance_cost(sender, instance, created, **kwargs):
+# """
+# Signal to handle `post_save` functionality for the `CarFinance` model. This function
+# creates or updates financial records related to a car's finance details in the ledger
+# associated with the car's vendor and dealer. For newly created instances, a ledger is
+# created or retrieved, and the `save_journal` function is executed to log the financial
+# transactions.
- This function also has commented-out logic to handle updates for already created
- instances, including journal updates or adjustments to existing financial transactions.
+# This function also has commented-out logic to handle updates for already created
+# instances, including journal updates or adjustments to existing financial transactions.
- :param sender: Model class that triggered the signal
- :type sender: Model
- :param instance: Instance of the `CarFinance` model passed to the signal
- :type instance: CarFinance
- :param created: Boolean value indicating if the instance was created (`True`) or updated (`False`)
- :type created: bool
- :param kwargs: Arbitrary keyword arguments passed to the signal
- :type kwargs: dict
- :return: None
- """
- if created:
- entity = instance.car.dealer.entity
- vendor = instance.car.vendor
- vin = instance.car.vin if instance.car.vin else ""
- make = instance.car.id_car_make.name if instance.car.id_car_make else ""
- model = instance.car.id_car_model.name if instance.car.id_car_model else ""
- year = instance.car.year
- vendor_name = vendor.name if vendor else ""
+# :param sender: Model class that triggered the signal
+# :type sender: Model
+# :param instance: Instance of the `CarFinance` model passed to the signal
+# :type instance: CarFinance
+# :param created: Boolean value indicating if the instance was created (`True`) or updated (`False`)
+# :type created: bool
+# :param kwargs: Arbitrary keyword arguments passed to the signal
+# :type kwargs: dict
+# :return: None
+# """
+# if created:
+# entity = instance.car.dealer.entity
+# vendor = instance.car.vendor
+# vin = instance.car.vin if instance.car.vin else ""
+# make = instance.car.id_car_make.name if instance.car.id_car_make else ""
+# model = instance.car.id_car_model.name if instance.car.id_car_model else ""
+# year = instance.car.year
+# vendor_name = vendor.name if vendor else ""
- name = f"{vin}-{make}-{model}-{year}-{vendor_name}"
- ledger, _ = LedgerModel.objects.get_or_create(name=name, entity=entity)
- save_journal(instance, ledger, vendor)
+# name = f"{vin}-{make}-{model}-{year}-{vendor_name}"
+# ledger, _ = LedgerModel.objects.get_or_create(name=name, entity=entity)
+# save_journal(instance, ledger, vendor)
- # if not created:
- # if ledger.additional_info.get("je_number"):
- # journal = JournalEntryModel.objects.filter(je_number=ledger.additional_info.get("je_number")).first()
- # journal.description = f"Finances of Car:{instance.car.vin} for Vendor:{instance.car.vendor.vendor_name}"
- # journal.save()
- # debit = journal.get_transaction_queryset().filter(tx_type='debit').first()
- # credit = journal.get_transaction_queryset().filter(tx_type='credit').first()
- # if debit and credit:
- # if journal.is_locked():
- # journal.mark_as_unlocked()
- # journal.save()
- # debit.amount = instance.cost_price
- # credit.amount = instance.cost_price
- # debit.save()
- # credit.save()
- # else:
- # save_journal(instance,ledger,vendor,journal=journal)
- # else:
- # save_journal(instance,ledger,vendor)
- # else:
- # save_journal(instance,ledger,vendor)
+# # if not created:
+# # if ledger.additional_info.get("je_number"):
+# # journal = JournalEntryModel.objects.filter(je_number=ledger.additional_info.get("je_number")).first()
+# # journal.description = f"Finances of Car:{instance.car.vin} for Vendor:{instance.car.vendor.vendor_name}"
+# # journal.save()
+# # debit = journal.get_transaction_queryset().filter(tx_type='debit').first()
+# # credit = journal.get_transaction_queryset().filter(tx_type='credit').first()
+# # if debit and credit:
+# # if journal.is_locked():
+# # journal.mark_as_unlocked()
+# # journal.save()
+# # debit.amount = instance.cost_price
+# # credit.amount = instance.cost_price
+# # debit.save()
+# # credit.save()
+# # else:
+# # save_journal(instance,ledger,vendor,journal=journal)
+# # else:
+# # save_journal(instance,ledger,vendor)
+# # else:
+# # save_journal(instance,ledger,vendor)
@receiver(post_save, sender=PurchaseOrderModel)
diff --git a/inventory/urls.py b/inventory/urls.py
index 29affe5b..ea1bb30d 100644
--- a/inventory/urls.py
+++ b/inventory/urls.py
@@ -348,13 +348,8 @@ urlpatterns = [
name="car_delete",
),
path(
- "Chart of Accounts
+
+ {% icon 'carbon:add-alt' 24 %} Add New
+
+
+
+
- {{ opportunity.car.finances.total }}
+ {{ opportunity.car.total }} # TODO : check later
{% endif %}
{{ opportunity.car.finances.total }}
+{{ opportunity.car.total }}
# TODO : check later- {{ opportunity.car.finances.total }} + {{ opportunity.car.total }}# TODO : check later
{{ _("This car information is not complete , please add colors and finances both before making it ready for sale .") }}
- {% elif car.finances and not car.colors %} + {% elif car.marked_price and not car.colors %}{{ _("This car information is not complete , please add colors before making it ready for sale .") }}
@@ -205,7 +205,7 @@