Skip to content

Commit

Permalink
-Added tooltip for bills involving deactivated members
Browse files Browse the repository at this point in the history
-Made involves_deactivated_members() a property of the Bill class
-Removed flashed messages
  • Loading branch information
chestnutFan committed Dec 13, 2022
1 parent 3f5f260 commit 58e912c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions ihatemoney/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,8 @@ def pay_each_default(self, amount):
else:
return 0

def involves_deactivated_members(self, project):
@property
def involves_deactivated_members(self):
"""Check whether the bill contains deactivated member.
Return:
True if it contains deactivated member,
Expand All @@ -745,8 +746,7 @@ def involves_deactivated_members(self, project):
bill_member_id_list = owers_id + [self.payer_id]
deactivated_member_number = (
Person.query.filter(Person.id.in_(bill_member_id_list))
.filter(Person.project_id == project.id)
.filter(Person.activated == False)
.filter(Person.activated.is_(False))
.count()
)
return deactivated_member_number != 0
Expand Down
16 changes: 14 additions & 2 deletions ihatemoney/templates/list_bills.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,22 @@ <h3 class="modal-title">{{ _('Add a bill') }}</h3>
</span>
</td>
<td class="bill-actions">
<a class="edit" href="{{ url_for(".edit_bill", bill_id=bill.id) }}" title="{{ _("edit") }}">{{ _('edit') }}</a>
<a class="edit" href="{{ url_for(".edit_bill", bill_id=bill.id) }}" data-toggle="tooltip"
{% if bill.involves_deactivated_members %}
title="Cannot be edited as deactivated members involved"
{% else %}
title="Click to edit this bill"
{% endif %}
>{{ _('edit') }}</a>
<form action="{{ url_for(".delete_bill", bill_id=bill.id) }}" method="POST">
{{ csrf_form.csrf_token }}
<button class="action delete" type="submit" title="{{ _("delete") }}"></button>
<button class="action delete" type="submit" data-toggle="tooltip"
{% if bill.involves_deactivated_members %}
title="Cannot be deleted as deactivated members involved"
{% else %}
title="Click to delete this bill"
{% endif %}
></button>
</form>
{% if bill.external_link %}
<a class="show" href="{{ bill.external_link }}" ref="noopener" target="_blank" title="{{ _("show") }}">{{ _('show') }} </a>
Expand Down
12 changes: 2 additions & 10 deletions ihatemoney/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,7 @@ def delete_bill(bill_id):
return redirect(url_for(".list_bills"))

# Check if the bill contains deactivated member. If yes, stop deleting.
if bill.involves_deactivated_members(g.project):
flash(
_("Deactivated users involved. This bill cannot be deleted."),
category="warning",
)
if bill.involves_deactivated_members:
return redirect(url_for(".list_bills"))

db.session.delete(bill)
Expand All @@ -783,11 +779,7 @@ def edit_bill(bill_id):
raise NotFound()

# Check if the bill contains deactivated member. If yes, stop editing.
if bill.involves_deactivated_members(g.project):
flash(
_("Deactivated users involved. This bill cannot be edited."),
category="warning",
)
if bill.involves_deactivated_members:
return redirect(url_for(".list_bills"))

form = get_billform_for(g.project, set_default=False)
Expand Down

0 comments on commit 58e912c

Please sign in to comment.