This commit is contained in:
Marwan Alwali 2025-04-29 17:59:30 +03:00
parent 53c4f491ab
commit c01d234e0e
6 changed files with 80889 additions and 70 deletions

80870
database_export.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -66,7 +66,7 @@ admin.site.register(models.Activity)
admin.site.register(models.Schedule) admin.site.register(models.Schedule)
admin.site.register(models.Notes) admin.site.register(models.Notes)
admin.site.register(models.UserActivityLog) admin.site.register(models.UserActivityLog)
# admin.site.register(appointment_models.Client) admin.site.register(models.DealersMake)
@admin.register(models.Car) @admin.register(models.Car)

View File

@ -11,8 +11,8 @@ from django.conf import settings
db_config = { db_config = {
'host': 'localhost', 'host': 'localhost',
'user': 'root', 'user': 'root',
'password': settings.PASSWORD, 'password': "Kfsh&rc9788",
'database': 'car2db01022025' 'database': 'car2db_april'
} }
EXCLUDED_TABLES = {"car_serie", "car_generation"} # Tables to exclude from direct dump EXCLUDED_TABLES = {"car_serie", "car_generation"} # Tables to exclude from direct dump

View File

@ -4,8 +4,7 @@ import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "car_inventory.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "car_inventory.settings")
django.setup() django.setup()
import os
import django
import json import json
from tqdm import tqdm from tqdm import tqdm
from inventory.models import ( from inventory.models import (
@ -13,12 +12,8 @@ from inventory.models import (
CarSpecification, CarSpecificationValue, CarOption, CarOptionValue CarSpecification, CarSpecificationValue, CarOption, CarOptionValue
) )
# Set up Django environment
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_project.settings")
# django.setup()
# Load the cleaned JSON data # Load the cleaned JSON data
with open("final_car_data.json", "r") as file: with open("database_export.json", "r") as file:
data = json.load(file) data = json.load(file)
# Step 1: Insert CarMake # Step 1: Insert CarMake
@ -27,9 +22,10 @@ for item in tqdm(data["car_make"], desc="Inserting CarMake"):
id_car_make=item["id_car_make"], id_car_make=item["id_car_make"],
defaults={ defaults={
"name": item["name"], "name": item["name"],
"arabic_name": item.get("arabic_name", ""), "id_car_type": item["id_car_type"],
"logo": item.get("Logo", ""), # "arabic_name": item.get("arabic_name", ""),
"is_sa_import": item.get("is_sa_import", False), # "logo": item.get("Logo", ""),
# "is_sa_import": item.get("is_sa_import", False),
} }
) )
@ -41,7 +37,7 @@ for item in tqdm(data["car_model"], desc="Inserting CarModel"):
defaults={ defaults={
"id_car_make_id": item["id_car_make"], "id_car_make_id": item["id_car_make"],
"name": item["name"], "name": item["name"],
"arabic_name": item.get("arabic_name", ""), # "arabic_name": item.get("arabic_name", ""),
} }
) )
@ -52,8 +48,8 @@ for item in tqdm(data["car_serie"], desc="Inserting CarSerie"):
id_car_serie=item["id_car_serie"], id_car_serie=item["id_car_serie"],
defaults={ defaults={
"id_car_model_id": item["id_car_model"], "id_car_model_id": item["id_car_model"],
"name": item["name"], "name": item["serie_name"],
"arabic_name": item.get("arabic_name", ""), # "arabic_name": item.get("arabic_name", ""),
"year_begin": item.get("year_begin"), "year_begin": item.get("year_begin"),
"year_end": item.get("year_end"), "year_end": item.get("year_end"),
"generation_name": item.get("generation_name", ""), "generation_name": item.get("generation_name", ""),
@ -68,7 +64,7 @@ for item in tqdm(data["car_trim"], desc="Inserting CarTrim"):
defaults={ defaults={
"id_car_serie_id": item["id_car_serie"], "id_car_serie_id": item["id_car_serie"],
"name": item["name"], "name": item["name"],
"arabic_name": item.get("arabic_name", ""), # "arabic_name": item.get("arabic_name", ""),
"start_production_year": item["start_production_year"], "start_production_year": item["start_production_year"],
"end_production_year": item["end_production_year"], "end_production_year": item["end_production_year"],
} }
@ -95,7 +91,7 @@ for item in tqdm(parent_specs, desc="Inserting Parent CarSpecifications"):
id_car_specification=item["id_car_specification"], id_car_specification=item["id_car_specification"],
defaults={ defaults={
"name": item["name"], "name": item["name"],
"arabic_name": item.get("arabic_name", ""), # "arabic_name": item.get("arabic_name", ""),
"id_parent_id": None "id_parent_id": None
} }
) )
@ -106,7 +102,7 @@ for item in tqdm(child_specs, desc="Inserting Child CarSpecifications"):
id_car_specification=item["id_car_specification"], id_car_specification=item["id_car_specification"],
defaults={ defaults={
"name": item["name"], "name": item["name"],
"arabic_name": item.get("arabic_name", ""), # "arabic_name": item.get("arabic_name", ""),
"id_parent_id": item["id_parent"] "id_parent_id": item["id_parent"]
} }
) )
@ -134,7 +130,7 @@ for item in tqdm(parent_options, desc="Inserting Parent CarOptions"):
id_car_option=item["id_car_option"], id_car_option=item["id_car_option"],
defaults={ defaults={
"name": item["name"], "name": item["name"],
"arabic_name": item.get("arabic_name", ""), # "arabic_name": item.get("arabic_name", ""),
"id_parent_id": None "id_parent_id": None
} }
) )
@ -145,7 +141,7 @@ for item in tqdm(child_options, desc="Inserting Child CarOptions"):
id_car_option=item["id_car_option"], id_car_option=item["id_car_option"],
defaults={ defaults={
"name": item["name"], "name": item["name"],
"arabic_name": item.get("arabic_name", ""), # "arabic_name": item.get("arabic_name", ""),
"id_parent_id": item["id_parent"] "id_parent_id": item["id_parent"]
} }
) )

