Add order count edit, remove, and undo-done

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-07 08:16:16 +03:30
parent ab4416251a
commit a5b863fa6c
10 changed files with 189 additions and 41 deletions

View File

@@ -32,9 +32,9 @@ class Order(models.Model):
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)
# Label counts (set from weight on create; editable afterwards)
canister_count = models.PositiveIntegerField(default=0)
box_count = models.PositiveIntegerField(default=0)
canister_pages = models.PositiveIntegerField(editable=False, default=0)
box_pages = models.PositiveIntegerField(editable=False, default=0)
@@ -48,9 +48,22 @@ class Order(models.Model):
def __str__(self):
return f"Order #{self.id} — {self.product.code} — {self.batch_number}"
def save(self, *args, **kwargs):
def apply_weight(self):
"""Derive canister/box counts from total_weight (create path)."""
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)
def set_counts(self, canister_count=None, box_count=None):
"""Edit label counts; keep total_weight aligned with canisters."""
if canister_count is not None:
self.canister_count = canister_count
self.total_weight = canister_count * self.canister_weight
if box_count is not None:
self.box_count = box_count
def save(self, *args, **kwargs):
if not self.canister_count and self.total_weight and self.canister_weight:
self.apply_weight()
self.canister_pages = math.ceil(self.canister_count / 4) if self.canister_count else 0
self.box_pages = math.ceil(self.box_count / 4) if self.box_count else 0
super().save(*args, **kwargs)