From 42d718ae8c87f9e5d1de88ef0d47a84a458833ac Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 15 Oct 2018 19:57:27 +0200 Subject: [PATCH] Fix display facture + room + machine_name --- cotisations/models.py | 14 ++++++++------ machines/models.py | 6 +++++- users/models.py | 3 +-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cotisations/models.py b/cotisations/models.py index 914dc115..9f294f6b 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -194,12 +194,14 @@ class Facture(BaseInvoice): return True, None def can_view(self, user_request, *_args, **_kwargs): - if not user_request.has_perm('cotisations.view_facture') and \ - self.user != user_request: - return False, _("You don't have the right to view someone else's " - "invoices history.") - elif not self.valid: - return False, _("The invoice has been invalidated.") + if not user_request.has_perm('cotisations.view_facture'): + if self.user != user_request: + return False, _("You don't have the right to view someone else's " + "invoices history.") + elif not self.valid: + return False, _("The invoice has been invalidated.") + else: + return True, None else: return True, None diff --git a/machines/models.py b/machines/models.py index 412e3750..8db0c9d8 100644 --- a/machines/models.py +++ b/machines/models.py @@ -197,7 +197,11 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model): def short_name(self): """Par defaut, renvoie le nom de la première interface de cette machine""" - return str(self.interface_set.first().domain.name) + interfaces_set = self.interface_set.first() + if interfaces_set: + return str(interfaces_set.domain.name) + else: + return "None" @cached_property def complete_name(self): diff --git a/users/models.py b/users/models.py index c204f763..928e771f 100755 --- a/users/models.py +++ b/users/models.py @@ -845,8 +845,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, """ return user_request == self, None - @staticmethod - def can_change_room(user_request, *_args, **_kwargs): + def can_change_room(self, user_request, *_args, **_kwargs): """ Check if a user can change a room :param user_request: The user who request