some changes in stat / permissions add modify state
This commit is contained in:
@@ -818,14 +818,15 @@ class OrganizationQuotaStats(BaseModel):
|
||||
sold_amount = models.PositiveBigIntegerField(default=0)
|
||||
remaining_amount = models.PositiveBigIntegerField(default=0) # total - sold
|
||||
|
||||
def update_amount(self):
|
||||
def update_amount(self, main_quota=None):
|
||||
""" calculate total/sold/remaining """
|
||||
from apps.warehouse.models import InventoryQuotaSaleItem
|
||||
|
||||
# calculate total amount of distribution
|
||||
# self.total_amount = self.distributions.filter().aggregate(
|
||||
# total=Sum('weight')
|
||||
# )['total'] or 0
|
||||
if not main_quota:
|
||||
# calculate total amount of distribution
|
||||
self.total_amount = self.distributions.filter().aggregate(
|
||||
total=Sum('weight')
|
||||
)['total'] or 0
|
||||
|
||||
self.total_distributed = self.distributions.filter().exclude(
|
||||
assigned_organization=self.organization
|
||||
|
||||
@@ -268,6 +268,7 @@ def organization_quota_stats(sender, instance: Quota, created: bool, **kwargs):
|
||||
)
|
||||
org_quota_stat.total_amount = instance.quota_weight
|
||||
org_quota_stat.save(update_fields=['total_amount'])
|
||||
org_quota_stat.update_amount()
|
||||
|
||||
# delete quota
|
||||
if instance.trash:
|
||||
@@ -293,7 +294,7 @@ def update_quota_stats_on_distribution(sender, instance: QuotaDistribution, crea
|
||||
organization=org,
|
||||
)
|
||||
stats.distributions.add(instance)
|
||||
stats.update_amount()
|
||||
stats.update_amount(main_quota=True)
|
||||
instance.one_time_loop_flag = True
|
||||
|
||||
|
||||
@@ -314,6 +315,6 @@ def handle_quota_stats_soft_delete_on_distribution(sender, instance: QuotaDistri
|
||||
if stats_qs:
|
||||
for stats in stats_qs:
|
||||
stats.distributions.remove(instance)
|
||||
stats.update_amount()
|
||||
stats.update_amount(main_quota=True)
|
||||
|
||||
instance.one_time_loop_flag = True
|
||||
|
||||
Reference in New Issue
Block a user