feat(pricing): add workspace user rates and price units

This commit is contained in:
2026-04-26 10:19:04 +03:30
parent f960ca8221
commit fadf898486
19 changed files with 731 additions and 266 deletions

View File

@@ -75,3 +75,57 @@ class WorkspaceMembership(BaseModel):
def __str__(self):
return f"{self.user} @ {self.workspace}"
class PriceUnit(BaseModel):
code = models.CharField(max_length=8, unique=True)
name = models.CharField(max_length=64)
local_name = models.CharField(max_length=64, blank=True)
symbol = models.CharField(max_length=16, blank=True)
class Meta:
db_table = "price_unit"
ordering = ("code",)
indexes = [
models.Index(fields=["code"], name="price_unit_code_idx"),
]
def __str__(self):
return self.code
class WorkspaceUserRate(BaseModel):
workspace = models.ForeignKey(
Workspace,
on_delete=models.CASCADE,
related_name="user_rates",
)
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
related_name="workspace_rates",
)
hourly_rate = models.DecimalField(
max_digits=10,
decimal_places=2,
)
currency = models.CharField(
max_length=3,
default="USD",
)
effective_from = models.DateTimeField()
class Meta:
db_table = "workspace_user_rate"
ordering = ("-effective_from",)
constraints = [
models.UniqueConstraint(
fields=["workspace", "user"],
name="unique_workspace_user_rate",
condition=models.Q(is_deleted=False),
)
]
indexes = [
models.Index(fields=["workspace"], name="wur_workspace_idx"),
models.Index(fields=["user"], name="wur_user_idx"),
]