Merge branch 'main' of http://10.10.1.136:3000/ismail/haikal into frontend
This commit is contained in:
commit
0d24584c81
@ -5,8 +5,4 @@ class InventoryConfig(AppConfig):
|
||||
name = 'inventory'
|
||||
|
||||
def ready(self):
|
||||
pass
|
||||
#from decimal import Decimal
|
||||
#from inventory.models import VatRate
|
||||
#VatRate.objects.get_or_create(rate=Decimal('0.15'), is_active=True)
|
||||
|
||||
import inventory.signals
|
||||
|
||||
20
inventory/migrations/0009_car_item_model.py
Normal file
20
inventory/migrations/0009_car_item_model.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.7 on 2025-05-25 11:41
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('django_ledger', '0021_alter_bankaccountmodel_account_model_and_more'),
|
||||
('inventory', '0008_lead_salary'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='car',
|
||||
name='item_model',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='cars', to='django_ledger.itemmodel', verbose_name='Item Model'),
|
||||
),
|
||||
]
|
||||
20
inventory/migrations/0010_alter_car_item_model.py
Normal file
20
inventory/migrations/0010_alter_car_item_model.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.7 on 2025-05-25 11:43
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('django_ledger', '0021_alter_bankaccountmodel_account_model_and_more'),
|
||||
('inventory', '0009_car_item_model'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='car',
|
||||
name='item_model',
|
||||
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='cars', to='django_ledger.itemmodel', verbose_name='Item Model'),
|
||||
),
|
||||
]
|
||||
20
inventory/migrations/0011_alter_car_item_model.py
Normal file
20
inventory/migrations/0011_alter_car_item_model.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.7 on 2025-05-25 11:44
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('django_ledger', '0021_alter_bankaccountmodel_account_model_and_more'),
|
||||
('inventory', '0010_alter_car_item_model'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='car',
|
||||
name='item_model',
|
||||
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='django_ledger.itemmodel', verbose_name='Item Model'),
|
||||
),
|
||||
]
|
||||
@ -458,6 +458,13 @@ class AdditionalServices(models.Model, LocalizedNameMixin):
|
||||
|
||||
|
||||
class Car(Base):
|
||||
item_model = models.OneToOneField(
|
||||
ItemModel,
|
||||
models.DO_NOTHING,
|
||||
verbose_name=_("Item Model"),
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
vin = models.CharField(max_length=17, unique=True, verbose_name=_("VIN"))
|
||||
dealer = models.ForeignKey(
|
||||
"Dealer", models.DO_NOTHING, related_name="cars", verbose_name=_("Dealer")
|
||||
@ -562,7 +569,7 @@ class Car(Base):
|
||||
color = ""
|
||||
try:
|
||||
color = self.colors.exterior.name if self.colors else ""
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
make = self.id_car_make.name if self.id_car_make else ""
|
||||
model = self.id_car_model.name if self.id_car_model else ""
|
||||
@ -572,12 +579,10 @@ class Car(Base):
|
||||
hash_object.update(f"{make}{model}{year}{serie}{trim}{color}".encode('utf-8'))
|
||||
return hash_object.hexdigest()
|
||||
|
||||
def mark_as_sold(self,request):
|
||||
dealer = get_user_type(request)
|
||||
def mark_as_sold(self):
|
||||
self.cancel_reservation()
|
||||
self.status = CarStatusChoices.SOLD
|
||||
self.save()
|
||||
Activity.objects.create(dealer=dealer,content_object=self, notes=_("Car Sold"),created_by=request.user,activity_type=ActionChoices.SALE_CAR)
|
||||
|
||||
def cancel_reservation(self):
|
||||
if self.reservations.exists():
|
||||
|
||||
@ -202,23 +202,25 @@ def create_item_model(sender, instance, created, **kwargs):
|
||||
:return: None
|
||||
"""
|
||||
entity = instance.dealer.entity
|
||||
|
||||
if created:
|
||||
coa = entity.get_default_coa()
|
||||
uom = entity.get_uom_all().get(name="Unit")
|
||||
|
||||
if not entity.get_items_all().filter(name=instance.vin).exists():
|
||||
if not instance.item_model:
|
||||
product = entity.create_item_product(
|
||||
name=instance.vin,
|
||||
item_type=ItemModel.ITEM_TYPE_MATERIAL,
|
||||
uom_model=uom,
|
||||
coa_model=coa,
|
||||
)
|
||||
instance.item_model = product
|
||||
product.additional_info = {}
|
||||
product.additional_info.update({'car_info': instance.to_dict()})
|
||||
product.save()
|
||||
|
||||
product = entity.get_items_all().filter(name=instance.vin).first()
|
||||
product.additional_info.update({'car_info': instance.to_dict()})
|
||||
product.save()
|
||||
else:
|
||||
instance.item_model.additional_info.update({'car_info': instance.to_dict()})
|
||||
instance.item_model.save()
|
||||
|
||||
# # update price - CarFinance
|
||||
@receiver(post_save, sender=models.CarFinance)
|
||||
@ -235,16 +237,14 @@ def update_item_model_cost(sender, instance, created, **kwargs):
|
||||
:param kwargs: Additional keyword arguments passed during the signal invocation.
|
||||
:return: None
|
||||
"""
|
||||
entity = instance.car.dealer.entity
|
||||
|
||||
product = entity.get_items_all().filter(name=instance.car.vin).first()
|
||||
|
||||
product.default_amount = instance.selling_price
|
||||
if not isinstance(product.additional_info, dict):
|
||||
product.additional_info = {}
|
||||
product.additional_info.update({"car_finance":instance.to_dict()})
|
||||
product.additional_info.update({"additional_services": [service.to_dict() for service in instance.additional_services.all()]})
|
||||
product.save()
|
||||
instance.car.item_model.default_amount = instance.selling_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}")
|
||||
|
||||
|
||||
|
||||
@ -1141,7 +1141,8 @@ def handle_account_process(invoice,amount,finance_data):
|
||||
:return: None
|
||||
"""
|
||||
for i in invoice.get_itemtxs_data()[0]:
|
||||
car = models.Car.objects.get(vin=invoice.get_itemtxs_data()[0].first().item_model.name)
|
||||
# car = models.Car.objects.get(vin=invoice.get_itemtxs_data()[0].first().item_model.name)
|
||||
car = i.item_model.car
|
||||
entity = invoice.ledger.entity
|
||||
coa = entity.get_default_coa()
|
||||
|
||||
|
||||
@ -3898,7 +3898,11 @@ def create_sale_order(request, pk):
|
||||
item.item_model.save()
|
||||
except KeyError:
|
||||
pass
|
||||
models.Car.objects.get(vin=item.item_model.name).mark_as_sold(request)
|
||||
dealer = get_user_type(request)
|
||||
|
||||
item.item_model.car.mark_as_sold()
|
||||
# models.Activity.objects.create(dealer=dealer,content_object=item.item_model.car, notes="Car Sold",created_by=request.user,activity_type=models.ActionChoices.SALE_CAR)
|
||||
|
||||
|
||||
messages.success(request, "Sale Order created successfully")
|
||||
return redirect("estimate_detail", pk=estimate.pk)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
<div class="modal fade" id="deleteModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content rounded">
|
||||
@ -56,9 +56,9 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row mt-4">
|
||||
|
||||
|
||||
<div class="table-responsive px-1 scrollbar mt-3">
|
||||
<table class="table align-items-center table-flush">
|
||||
<thead>
|
||||
@ -91,7 +91,9 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="align-middle product white-space-nowrap">
|
||||
{% if tx.description %}
|
||||
{{ tx.description }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="align-middle white-space-nowrap text-start">
|
||||
<div class="btn-reveal-trigger position-static">
|
||||
@ -106,7 +108,7 @@
|
||||
|
||||
<tr class="hover-actions-trigger btn-reveal-trigger position-static">
|
||||
<td class="align-middle product white-space-nowrap">
|
||||
|
||||
|
||||
</td>
|
||||
<td class="align-middle product white-space-nowrap">
|
||||
<span class="fw-bold fs-8">{{ _("Total") }}</span>
|
||||
@ -118,20 +120,20 @@
|
||||
<span class="fw-bold fs-8 text-danger">{{ total_credits }} <span class="currency">{{ CURRENCY }}</span></span>
|
||||
</td>
|
||||
<td class="align-middle product white-space-nowrap">
|
||||
|
||||
|
||||
</td>
|
||||
<td class="align-middle white-space-nowrap text-start">
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="mt-3 d-flex">
|
||||
<a class="btn btn-sm btn-phoenix-primary me-1" href="{% url 'account_update' account.pk %}">
|
||||
<!-- <i class="bi bi-pencil-square"></i> -->
|
||||
|
||||
@ -275,7 +275,7 @@
|
||||
|
||||
|
||||
// Run the function on page load
|
||||
//window.onload = calculateTotals;
|
||||
//window.onload = calculateTotals;
|
||||
|
||||
function setFormAction(action) {
|
||||
// Get the form element
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user