This commit is contained in:
2026-01-06 11:52:03 +01:00
parent b74cf45c5c
commit 34f040df30
11 changed files with 1027 additions and 264 deletions

View File

@@ -6,7 +6,7 @@ from decimal import Decimal, InvalidOperation
from django.apps import apps
from datetime import date, datetime
from django.utils import timezone
from .models import Client, SecondTableEntry
from .models import Client, SecondTableEntry, Institute
from django.db.models import Sum
from django.urls import reverse
from django.db.models.functions import Coalesce
@@ -14,11 +14,7 @@ from .forms import BetriebskostenForm
from .models import Betriebskosten
from django.utils.dateparse import parse_date
# Clients Page (Main)
from django.shortcuts import render
from django.db.models import Sum
from datetime import datetime
from .models import Client, SecondTableEntry
def clients_list(request):
@@ -68,10 +64,13 @@ def clients_list(request):
def table_one_view(request):
ExcelEntry = apps.get_model('sheets', 'ExcelEntry')
entries_table1 = ExcelEntry.objects.all().select_related('client')
clients = Client.objects.all()
clients = Client.objects.all().select_related('institute') # Add select_related
institutes = Institute.objects.all() # Add institutes
return render(request, 'table_one.html', {
'entries_table1': entries_table1,
'clients': clients,
'institutes': institutes, # Add institutes to context
})
@@ -80,20 +79,22 @@ def table_two_view(request):
try:
SecondTableEntry = apps.get_model('sheets', 'SecondTableEntry')
entries = SecondTableEntry.objects.all().order_by('-date')
clients = Client.objects.all()
clients = Client.objects.all().select_related('institute') # Add select_related
institutes = Institute.objects.all()
return render(request, 'table_two.html', {
'entries_table2': entries,
'clients': clients,
'institutes': institutes,
})
except Exception as e:
return render(request, 'table_two.html', {
'error_message': f"Failed to load data: {str(e)}",
'entries_table2': [],
'clients': Client.objects.all()
})
'clients': Client.objects.all().select_related('institute'),
'institutes': Institute.objects.all()
})
# Add Entry (Generic)
@@ -128,6 +129,7 @@ def add_entry(request, model_name):
'status': 'success',
'id': entry.id,
'client_name': entry.client.name,
'institute_name': entry.client.institute.name, # Add this line
'date': entry.date.strftime('%Y-%m-%d') if entry.date else '',
'is_warm': entry.is_warm,
'lhe_delivery': entry.lhe_delivery,
@@ -157,6 +159,7 @@ def add_entry(request, model_name):
'status': 'success',
'id': entry.id,
'client_name': entry.client.name,
'institute_name': entry.client.institute.name, # Add this line
'pressure': str(entry.pressure),
'purity': str(entry.purity),
'notes': entry.notes
@@ -219,6 +222,7 @@ def update_entry(request, model_name):
'status': 'success',
'id': entry.id,
'client_name': entry.client.name,
'institute_name': entry.client.institute.name, # Add this line
'date': entry.date.strftime('%Y-%m-%d') if entry.date else '',
'is_warm': entry.is_warm,
'lhe_delivery': entry.lhe_delivery,
@@ -243,6 +247,7 @@ def update_entry(request, model_name):
'status': 'success',
'id': entry.id,
'client_name': entry.client.name,
'institute_name': entry.client.institute.name, # Add this line
'date': entry.date.strftime('%Y-%m-%d') if entry.date else '',
'pressure': str(entry.pressure),
'purity': str(entry.purity),