Initial commit: Product Slip Manager
This commit is contained in:
56
slips/models.py
Normal file
56
slips/models.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import math
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
class Product(models.Model):
|
||||
code = models.CharField(max_length=50, unique=True)
|
||||
description = models.CharField(max_length=200)
|
||||
default_net_weight = models.FloatField(default=5.0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['code']
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.code} — {self.description}"
|
||||
|
||||
|
||||
class Order(models.Model):
|
||||
STATUS_CHOICES = [
|
||||
('pending', 'Pending'),
|
||||
('printing', 'Printing'),
|
||||
('done', 'Done'),
|
||||
('cancelled', 'Cancelled'),
|
||||
]
|
||||
|
||||
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='orders')
|
||||
batch_number = models.CharField(max_length=50)
|
||||
production_date = models.DateField(default=timezone.now)
|
||||
next_control_date = models.DateField()
|
||||
total_weight = models.FloatField(default=0)
|
||||
canister_weight = models.FloatField(default=5)
|
||||
canisters_per_box = models.PositiveIntegerField(default=4)
|
||||
|
||||
# Calculated fields
|
||||
canister_count = models.PositiveIntegerField(editable=False, default=0)
|
||||
box_count = models.PositiveIntegerField(editable=False, default=0)
|
||||
canister_pages = models.PositiveIntegerField(editable=False, default=0)
|
||||
box_pages = models.PositiveIntegerField(editable=False, default=0)
|
||||
|
||||
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
printed_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at']
|
||||
|
||||
def __str__(self):
|
||||
return f"Order #{self.id} — {self.product.code} — {self.batch_number}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.canister_count = math.ceil(self.total_weight / self.canister_weight)
|
||||
self.box_count = math.ceil(self.canister_count / self.canisters_per_box)
|
||||
self.canister_pages = math.ceil(self.canister_count / 4)
|
||||
self.box_pages = math.ceil(self.box_count / 4)
|
||||
super().save(*args, **kwargs)
|
||||
Reference in New Issue
Block a user