some changes in stat / permissions add modify state
This commit is contained in:
@@ -98,7 +98,18 @@ class PermissionViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
|||||||
search_fields = ['page__name', 'name']
|
search_fields = ['page__name', 'name']
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
queryset = self.filter_queryset(self.get_queryset().order_by('-modify_date')) # noqa
|
""" all permissions """
|
||||||
|
if 'modify_state' in request.GET.keys():
|
||||||
|
param = self.request.query_params.get('modify_state') # noqa
|
||||||
|
if param == 'true':
|
||||||
|
self.queryset = self.get_queryset().filter(modify_state=True).order_by('-modify_date')
|
||||||
|
elif param == 'false':
|
||||||
|
self.queryset = self.get_queryset().filter(modify_state=False).order_by('-modify_date')
|
||||||
|
else:
|
||||||
|
self.queryset = self.get_queryset().filter().order_by('-modify_date')
|
||||||
|
else:
|
||||||
|
self.queryset = self.queryset.order_by('-modify_date')
|
||||||
|
queryset = self.filter_queryset(self.queryset) # noqa
|
||||||
|
|
||||||
page = self.paginate_queryset(queryset)
|
page = self.paginate_queryset(queryset)
|
||||||
if page is not None:
|
if page is not None:
|
||||||
|
|||||||
@@ -818,14 +818,15 @@ class OrganizationQuotaStats(BaseModel):
|
|||||||
sold_amount = models.PositiveBigIntegerField(default=0)
|
sold_amount = models.PositiveBigIntegerField(default=0)
|
||||||
remaining_amount = models.PositiveBigIntegerField(default=0) # total - sold
|
remaining_amount = models.PositiveBigIntegerField(default=0) # total - sold
|
||||||
|
|
||||||
def update_amount(self):
|
def update_amount(self, main_quota=None):
|
||||||
""" calculate total/sold/remaining """
|
""" calculate total/sold/remaining """
|
||||||
from apps.warehouse.models import InventoryQuotaSaleItem
|
from apps.warehouse.models import InventoryQuotaSaleItem
|
||||||
|
|
||||||
# calculate total amount of distribution
|
if not main_quota:
|
||||||
# self.total_amount = self.distributions.filter().aggregate(
|
# calculate total amount of distribution
|
||||||
# total=Sum('weight')
|
self.total_amount = self.distributions.filter().aggregate(
|
||||||
# )['total'] or 0
|
total=Sum('weight')
|
||||||
|
)['total'] or 0
|
||||||
|
|
||||||
self.total_distributed = self.distributions.filter().exclude(
|
self.total_distributed = self.distributions.filter().exclude(
|
||||||
assigned_organization=self.organization
|
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.total_amount = instance.quota_weight
|
||||||
org_quota_stat.save(update_fields=['total_amount'])
|
org_quota_stat.save(update_fields=['total_amount'])
|
||||||
|
org_quota_stat.update_amount()
|
||||||
|
|
||||||
# delete quota
|
# delete quota
|
||||||
if instance.trash:
|
if instance.trash:
|
||||||
@@ -293,7 +294,7 @@ def update_quota_stats_on_distribution(sender, instance: QuotaDistribution, crea
|
|||||||
organization=org,
|
organization=org,
|
||||||
)
|
)
|
||||||
stats.distributions.add(instance)
|
stats.distributions.add(instance)
|
||||||
stats.update_amount()
|
stats.update_amount(main_quota=True)
|
||||||
instance.one_time_loop_flag = 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:
|
if stats_qs:
|
||||||
for stats in stats_qs:
|
for stats in stats_qs:
|
||||||
stats.distributions.remove(instance)
|
stats.distributions.remove(instance)
|
||||||
stats.update_amount()
|
stats.update_amount(main_quota=True)
|
||||||
|
|
||||||
instance.one_time_loop_flag = True
|
instance.one_time_loop_flag = True
|
||||||
|
|||||||
Reference in New Issue
Block a user