diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 313090fc..af11da28 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -752,7 +752,8 @@ class Bill(db.Model): 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, @@ -762,8 +763,7 @@ class Bill(db.Model): 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 diff --git a/ihatemoney/templates/list_bills.html b/ihatemoney/templates/list_bills.html index 79e25262..7f4350e8 100644 --- a/ihatemoney/templates/list_bills.html +++ b/ihatemoney/templates/list_bills.html @@ -148,10 +148,22 @@ - {{ _('edit') }} + {{ _('edit') }}
{{ csrf_form.csrf_token }} - +
{% if bill.external_link %} {{ _('show') }} diff --git a/ihatemoney/web.py b/ihatemoney/web.py index 58b0580f..d3706e40 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -801,11 +801,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) @@ -823,11 +819,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)