quota stat by organization - v1
This commit is contained in:
@@ -463,6 +463,13 @@ class Quota(BaseModel):
|
||||
|
||||
return persian_date.month in self.sale_license
|
||||
|
||||
def quota_amount_by_org(self, org: Organization):
|
||||
stat = OrganizationQuotaStats.objects.filter(
|
||||
quota=self,
|
||||
organization=org
|
||||
)
|
||||
return stat.first().total_amount if stat.exists() else None
|
||||
|
||||
def soft_delete(self):
|
||||
self.trash = True
|
||||
self.save(update_fields=['trash'])
|
||||
@@ -783,3 +790,27 @@ class QuotaDistribution(BaseModel):
|
||||
if not self.distribution_id:
|
||||
self.distribution_id = self.generate_distribution_id()
|
||||
return super(QuotaDistribution, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class OrganizationQuotaStats(BaseModel):
|
||||
organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='org_quota_stats',
|
||||
null=True
|
||||
)
|
||||
quota = models.ForeignKey(
|
||||
Quota,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='org_quota_stats',
|
||||
null=True
|
||||
)
|
||||
|
||||
distributions = models.ManyToManyField(QuotaDistribution)
|
||||
total_amount = models.PositiveBigIntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return f"organization: {self.organization} - quota: {self.quota}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
return super(OrganizationQuotaStats, self).save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user