fix - hesab asli was removed from transaction dashboard

This commit is contained in:
2025-11-30 11:31:24 +03:30
parent 0de6e7cb40
commit 634d50c4cd
2 changed files with 76 additions and 4 deletions

View File

@@ -1,3 +1,6 @@
import json
import requests
from django.db import transaction
from django.db.models import Count
from rest_framework import filters
@@ -33,13 +36,54 @@ class UpdatePageAccessViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSe
serializer_class = PageSerializer
permission_classes = [AllowAny]
@action(methods=['post'], detail=False, url_name='update_pages', url_path='update_pages')
def update_pages(self, request, *args, **kwargs):
queryset = self.queryset
def list(self, request, *args, **kwargs):
queryset = self.queryset.all()
page_serializer = self.serializer_class(queryset)
page_serializer = self.get_serializer(queryset, many=True)
return Response(page_serializer.data)
@transaction.atomic
def create(self, request, *args, **kwargs):
"""
sync update page & access on development version with production
"""
url = 'http://127.0.0.1:8000/auth/api/v1/update_access/'
# get data page & permissions data from development
req = requests.get(url)
response = json.loads(req.text.encode('utf-8'))
url = 'http://127.0.0.1:8000/auth/api/v1/update_access/update_access'
# # delete all pages
# Page.objects.all().delete()
#
# # delete all permissions
# Permissions.objects.all().delete()
#
# # recreate page & permissions
# for page in response:
# page_obj = Page.objects.create(
# name=page['name'],
# code=page['code'],
# is_active=page['is_active']
# )
# for permission in page['permissions']:
# Permissions.objects.create(
# name=permission['name'],
# description=permission['description'],
# category=permission['category'],
# page_id=page_obj.id,
# is_active=permission['is_active'],
# modify_state=permission['modify_state']
# )
#
# return Response(response)
@action(methods=['post'], detail=False, url_name='update_page_access', url_path='update_page_access')
def update_page_access(self, request, *args, **kwargs):
return Response(request.data)
class RoleViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet):
""" Crud Operations For User Roles """

View File

@@ -118,9 +118,13 @@ class TransactionDashboardService:
# share: {"name": "", "price": "", ....}
name = share.get("name")
price = share.get("price", 0)
shaba = share.get("shaba", 0) # noqa
share_totals[name]["total_price"] += price
share_totals[name]["count"] += 1
share_totals[name]["shaba"] = shaba # noqa
share_totals = merge_by_shaba_single_name(share_totals)
product["item_share_stats"] = sorted(
[
@@ -147,3 +151,27 @@ class TransactionDashboardService:
"product_summary": list(products_stats),
"brokers_sharing_summary": share_totals
}
def merge_by_shaba_single_name(data): # noqa
grouped = defaultdict(lambda: {"name": None, "total_price": 0, "count": 0, "shaba": None}) # noqa
for name, info in data.items(): # noqa
shaba = info["shaba"] # noqa
if grouped[shaba]["name"] is None:
grouped[shaba]["name"] = name
grouped[shaba]["total_price"] += info["total_price"]
grouped[shaba]["count"] += info["count"]
grouped[shaba]["shaba"] = shaba # noqa
final_result = {}
for shaba, g in grouped.items(): # noqa
final_result[g["name"]] = {
"total_price": g["total_price"],
"count": g["count"],
"shaba": g["shaba"], # noqa
}
return final_result