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
|
return
|
||||||
|
|
||||||
tag_dist_batch = instance
|
tag_dist_batch = instance
|
||||||
if tag_dist_batch.parent:
|
parent = tag_dist_batch.parent
|
||||||
tag_dist_batch.parent.total_distributed_tag_count += tag_dist_batch.total_tag_count
|
if parent:
|
||||||
tag_dist_batch.parent.remaining_tag_count = (
|
# parent.total_distributed_tag_count += tag_dist_batch.total_tag_count
|
||||||
tag_dist_batch.parent.total_tag_count - tag_dist_batch.parent.total_distributed_tag_count
|
parent.remaining_tag_count = 20
|
||||||
)
|
print(parent.remaining_tag_count)
|
||||||
print(tag_dist_batch.parent.remaining_tag_count)
|
parent.save(update_fields=['remaining_tag_count'])
|
||||||
tag_dist_batch.parent.save(update_fields=['total_distributed_tag_count', 'remaining_tag_count'])
|
|
||||||
|
|
||||||
tag_dist_batch.remaining_tag_count = tag_dist_batch.total_tag_count
|
tag_dist_batch.remaining_tag_count = tag_dist_batch.total_tag_count
|
||||||
instance.flag = True
|
instance.flag = True
|
||||||
|
|||||||
@@ -12,7 +12,14 @@ from apps.warehouse.models import InventoryQuotaSaleTransaction, InventoryQuotaS
|
|||||||
class TransactionDashboardService:
|
class TransactionDashboardService:
|
||||||
|
|
||||||
@staticmethod
|
@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 = get_all_org_child(org=org)
|
||||||
orgs_child.append(org)
|
orgs_child.append(org)
|
||||||
@@ -23,13 +30,18 @@ class TransactionDashboardService:
|
|||||||
items = InventoryQuotaSaleItem.objects.all().select_related("gov_product", "free_product")
|
items = InventoryQuotaSaleItem.objects.all().select_related("gov_product", "free_product")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
transactions = InventoryQuotaSaleTransaction.objects.filter(
|
if free_visibility_tr_objects:
|
||||||
seller_organization__in=orgs_child
|
transactions = free_visibility_tr_objects
|
||||||
)
|
items = InventoryQuotaSaleItem.objects.filter(
|
||||||
|
transaction__in=transactions
|
||||||
items = InventoryQuotaSaleItem.objects.filter(
|
).select_related("gov_product", "free_product")
|
||||||
transaction__seller_organization__in=orgs_child
|
else:
|
||||||
).select_related("gov_product", "free_product")
|
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
|
# filter queryset (transactions & items) by date
|
||||||
if start_date and end_date:
|
if start_date and end_date:
|
||||||
|
|||||||
@@ -280,13 +280,25 @@ class InventoryQuotaSaleTransactionViewSet(
|
|||||||
transaction_status = query_param.get('status') if 'status' in query_param.keys() else None
|
transaction_status = query_param.get('status') if 'status' in query_param.keys() else None
|
||||||
|
|
||||||
org = get_organization_by_user(request.user)
|
org = get_organization_by_user(request.user)
|
||||||
# filer by date & transaction status
|
if org.free_visibility_by_scope:
|
||||||
transaction_dashboard_data = self.get_dashboard(
|
tr_objects = self.get_queryset(visibility_by_org_scope=True)
|
||||||
org,
|
tr_item_objects = InventoryQuotaSaleItemViewSet().get_queryset(visibility_by_org_scope=True)
|
||||||
start_date=start_date,
|
transaction_dashboard_data = self.get_dashboard(
|
||||||
end_date=end_date,
|
org,
|
||||||
status=transaction_status
|
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)
|
return Response(transaction_dashboard_data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user