You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
depot_django/containers/models.py

105 lines
3.5 KiB
Python

from django.core.exceptions import ValidationError
from django.db import models
from common.fields import ContainerNumberField
from common.models import LinesModel, ContainerTypeModel
# from payments.models import ContainerTariffPeriod, AdditionalFees
# Create your models here.
class Container(models.Model):
number = ContainerNumberField(max_length=11)
line = models.ForeignKey(
LinesModel,
on_delete=models.CASCADE,
related_name='container_lines',
)
container_type = models.ForeignKey(
ContainerTypeModel,
on_delete=models.CASCADE,
related_name='container_container_types',
)
received_on = models.DateTimeField(auto_now_add=True)
received_by = models.ForeignKey(
'accounts.DepotUser',
on_delete=models.CASCADE,
related_name='container_received_by',
)
receive_vehicle = models.CharField(max_length=100, blank=True, null=True)
damages = models.TextField(blank=True, null=True)
heavy_damaged = models.BooleanField(default=False)
position = models.CharField(max_length=7, blank=True, null=True)
swept = models.BooleanField(default=False)
swept_on = models.DateTimeField(blank=True, null=True)
swept_by = models.ForeignKey(
'accounts.DepotUser',
on_delete=models.CASCADE,
related_name='container_swept_by',
blank=True,
null=True
)
washed = models.BooleanField(default=False)
washed_on = models.DateTimeField(blank=True, null=True)
washed_by = models.ForeignKey(
'accounts.DepotUser',
on_delete=models.CASCADE,
related_name='container_washed_by',
blank=True,
null=True
)
preinfo = models.ForeignKey(
'preinfo.Preinfo',
on_delete=models.CASCADE,
related_name='container_preinfo',
)
booking = models.ForeignKey(
'booking.Booking',
on_delete=models.CASCADE,
related_name='container_bookings',
blank = True,
null = True
)
expedited = models.BooleanField(default=False)
expedited_on = models.DateTimeField(blank=True, null=True)
expedited_by = models.ForeignKey(
'accounts.DepotUser',
on_delete=models.CASCADE,
related_name='container_expedited_by',
blank=True,
null=True
)
expedition_vehicle = models.CharField(max_length=100, blank=True, null=True)
def clean(self):
if Container.objects.filter(number=self.number, expedited=False).exclude(id=self.id).exists():
raise ValidationError(f'Container with number {self.number} already exists in the depot.!')
if self.heavy_damaged and not self.damages.strip():
raise ValidationError('Heavy damaged containers must have damages specified.')
class ContainerHistory(Container):
operation = models.ForeignKey(
'common.OperationModel',
on_delete=models.CASCADE,
related_name='history_operations',
)
operation_date = models.DateTimeField(auto_now_add=True)
container = models.ForeignKey(
Container,
on_delete=models.CASCADE,
related_name='history_containers'
)
class ContainerPhotos(models.Model):
container = models.ForeignKey(
Container,
on_delete=models.CASCADE,
related_name='photos',
)
photo = models.TextField(blank=True, null=True)
uploaded_on = models.DateTimeField(auto_now_add=True)
uploaded_by = models.ForeignKey(
'accounts.DepotUser',
on_delete=models.CASCADE,
related_name='container_photos_uploaded_by',
)