fix --> bug of transactions dashboard with free visibility scope on queryset

This commit is contained in:
2026-02-02 10:25:05 +03:30
parent 56025d77b1
commit 0b08107c14
3 changed files with 45 additions and 22 deletions

View File

@@ -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

View File

@@ -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)
@@ -23,13 +30,18 @@ class TransactionDashboardService:
items = InventoryQuotaSaleItem.objects.all().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")
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")
# filter queryset (transactions & items) by date
if start_date and end_date:

View File

@@ -280,13 +280,25 @@ class InventoryQuotaSaleTransactionViewSet(
transaction_status = query_param.get('status') if 'status' in query_param.keys() else None
org = get_organization_by_user(request.user)
# filer by date & transaction status
transaction_dashboard_data = self.get_dashboard(
org,
start_date=start_date,
end_date=end_date,
status=transaction_status
)
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,
)
return Response(transaction_dashboard_data, status=status.HTTP_200_OK)