Skip to content

Commit 96cf92c

Browse files
committed
fix: hide used or expired items that were shared
1 parent aa67154 commit 96cf92c

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

myapp/templates/sharing_center.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,29 @@ <h6>{{ entry.item.name }}</h6>
5151
{% endif %}
5252
</div>
5353
<div class="item-details">
54+
{% if preferences.show_issue_date %}
5455
<div class="detail-item default-tile" style="background-color: {{ entry.item.tile_color|default:'#placeholder'|darken }}">
5556
<i class="bi bi-calendar text-muted"></i> <span><b>{% trans "Issue Date" %}:</b> {{ entry.item.issue_date }}</span>
5657
</div>
58+
{% endif %}
59+
{% if preferences.show_expiry_date %}
5760
<div class="detail-item default-tile" style="background-color: {{ entry.item.tile_color|default:'#placeholder'|darken }}">
5861
<i class="bi bi-calendar-x text-muted"></i> <span><b>{% trans "Expiry Date" %}:</b> {{ entry.item.expiry_date }}</span>
5962
</div>
63+
{% endif %}
64+
{% if entry.item.type != "loyaltycard" %}
65+
{% if preferences.show_value %}
66+
<div class="detail-item default-tile" style="background-color: {{ entry.item.tile_color|default:'#placeholder'|darken }}">
67+
{% if entry.item.value_type == "percentage" %}
68+
<i class="bi bi-percent text-muted"></i> <span><b>{% trans "Percentage" %}:</b> {{ entry.current_value|floatformat:2 }}</span>
69+
{% elif entry.item.value_type == "money" %}
70+
<i class="bi bi-cash text-muted"></i> <span><b>{% trans "Value" %}:</b> {{ entry.current_value|floatformat:2 }}</span>
71+
{% elif entry.item.value_type == "multiplier" %}
72+
<i class="bi bi-dice-5 text-muted"></i> <span><b>{% trans "Multiplier" %}:</b> {{ entry.current_value|floatformat:2 }}</span>
73+
{% endif %}
74+
</div>
75+
{% endif %}
76+
{% endif %}
6077
<div class="detail-item default-tile" style="background-color: {{ entry.item.tile_color|default:'#placeholder'|darken }}">
6178
<i class="bi bi-people text-muted"></i>
6279
<span>

myapp/views.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ def verify_apprise_urls(request):
544544
@login_required
545545
def 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

Comments
 (0)