Initial commit
This commit is contained in:
@@ -5,4 +5,5 @@ from .district import *
|
||||
from .toyMovement import *
|
||||
from .warehouse import *
|
||||
from .expense import *
|
||||
from .rent import *
|
||||
from .rent import *
|
||||
from .report import *
|
||||
@@ -1,10 +1,31 @@
|
||||
from django.db import models
|
||||
from .district import District
|
||||
from django.utils import timezone
|
||||
|
||||
class Device(models.Model):
|
||||
address = models.CharField(max_length=100, unique=True)
|
||||
district = models.ForeignKey(District, on_delete=models.PROTECT)
|
||||
due_date = models.DateField(null=True, blank=True)
|
||||
amount = models.IntegerField(null=True, blank=True)
|
||||
is_paid = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.address
|
||||
return self.address
|
||||
|
||||
@property
|
||||
def days_until_due(self):
|
||||
"""Calculate days remaining until payment is due"""
|
||||
if not self.due_date:
|
||||
return None
|
||||
today = timezone.now().date()
|
||||
delta = self.due_date - today
|
||||
return delta.days
|
||||
|
||||
@property
|
||||
def is_overdue(self):
|
||||
"""Check if payment is overdue"""
|
||||
if not self.due_date or self.is_paid:
|
||||
return False
|
||||
today = timezone.now().date()
|
||||
return self.due_date < today
|
||||
@@ -4,7 +4,7 @@ from .region import Region
|
||||
class District(models.Model):
|
||||
region = models.ForeignKey(
|
||||
Region,
|
||||
on_delete=models.CASCADE,
|
||||
on_delete=models.PROTECT,
|
||||
related_name="districts"
|
||||
)
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
@@ -3,7 +3,6 @@ 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"
|
||||
@@ -28,7 +27,7 @@ class Expense(models.Model):
|
||||
"accounts.User", on_delete=models.PROTECT,
|
||||
null=True, blank=True, related_name="confirmed_expenses"
|
||||
)
|
||||
|
||||
comment = models.TextField(blank=True, null=True)
|
||||
is_confirmed = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
@@ -41,7 +40,6 @@ class Expense(models.Model):
|
||||
|
||||
# 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."})
|
||||
@@ -3,8 +3,10 @@ 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")
|
||||
warehouse = models.ForeignKey("management.Warehouse", on_delete=models.PROTECT, related_name="warehouse_incomes", null=True, blank=True)
|
||||
|
||||
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)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from django.db import models
|
||||
from .district import District
|
||||
from .device import Device
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Rent(models.Model):
|
||||
address = models.CharField(max_length=100, unique=True)
|
||||
@@ -9,6 +11,15 @@ class Rent(models.Model):
|
||||
due_date = models.DateField()
|
||||
amount = models.IntegerField()
|
||||
|
||||
is_paid = models.BooleanField(default=False)
|
||||
paid_at = models.DateTimeField(null=True, blank=True)
|
||||
created_by = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
related_name="created_rents",
|
||||
on_delete=models.PROTECT,
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
9
core/apps/management/models/report.py
Normal file
9
core/apps/management/models/report.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Report(models.Model):
|
||||
quantity = models.PositiveIntegerField(default=0)
|
||||
device = models.ForeignKey("management.Device", on_delete=models.PROTECT, null=True, blank=True)
|
||||
created_by = models.ForeignKey("accounts.User", on_delete=models.PROTECT, null=True, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
@@ -1,23 +1,39 @@
|
||||
from django.db import models
|
||||
from .device import Device
|
||||
|
||||
from core.apps.management.choice import TOY_MOVEMENT_TYPE
|
||||
from core.apps.management.models 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,
|
||||
Warehouse,
|
||||
on_delete=models.PROTECT,
|
||||
related_name="outgoing"
|
||||
)
|
||||
|
||||
to_warehouse = models.ForeignKey(
|
||||
Warehouse, on_delete=models.PROTECT,
|
||||
Warehouse,
|
||||
on_delete=models.PROTECT,
|
||||
related_name="incoming",
|
||||
null=True, blank=True
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
|
||||
device = models.ForeignKey(
|
||||
Device, on_delete=models.PROTECT,
|
||||
null=True, blank=True
|
||||
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)
|
||||
|
||||
created_by = models.ForeignKey(
|
||||
"accounts.User",
|
||||
on_delete=models.PROTECT
|
||||
)
|
||||
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
Reference in New Issue
Block a user