ixg_platform/apps/documents/models.py

81 lines
3.4 KiB
Python

import uuid
from django.conf import settings
from django.db import models
class CertificateOfAnalysis(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
batch = models.ForeignKey("batches.ProcessingBatch", on_delete=models.CASCADE, related_name="certificates_of_analysis")
file_url = models.TextField()
file_name = models.CharField(max_length=255)
issuer = models.CharField(max_length=255, blank=True)
issue_date = models.DateField(null=True, blank=True)
expiry_date = models.DateField(null=True, blank=True)
uploaded_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True)
uploaded_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = "certificates_of_analysis"
verbose_name_plural = "Certificates of Analysis"
def __str__(self):
return f"CoA - {self.batch.batch_reference} - {self.file_name}"
class RegulatoryCert(models.Model):
class CertType(models.TextChoices):
PHYTOSANITARY = "phytosanitary", "Phytosanitary"
EXPORT_PERMIT = "export_permit", "Export Permit"
ORGANIC = "organic", "Organic"
FAIR_TRADE = "fair_trade", "Fair Trade"
EUDR_DDS = "eudr_dds", "EUDR DDS"
OTHER = "other", "Other"
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
batch = models.ForeignKey("batches.ProcessingBatch", on_delete=models.CASCADE, related_name="regulatory_certs")
cert_type = models.CharField(max_length=20, choices=CertType.choices)
file_url = models.TextField()
file_name = models.CharField(max_length=255)
cert_reference = models.CharField(max_length=255, blank=True)
issue_date = models.DateField(null=True, blank=True)
expiry_date = models.DateField(null=True, blank=True)
uploaded_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = "regulatory_certs"
verbose_name = "Regulatory Certificate"
def __str__(self):
return f"{self.get_cert_type_display()} - {self.batch.batch_reference}"
class Document(models.Model):
class DocType(models.TextChoices):
COA = "coa", "Certificate of Analysis"
REGULATORY = "regulatory", "Regulatory"
INVOICE = "invoice", "Invoice"
PACKING_LIST = "packing_list", "Packing List"
BL = "bl", "Bill of Lading"
INSURANCE = "insurance", "Insurance"
OTHER = "other", "Other"
class Visibility(models.TextChoices):
BUYER = "buyer", "Buyer"
OPS = "ops", "Operations"
ADMIN = "admin", "Admin"
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
batch = models.ForeignKey("batches.ProcessingBatch", on_delete=models.CASCADE, null=True, blank=True, related_name="documents")
doc_type = models.CharField(max_length=20, choices=DocType.choices)
file_url = models.TextField()
file_name = models.CharField(max_length=255)
file_size_bytes = models.IntegerField(null=True, blank=True)
visibility = models.CharField(max_length=10, choices=Visibility.choices, default=Visibility.BUYER)
uploaded_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True)
uploaded_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = "documents"
def __str__(self):
return f"{self.get_doc_type_display()} - {self.file_name}"