diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 299859472..b394fd996 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -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, @@ -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 diff --git a/ihatemoney/templates/list_bills.html b/ihatemoney/templates/list_bills.html index 0445d99d8..13e641863 100644 --- a/ihatemoney/templates/list_bills.html +++ b/ihatemoney/templates/list_bills.html @@ -136,10 +136,22 @@ - {{ _('edit') }} + {{ _('edit') }}
{{ csrf_form.csrf_token }} - +
{% if bill.external_link %} {{ _('show') }} diff --git a/ihatemoney/web.py b/ihatemoney/web.py index c3100505f..48e58b76b 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -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) @@ -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)