View File

@ -1951,7 +1951,7 @@ class CustomerDetailView(LoginRequiredMixin, PermissionRequiredMixin, DetailView
@login_required @login_required
def add_note_to_customer(request, pk): def add_note_to_customer(request, customer_id):
""" """
This function allows authenticated users to add a note to a specific customer. The This function allows authenticated users to add a note to a specific customer. The
note creation is handled by a form, which is validated after submission. If the form note creation is handled by a form, which is validated after submission. If the form
@ -1968,7 +1968,7 @@ def add_note_to_customer(request, pk):
POST request, it renders the note form template with context including POST request, it renders the note form template with context including
the form and customer. the form and customer.
""" """
customer = get_object_or_404(CustomerModel, pk=pk) customer = get_object_or_404(CustomerModel, pk=customer_id)
if request.method == "POST": if request.method == "POST":
form = forms.NoteForm(request.POST) form = forms.NoteForm(request.POST)
if form.is_valid(): if form.is_valid():

View File

@ -181,7 +181,6 @@ def run():
# print(Permission.objects.filter(codename__icontains='customermodel').first().codename) # print(Permission.objects.filter(codename__icontains='customermodel').first().codename)
# print(os.getenv("DJANGO_ALLOWED_HOSTS")) # print(os.getenv("DJANGO_ALLOWED_HOSTS"))
car_makes = CarMake.objects.all()[:10] car_makes = CarMake.objects.all()[:10]
# Fetch the entity and COGS account # Fetch the entity and COGS account
@ -193,8 +192,6 @@ def run():
for make in range(len(car_makes)): # Start from 0 to include all items for make in range(len(car_makes)): # Start from 0 to include all items
# Generate a unique code # Generate a unique code
# Generate a unique code
# Create the account # Create the account
# account = AccountModel.objects.create( # account = AccountModel.objects.create(
# name=car_makes[make].name, # name=car_makes[make].name,
@ -220,17 +217,10 @@ def run():
.order_by("-created") .order_by("-created")
.first() .first()
) )
last_account = (
entity.get_all_accounts()
.filter(role=roles.COGS)
.order_by("-created")
.first()
)
if len(last_account.code) == 4: if len(last_account.code) == 4:
code = f"{int(last_account.code)}{1:03d}" code = f"{int(last_account.code)}{1:03d}"
elif len(last_account.code) > 4: elif len(last_account.code) > 4:
code = f"{int(last_account.code) + 1}" code = f"{int(last_account.code) + 1}"
code = f"{int(last_account.code) + 1}"
# account = entity.create_account( # account = entity.create_account(
# name=car_makes[make].name, # name=car_makes[make].name,
@ -256,24 +246,12 @@ def run():
.order_by("-created") .order_by("-created")
.first() .first()
) )
path = ""
depth=3,
)
# 00060004001S
last_account = (
entity.get_all_accounts()
.filter(role=roles.COGS)
.order_by("-created")
.first()
)
path = "" path = ""
if len(last_account.code) == 12: if len(last_account.code) == 12:
path = f"{int(last_account.path)}{1:03d}" path = f"{int(last_account.path)}{1:03d}"
elif len(last_account.code) > 12: elif len(last_account.code) > 12:
path = f"{int(last_account.path) + 1}" path = f"{int(last_account.path) + 1}"
path = f"{int(last_account.path) + 1}"
# account.path = path # account.path = path
try:
try: try:
account = cogs.add_child(instance=account) account = cogs.add_child(instance=account)
account.move(cogs, pos="sorted-sibling") account.move(cogs, pos="sorted-sibling")
@ -282,7 +260,6 @@ def run():
except Exception as e: except Exception as e:
print(e) print(e)
# form_data = { # form_data = {
# 'name': car_makes[make].name, # 'name': car_makes[make].name,
# 'code': code, # 'code': code,
@ -292,7 +269,6 @@ def run():
# 'coa_model': coa # Ensure the COA model is included # 'coa_model': coa # Ensure the COA model is included
# } # }
# Create the form instance with the data # Create the form instance with the data
# create_form = AccountModelCreateForm(data=form_data, coa_model=coa) # create_form = AccountModelCreateForm(data=form_data, coa_model=coa)
# # Validate and save the form # # Validate and save the form
@ -316,26 +292,3 @@ def run():
# print(f"Account {account.name} created successfully.") # print(f"Account {account.name} created successfully.")
# else: # else:
# print(f"Failed to create account {account.name}. Errors: {form.errors}") # print(f"Failed to create account {account.name}. Errors: {form.errors}")
# create_form = AccountModelCreateForm(data=form_data, coa_model=coa)
# # Validate and save the form
# if create_form.is_valid():
# account = create_form.save(commit=False)
# account.coa_model = coa # Set the entity for the account
# Add the account as a child of the COGS account
# cogs.add_child(instance=account)
# print(f"Account '{account.name}' created successfully.")
# else:
# print(f"Failed to create account. Errors: {create_form.errors}")
# form = AccountModelUpdateForm(instance=account)
# if form.is_valid():
# instance = form.save(commit=False)
# instance._position = "sorted-sibling"
# instance._ref_node_id = cogs.pk
# instance.save()
# print(f"Account {account.name} created successfully.")
# else:
# print(f"Failed to create account {account.name}. Errors: {form.errors}")