2026-01-27 08:24:22 +00:00
|
|
|
# Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
# See the LICENSE file for details.
|
|
|
|
|
|
2023-04-04 18:49:53 +00:00
|
|
|
# Django imports
|
2026-03-03 14:05:34 +00:00
|
|
|
from django.core.validators import MinValueValidator
|
2023-04-04 18:49:53 +00:00
|
|
|
from django.db import models
|
2024-08-02 07:45:59 +00:00
|
|
|
from django.db.models import Q
|
2023-04-04 18:49:53 +00:00
|
|
|
|
|
|
|
|
# Module imports
|
2024-05-08 17:31:20 +00:00
|
|
|
from .project import ProjectBaseModel
|
2023-04-04 18:49:53 +00:00
|
|
|
|
2026-03-30 10:00:02 +00:00
|
|
|
class EstimateType(models.TextChoices):
|
|
|
|
|
CATEGORIES = "categories", "Categories"
|
|
|
|
|
POINTS = "points", "Points"
|
|
|
|
|
|
2023-04-04 18:49:53 +00:00
|
|
|
|
|
|
|
|
class Estimate(ProjectBaseModel):
|
|
|
|
|
name = models.CharField(max_length=255)
|
2024-11-21 12:12:44 +00:00
|
|
|
description = models.TextField(verbose_name="Estimate Description", blank=True)
|
2026-03-30 10:00:02 +00:00
|
|
|
type = models.CharField(max_length=255, choices=EstimateType.choices, default=EstimateType.CATEGORIES)
|
2024-06-10 06:46:23 +00:00
|
|
|
last_used = models.BooleanField(default=False)
|
2023-04-04 18:49:53 +00:00
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
"""Return name of the estimate"""
|
|
|
|
|
return f"{self.name} <{self.project.name}>"
|
|
|
|
|
|
|
|
|
|
class Meta:
|
2024-08-02 07:45:59 +00:00
|
|
|
unique_together = ["name", "project", "deleted_at"]
|
|
|
|
|
constraints = [
|
|
|
|
|
models.UniqueConstraint(
|
|
|
|
|
fields=["name", "project"],
|
|
|
|
|
condition=Q(deleted_at__isnull=True),
|
|
|
|
|
name="estimate_unique_name_project_when_deleted_at_null",
|
|
|
|
|
)
|
|
|
|
|
]
|
2023-04-04 18:49:53 +00:00
|
|
|
verbose_name = "Estimate"
|
|
|
|
|
verbose_name_plural = "Estimates"
|
|
|
|
|
db_table = "estimates"
|
|
|
|
|
ordering = ("name",)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EstimatePoint(ProjectBaseModel):
|
2025-09-29 13:45:32 +00:00
|
|
|
estimate = models.ForeignKey("db.Estimate", on_delete=models.CASCADE, related_name="points")
|
2026-02-10 11:37:14 +00:00
|
|
|
key = models.IntegerField(default=0, validators=[MinValueValidator(0)])
|
2023-04-04 18:49:53 +00:00
|
|
|
description = models.TextField(blank=True)
|
2024-06-10 06:46:23 +00:00
|
|
|
value = models.CharField(max_length=255)
|
2023-04-04 18:49:53 +00:00
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
"""Return name of the estimate"""
|
|
|
|
|
return f"{self.estimate.name} <{self.key}> <{self.value}>"
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
verbose_name = "Estimate Point"
|
|
|
|
|
verbose_name_plural = "Estimate Points"
|
|
|
|
|
db_table = "estimate_points"
|
|
|
|
|
ordering = ("value",)
|