fix --> bug of transactions dashboard with free visibility scope on queryset
This commit is contained in:
@@ -51,13 +51,12 @@ def calculate_tag_distribution_detail(sender, instance: TagDistributionBatch, **
|
||||
return
|
||||
|
||||
tag_dist_batch = instance
|
||||
if tag_dist_batch.parent:
|
||||
tag_dist_batch.parent.total_distributed_tag_count += tag_dist_batch.total_tag_count
|
||||
tag_dist_batch.parent.remaining_tag_count = (
|
||||
tag_dist_batch.parent.total_tag_count - tag_dist_batch.parent.total_distributed_tag_count
|
||||
)
|
||||
print(tag_dist_batch.parent.remaining_tag_count)
|
||||
tag_dist_batch.parent.save(update_fields=['total_distributed_tag_count', 'remaining_tag_count'])
|
||||
parent = tag_dist_batch.parent
|
||||
if parent:
|
||||
# parent.total_distributed_tag_count += tag_dist_batch.total_tag_count
|
||||
parent.remaining_tag_count = 20
|
||||
print(parent.remaining_tag_count)
|
||||
parent.save(update_fields=['remaining_tag_count'])
|
||||
|
||||
tag_dist_batch.remaining_tag_count = tag_dist_batch.total_tag_count
|
||||
instance.flag = True
|
||||
|
||||
@@ -12,7 +12,14 @@ from apps.warehouse.models import InventoryQuotaSaleTransaction, InventoryQuotaS
|
||||
class TransactionDashboardService:
|
||||
|
||||
@staticmethod
|
||||
def get_dashboard(org: Organization, start_date: str = None, end_date: str = None, status: str = None):
|
||||
def get_dashboard(
|
||||
org: Organization,
|
||||
free_visibility_tr_objects=None,
|
||||
free_visibility_tr_item_objects=None,
|
||||
start_date: str = None,
|
||||
end_date: str = None,
|
||||
status: str = None
|
||||
):
|
||||
|
||||
orgs_child = get_all_org_child(org=org)
|
||||
orgs_child.append(org)
|
||||
@@ -22,11 +29,16 @@ class TransactionDashboardService:
|
||||
|
||||
items = InventoryQuotaSaleItem.objects.all().select_related("gov_product", "free_product")
|
||||
|
||||
else:
|
||||
if free_visibility_tr_objects:
|
||||
transactions = free_visibility_tr_objects
|
||||
items = InventoryQuotaSaleItem.objects.filter(
|
||||
transaction__in=transactions
|
||||
).select_related("gov_product", "free_product")
|
||||
else:
|
||||
transactions = InventoryQuotaSaleTransaction.objects.filter(
|
||||
seller_organization__in=orgs_child
|
||||
)
|
||||
|
||||
items = InventoryQuotaSaleItem.objects.filter(
|
||||
transaction__seller_organization__in=orgs_child
|
||||
).select_related("gov_product", "free_product")
|
||||
|
||||
@@ -280,12 +280,24 @@ class InventoryQuotaSaleTransactionViewSet(
|
||||
transaction_status = query_param.get('status') if 'status' in query_param.keys() else None
|
||||
|
||||
org = get_organization_by_user(request.user)
|
||||
if org.free_visibility_by_scope:
|
||||
tr_objects = self.get_queryset(visibility_by_org_scope=True)
|
||||
tr_item_objects = InventoryQuotaSaleItemViewSet().get_queryset(visibility_by_org_scope=True)
|
||||
transaction_dashboard_data = self.get_dashboard(
|
||||
org,
|
||||
free_visibility_tr_objects=tr_objects,
|
||||
free_visibility_tr_item_objects=tr_item_objects,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
status=transaction_status,
|
||||
)
|
||||
else:
|
||||
# filer by date & transaction status
|
||||
transaction_dashboard_data = self.get_dashboard(
|
||||
org,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
status=transaction_status
|
||||
status=transaction_status,
|
||||
)
|
||||
|
||||
return Response(transaction_dashboard_data, status=status.HTTP_200_OK)
|
||||
|
||||
Reference in New Issue
Block a user