@@ -544,6 +544,10 @@ def verify_apprise_urls(request):
544544@login_required
545545def sharing_center (request ):
546546 current_user = request .user
547+ today = now ().date ()
548+
549+ # Retrieve or create user preferences
550+ preferences , _ = UserPreference .objects .get_or_create (user = current_user )
547551
548552 shares = ItemShare .objects .filter (
549553 Q (shared_with_user = current_user ) | Q (shared_by = current_user )
@@ -555,27 +559,32 @@ def sharing_center(request):
555559 for share in shares :
556560 item = share .item
557561 if item .id not in unique_items :
558- if share .shared_with_user == current_user :
562+ transactions_sum = Transaction .objects .filter (item = item ).aggregate (Sum ('value' ))['value__sum' ] or 0
563+ current_value = item .value + transactions_sum
564+ if share .shared_with_user == current_user and not item .is_used and item .expiry_date >= today :
559565 # You are the receiver
560566 unique_items [item .id ] = {
561567 'item' : item ,
562568 'qr_code_base64' : item .qr_code_base64 ,
563569 'shared_by' : share .shared_by ,
564- 'shared_with_me' : True
570+ 'shared_with_me' : True ,
571+ 'current_value' : current_value
565572 }
566573 elif share .shared_by == current_user :
567574 # You are the sender
568575 unique_items [item .id ] = {
569576 'item' : item ,
570577 'qr_code_base64' : item .qr_code_base64 ,
571- 'shared_with_me' : False
578+ 'shared_with_me' : False ,
579+ 'current_value' : current_value
572580 }
573581
574582 shared_items = list (unique_items .values ())
575583
576584 return render (request , 'sharing_center.html' , {
577585 'shared_items' : shared_items ,
578586 'current_date' : timezone .now (),
587+ 'preferences' : preferences ,
579588 })
580589
581590@login_required
0 commit comments