feat(rates): record hourly rate history
This commit is contained in:
@@ -173,3 +173,53 @@ class WorkspaceUserRate(BaseModel):
|
||||
"currency": self.currency,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class HourlyRateHistory(BaseModel):
|
||||
class Scope(models.TextChoices):
|
||||
WORKSPACE = "workspace", "Workspace"
|
||||
PROJECT = "project", "Project"
|
||||
|
||||
workspace = models.ForeignKey(
|
||||
Workspace,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="hourly_rate_history",
|
||||
)
|
||||
user = models.ForeignKey(
|
||||
User,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="hourly_rate_history",
|
||||
)
|
||||
project = models.ForeignKey(
|
||||
"projects.Project",
|
||||
on_delete=models.CASCADE,
|
||||
related_name="hourly_rate_history",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
scope = models.CharField(max_length=16, choices=Scope.choices)
|
||||
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 = "hourly_rate_history"
|
||||
ordering = ("effective_from", "created_at")
|
||||
indexes = [
|
||||
models.Index(fields=["workspace", "user", "effective_from"], name="hrh_ws_user_eff_idx"),
|
||||
models.Index(fields=["project", "user", "effective_from"], name="hrh_project_user_eff_idx"),
|
||||
]
|
||||
|
||||
def get_additional_data(self):
|
||||
return build_workspace_log_metadata(
|
||||
section=SECTION_RATES,
|
||||
workspace_id=self.workspace_id,
|
||||
target_id=self.id,
|
||||
target_label=self.user.full_name or self.user.mobile,
|
||||
extra={
|
||||
"rate_user_id": str(self.user_id),
|
||||
"project_id": str(self.project_id) if self.project_id else None,
|
||||
"scope": self.scope,
|
||||
"currency": self.currency,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user