This commit is contained in:
Marwan Alwali 2025-01-06 21:55:48 +03:00
parent f7a43a3b22
commit b8b388262a
8 changed files with 159177 additions and 26 deletions

BIN
.DS_Store vendored

Binary file not shown.

Binary file not shown.

38
import_data.py Normal file
View File

@ -0,0 +1,38 @@
import json
# Load JSON data
with open("haikaldb.json", "r") as file:
data = json.load(file)
car_generation = data.get("car_generation", [])
car_serie = data.get("car_serie", [])
# Create a lookup dictionary for car_generation by id
generation_lookup = {gen["id_car_generation"]: gen for gen in car_generation}
# Merge car_generation and car_serie
merged_data = []
for serie in car_serie:
gen_id = serie["id_car_generation"]
generation = generation_lookup.get(gen_id, {})
merged_entry = {
"id_car_generation_serie": serie["id_car_serie"], # Use car_serie ID as the merged ID
"id_car_model": generation.get("id_car_model"),
"name": f"{generation.get('name', '')} {serie.get('name', '')}".strip(),
# "arabic_name": f"{generation.get('arabic_name', '')} {serie.get('arabic_name', '')}".strip(),
"year_begin": generation.get("year_begin"),
"year_end": generation.get("year_end"),
"generation_name": generation.get("name"),
"serie_name": serie.get("name"),
# "arabic_generation_name": generation.get("arabic_name"),
"arabic_serie_name": serie.get("arabic_name"),
}
merged_data.append(merged_entry)
# Write merged data to a new JSON file
with open("merged_car_generation_serie.json", "w") as file:
json.dump(merged_data, file, indent=4, ensure_ascii=False)
print("Merging completed. Data saved to merged_car_generation_serie.json.")

BIN
inventory/data/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -67,8 +67,8 @@ class VatRate(models.Model):
class CarMake(models.Model, LocalizedNameMixin):
id_car_make = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
arabic_name = models.CharField(max_length=255)
name = models.CharField(max_length=255, blank=True, null=True)
arabic_name = models.CharField(max_length=255, blank=True, null=True)
logo = models.ImageField(_("logo"), upload_to="car_make", blank=True, null=True)
is_sa_import = models.BooleanField(default=False)
@ -82,8 +82,8 @@ class CarMake(models.Model, LocalizedNameMixin):
class CarModel(models.Model, LocalizedNameMixin):
id_car_model = models.AutoField(primary_key=True)
id_car_make = models.ForeignKey(CarMake, models.DO_NOTHING, db_column="id_car_make")
name = models.CharField(max_length=255)
arabic_name = models.CharField(max_length=255)
name = models.CharField(max_length=255, blank=True, null=True)
arabic_name = models.CharField(max_length=255, blank=True, null=True)
def __str__(self):
return self.name
@ -92,11 +92,24 @@ class CarModel(models.Model, LocalizedNameMixin):
verbose_name = "Model"
class CarGeneration(models.Model):
id_car_generation = models.AutoField(primary_key=True)
id_car_model = models.ForeignKey(CarModel, models.DO_NOTHING, db_column='id_car_model')
name = models.CharField(max_length=255, blank=True, null=True)
arabic_name = models.CharField(max_length=255, blank=True, null=True)
year_begin = models.CharField(max_length=255, blank=True, null=True)
year_end = models.CharField(max_length=255, blank=True, null=True)
def __str__(self):
return self.name
class Meta:
verbose_name = "Generation"
class CarSerie(models.Model, LocalizedNameMixin):
id_car_serie = models.AutoField(primary_key=True)
id_car_model = models.ForeignKey(
CarModel, models.DO_NOTHING, db_column="id_car_model"
)
id_car_model = models.ForeignKey(CarModel, models.DO_NOTHING, db_column="id_car_model")
name = models.CharField(max_length=255)
arabic_name = models.CharField(max_length=255)
year_begin = models.IntegerField(blank=True, null=True)
@ -111,9 +124,7 @@ class CarSerie(models.Model, LocalizedNameMixin):
class CarTrim(models.Model, LocalizedNameMixin):
id_car_trim = models.AutoField(primary_key=True)
id_car_serie = models.ForeignKey(
CarSerie, models.DO_NOTHING, db_column="id_car_serie"
)
id_car_serie = models.ForeignKey(CarSerie, models.DO_NOTHING, db_column="id_car_serie")
name = models.CharField(max_length=255)
arabic_name = models.CharField(max_length=255)
start_production_year = models.IntegerField(blank=True, null=True)
@ -127,13 +138,15 @@ class CarTrim(models.Model, LocalizedNameMixin):
verbose_name = "Trim"
class CarEquipment(models.Model, LocalizedNameMixin):
id_car_equipment = models.AutoField(primary_key=True)
class CarSpecification(models.Model, LocalizedNameMixin):
id_car_specification = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
arabic_name = models.CharField(max_length=255)
id_parent = models.ForeignKey(
"self", models.DO_NOTHING, db_column="id_parent", blank=True, null=True
)
id_parent = models.ForeignKey("self", models.DO_NOTHING, db_column="id_parent", blank=True, null=True)
def __str__(self):
return self.name
@ -145,9 +158,7 @@ class CarSpecification(models.Model, LocalizedNameMixin):
class CarSpecificationValue(models.Model):
id_car_specification_value = models.AutoField(primary_key=True)
id_car_trim = models.ForeignKey(CarTrim, models.DO_NOTHING, db_column="id_car_trim")
id_car_specification = models.ForeignKey(
CarSpecification, models.DO_NOTHING, db_column="id_car_specification"
)
id_car_specification = models.ForeignKey(CarSpecification, models.DO_NOTHING, db_column="id_car_specification")
value = models.CharField(max_length=500)
unit = models.CharField(max_length=255, blank=True, null=True)

View File

@ -1,9 +1,4 @@
import requests
from django.test import Client
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import Paginator
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
from django_ledger.models import (
EntityModel,
InvoiceModel,
@ -30,7 +25,6 @@ from django.contrib.admin.models import LogEntry
import logging
import json
import datetime
from decimal import Decimal
from django.db.models.functions import Coalesce
from django.shortcuts import HttpResponse
from django.contrib.auth.mixins import LoginRequiredMixin
@ -56,14 +50,10 @@ from django.contrib import messages
from django.db.models import Sum, F, Count
from django.db import transaction
from .models import Customer
from .services import (
elm,
decodevin,
get_make,
get_model,
normalize_name,
get_ledger_data,
)
from . import models, forms
from django.contrib.auth.mixins import PermissionRequiredMixin

File diff suppressed because it is too large Load Diff