organization limit for quota - get org childs

This commit is contained in:
2025-07-16 12:21:29 +03:30
parent a70d451ca1
commit a6b29ad28d
47 changed files with 375 additions and 11 deletions

View File

@@ -134,6 +134,25 @@ class Product(BaseModel):
super(Product, self).save(*args, **kwargs)
class ProductStats(BaseModel):
product = models.OneToOneField(
Product,
on_delete=models.CASCADE,
related_name='stats',
null=True
)
total_quota = models.PositiveBigIntegerField(default=0)
total_remaining = models.PositiveBigIntegerField(default=0)
total_sold = models.PositiveBigIntegerField(default=0)
total_transactions = models.PositiveBigIntegerField(default=0)
def __str__(self):
return f'Product: {self.product.name}-{self.product.id} stats'
def save(self, *args, **kwargs):
return super(ProductStats).save(*args, **kwargs)
class Attribute(BaseModel):
"""
every reference product have multiple attributes
@@ -316,6 +335,8 @@ class Quota(BaseModel):
)
has_distribution_limit = models.BooleanField(default=False)
distribution_mode = ArrayField(base_field=models.IntegerField(), blank=True, null=True)
has_organization_limit = models.BooleanField(default=False)
limit_by_organizations = models.ManyToManyField(Organization, related_name='quota_limits')
base_price_factory = models.DecimalField(max_digits=12, decimal_places=2)
base_price_cooperative = models.DecimalField(max_digits=12, decimal_places=2)
final_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
@@ -371,6 +392,25 @@ class Quota(BaseModel):
return super(Quota, self).save(*args, **kwargs)
class QuotaStats(BaseModel):
quota = models.OneToOneField(
Quota,
on_delete=models.CASCADE,
related_name='stats',
null=True,
)
total_distributed = models.PositiveBigIntegerField(default=0)
remaining = models.PositiveBigIntegerField(default=0)
total_inventory = models.PositiveBigIntegerField(default=0)
total_sale = models.PositiveBigIntegerField(default=0)
def __str__(self):
return f'Quota: {self.quota.quota_id} stats'
def save(self, *args, **kwargs):
return super(QuotaStats, self).save(*args, **kwargs)
class QuotaIncentiveAssignment(BaseModel):
""" assign incentive plan to quota """