from django.contrib.auth.models import User from django.db import models from accounts.models import DepotUser from common.models import CompanyModel from containers.models import Container # Create your models here. class Payment(models.Model): invoice_number = models.CharField(max_length=50, unique=True) total_amount = models.DecimalField(max_digits=10, decimal_places=2) company = models.ForeignKey(CompanyModel, related_name='payment_company', on_delete=models.CASCADE) created_on = models.DateTimeField(auto_now_add=True) created_by = models.ForeignKey(DepotUser, related_name='payments_user', on_delete=models.CASCADE) paid = models.BooleanField(default=False) paid_on = models.DateTimeField(auto_now_add=True) paid_info = models.TextField(blank=True, null=True) description = models.CharField(max_length=255, blank=True, null=True) def clean(self): if Payment.objects.filter(invoice_number=self.invoice_number).exclude(id=self.id).exists(): raise ValueError(f'Payment with invoice number {self.invoice_number} already exists.') class PaymentItem(models.Model): payment = models.ForeignKey(Payment, related_name='payment_items', on_delete=models.CASCADE) container = models.ForeignKey(Container, related_name='payment_containers', on_delete=models.CASCADE) amount = models.DecimalField(max_digits=10, decimal_places=2) class ContainerTariffPeriod(models.Model): CONTAINER_SIZE_CHOICES = [ ('20', '20 feet'), ('40', '40/45 feet'), ] container_size = models.CharField(max_length=2, choices=CONTAINER_SIZE_CHOICES) from_days = models.PositiveIntegerField() to_days = models.PositiveIntegerField(null=True, blank=True) # null for last period (16+ days) daily_rate = models.DecimalField(max_digits=6, decimal_places=2) class Meta: unique_together = ['container_size', 'from_days'] ordering = ['container_size', 'from_days'] class AdditionalFees(models.Model): reefer_daily_supplement = models.DecimalField(max_digits=6, decimal_places=2, default=3.00) sweeping_fee = models.DecimalField(max_digits=6, decimal_places=2, default=35.00) fumigation_fee = models.DecimalField(max_digits=6, decimal_places=2, default=75.00) class Meta: verbose_name = 'Additional Fees' verbose_name_plural = 'Additional Fees'