first commit
This commit is contained in:
8
core/apps/management/models/__init__.py
Normal file
8
core/apps/management/models/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from .region import *
|
||||
from .device import *
|
||||
from .income import *
|
||||
from .district import *
|
||||
from .toyMovement import *
|
||||
from .warehouse import *
|
||||
from .expense import *
|
||||
from .rent import *
|
||||
10
core/apps/management/models/device.py
Normal file
10
core/apps/management/models/device.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.db import models
|
||||
from .district import District
|
||||
|
||||
class Device(models.Model):
|
||||
address = models.CharField(max_length=100, unique=True)
|
||||
district = models.ForeignKey(District, on_delete=models.PROTECT)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.address
|
||||
16
core/apps/management/models/district.py
Normal file
16
core/apps/management/models/district.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from django.db import models
|
||||
from .region import Region
|
||||
|
||||
class District(models.Model):
|
||||
region = models.ForeignKey(
|
||||
Region,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="districts"
|
||||
)
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("region", "name")
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} — {self.region.name}"
|
||||
47
core/apps/management/models/expense.py
Normal file
47
core/apps/management/models/expense.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from django.db import models
|
||||
from core.apps.management.models import Device
|
||||
|
||||
class Expense(models.Model):
|
||||
class ExpenseType(models.TextChoices):
|
||||
RENT = "rent", "Ijara"
|
||||
SALARY = "salary", "Maosh"
|
||||
UTILITIES = "utilities", "Kommunal to‘lovlar"
|
||||
MAINTENANCE = "maintenance", "Texnik xizmat"
|
||||
FOOD = "food", "Oziq-ovqat"
|
||||
TRANSPORT = "transport", "Yo'lkira"
|
||||
BUY_TOYS = "buy_toys", "Oʻyinchoqlar sotib olish"
|
||||
OTHER = "other", "Boshqa"
|
||||
|
||||
amount = models.DecimalField(max_digits=12, decimal_places=2)
|
||||
expense_type = models.CharField(
|
||||
max_length=20,
|
||||
choices=ExpenseType.choices,
|
||||
default=ExpenseType.OTHER,
|
||||
)
|
||||
|
||||
# Conditional fields
|
||||
employee = models.ForeignKey("accounts.User", related_name="salaries", null=True, blank=True, on_delete=models.PROTECT)
|
||||
device = models.ForeignKey(Device, null=True, blank=True, on_delete=models.PROTECT)
|
||||
|
||||
created_by = models.ForeignKey("accounts.User", on_delete=models.PROTECT)
|
||||
confirmed_by = models.ForeignKey(
|
||||
"accounts.User", on_delete=models.PROTECT,
|
||||
null=True, blank=True, related_name="confirmed_expenses"
|
||||
)
|
||||
|
||||
is_confirmed = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def clean(self):
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
# Salary requires employee
|
||||
if self.expense_type == self.ExpenseType.SALARY and not self.employee:
|
||||
raise ValidationError({"employee": "Employee must be set for Salary expenses."})
|
||||
|
||||
# Device required for rent/utilities/maintenance
|
||||
if self.expense_type in [
|
||||
self.ExpenseType.RENT,
|
||||
self.ExpenseType.MAINTENANCE
|
||||
] and not self.device:
|
||||
raise ValidationError({"device": "Device must be set for this type of expense."})
|
||||
10
core/apps/management/models/income.py
Normal file
10
core/apps/management/models/income.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.db import models
|
||||
from .device import Device
|
||||
|
||||
class Income(models.Model):
|
||||
device = models.ForeignKey(Device, related_name='incomes',on_delete=models.PROTECT)
|
||||
amount = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
|
||||
created_by = models.ForeignKey("accounts.User", on_delete=models.PROTECT, related_name="created_incomes")
|
||||
|
||||
is_confirmed = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
7
core/apps/management/models/region.py
Normal file
7
core/apps/management/models/region.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.db import models
|
||||
|
||||
class Region(models.Model):
|
||||
name = models.CharField(max_length=100, unique=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
15
core/apps/management/models/rent.py
Normal file
15
core/apps/management/models/rent.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.db import models
|
||||
from .district import District
|
||||
from .device import Device
|
||||
|
||||
class Rent(models.Model):
|
||||
address = models.CharField(max_length=100, unique=True)
|
||||
district = models.ForeignKey(District, related_name="district_rents", on_delete=models.PROTECT)
|
||||
device = models.ForeignKey(Device, related_name="device_rents", on_delete=models.PROTECT)
|
||||
due_date = models.DateField()
|
||||
amount = models.IntegerField()
|
||||
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.address
|
||||
23
core/apps/management/models/toyMovement.py
Normal file
23
core/apps/management/models/toyMovement.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.db import models
|
||||
from .device import Device
|
||||
from .warehouse import Warehouse
|
||||
from ..choice import TOY_MOVEMENT_TYPE
|
||||
|
||||
class ToyMovement(models.Model):
|
||||
movement_type = models.CharField(max_length=30, choices=TOY_MOVEMENT_TYPE)
|
||||
from_warehouse = models.ForeignKey(
|
||||
Warehouse, on_delete=models.PROTECT,
|
||||
related_name="outgoing"
|
||||
)
|
||||
to_warehouse = models.ForeignKey(
|
||||
Warehouse, on_delete=models.PROTECT,
|
||||
related_name="incoming",
|
||||
null=True, blank=True
|
||||
)
|
||||
device = models.ForeignKey(
|
||||
Device, on_delete=models.PROTECT,
|
||||
null=True, blank=True
|
||||
)
|
||||
quantity = models.PositiveIntegerField()
|
||||
created_by = models.ForeignKey("accounts.User", on_delete=models.PROTECT)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
15
core/apps/management/models/warehouse.py
Normal file
15
core/apps/management/models/warehouse.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.db import models
|
||||
from .region import Region
|
||||
|
||||
class Warehouse(models.Model):
|
||||
name = models.CharField(max_length=100, unique=True)
|
||||
region = models.ForeignKey(
|
||||
Region,
|
||||
on_delete=models.PROTECT,
|
||||
related_name="warehouses"
|
||||
)
|
||||
toys_count = models.PositiveIntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
Reference in New Issue
Block a user