Finished months balance except the below tables
This commit is contained in:
+102
-9
@@ -8,9 +8,74 @@ class Institute(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Client(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
address = models.TextField()
|
||||
institute = models.ForeignKey(Institute, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.institute.name})"
|
||||
|
||||
class MonthlySheet(models.Model):
|
||||
"""Represents one monthly page"""
|
||||
year = models.IntegerField()
|
||||
month = models.IntegerField() # 1-12
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ['year', 'month']
|
||||
ordering = ['year', 'month']
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.year}-{self.month:02d}"
|
||||
|
||||
class Cell(models.Model):
|
||||
"""A single cell in the spreadsheet"""
|
||||
sheet = models.ForeignKey(MonthlySheet, on_delete=models.CASCADE, related_name='cells')
|
||||
client = models.ForeignKey(Client, on_delete=models.CASCADE)
|
||||
table_type = models.CharField(max_length=20, choices=[
|
||||
('top_left', 'Top Left Table'),
|
||||
('top_right', 'Top Right Table'),
|
||||
('bottom_1', 'Bottom Table 1'),
|
||||
('bottom_2', 'Bottom Table 2'),
|
||||
('bottom_3', 'Bottom Table 3'),
|
||||
])
|
||||
row_index = models.IntegerField() # 0-23 for top tables, 0-9 for bottom
|
||||
column_index = models.IntegerField() # Actually client index (0-5)
|
||||
is_formula = models.BooleanField(default=False)
|
||||
# Cell content
|
||||
value = models.DecimalField(max_digits=15, decimal_places=6, null=True, blank=True)
|
||||
formula = models.TextField(blank=True)
|
||||
|
||||
|
||||
# Metadata
|
||||
data_type = models.CharField(max_length=20, default='number', choices=[
|
||||
('number', 'Number'),
|
||||
('text', 'Text'),
|
||||
('date', 'Date'),
|
||||
])
|
||||
|
||||
class Meta:
|
||||
unique_together = ['sheet', 'client', 'table_type', 'row_index', 'column_index']
|
||||
indexes = [
|
||||
models.Index(fields=['sheet', 'table_type', 'row_index']),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.sheet} - {self.client.name} - {self.table_type}[{self.row_index}][{self.column_index}]"
|
||||
|
||||
class CellReference(models.Model):
|
||||
"""Track dependencies between cells for calculations"""
|
||||
source_cell = models.ForeignKey(Cell, on_delete=models.CASCADE, related_name='dependents')
|
||||
target_cell = models.ForeignKey(Cell, on_delete=models.CASCADE, related_name='dependencies')
|
||||
|
||||
class Meta:
|
||||
unique_together = ['source_cell', 'target_cell']
|
||||
|
||||
class Betriebskosten(models.Model):
|
||||
KOSTENTYP_CHOICES = [
|
||||
('sach', 'Sachkostöen'),
|
||||
('sach', 'Sachkosten'),
|
||||
('ln2', 'LN2'),
|
||||
('helium', 'Helium'),
|
||||
('inv', 'Inventar'),
|
||||
@@ -30,16 +95,40 @@ class Betriebskosten(models.Model):
|
||||
return None
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.buchungsdatum} - {self.get_kostentyp_display()} - {self.betrag}€" # Fixed the missing quote
|
||||
|
||||
class Client(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
address = models.TextField()
|
||||
institute = models.ForeignKey(Institute, on_delete=models.CASCADE) # Remove null=True, blank=True
|
||||
return f"{self.buchungsdatum} - {self.get_kostentyp_display()} - {self.betrag}€"
|
||||
class RowCalculation(models.Model):
|
||||
"""Define calculations for specific rows"""
|
||||
table_type = models.CharField(max_length=20, choices=[
|
||||
('top_left', 'Top Left Table'),
|
||||
('top_right', 'Top Right Table'),
|
||||
('bottom_1', 'Bottom Table 1'),
|
||||
('bottom_2', 'Bottom Table 2'),
|
||||
('bottom_3', 'Bottom Table 3'),
|
||||
])
|
||||
row_index = models.IntegerField() # Which row has the formula
|
||||
formula = models.TextField() # e.g., "row_10 + row_9"
|
||||
description = models.CharField(max_length=200, blank=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ['table_type', 'row_index']
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.institute.name})"
|
||||
return f"{self.table_type}[{self.row_index}]: {self.formula}"
|
||||
|
||||
# Or simpler: Just store row calculations in a JSONField
|
||||
class TableConfig(models.Model):
|
||||
"""Configuration for table calculations"""
|
||||
table_type = models.CharField(max_length=20, unique=True, choices=[
|
||||
('top_left', 'Top Left Table'),
|
||||
('top_right', 'Top Right Table'),
|
||||
('bottom_1', 'Bottom Table 1'),
|
||||
('bottom_2', 'Bottom Table 2'),
|
||||
('bottom_3', 'Bottom Table 3'),
|
||||
])
|
||||
calculations = models.JSONField(default=dict) # {11: "10 + 9", 15: "14 - 13"}
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.get_table_type_display()} Config"
|
||||
class ExcelEntry(models.Model):
|
||||
client = models.ForeignKey(Client, on_delete=models.CASCADE)
|
||||
date = models.DateField(default=timezone.now)
|
||||
@@ -103,6 +192,10 @@ class ExcelEntry(models.Model):
|
||||
decimal_places=6,
|
||||
default=0.0
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.client.name} - {self.date}"
|
||||
|
||||
class SecondTableEntry(models.Model):
|
||||
client = models.ForeignKey(Client, on_delete=models.CASCADE)
|
||||
date = models.DateField(default=timezone.now)
|
||||
@@ -119,4 +212,4 @@ class SecondTableEntry(models.Model):
|
||||
date_joined = models.DateField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.client.name} - {self.date}"
|
||||
return f"{self.client.name} - {self.date}"
|
||||
Reference in New Issue
Block a user