diff --git a/equipment/admin.py b/equipment/admin.py index 55fd412..4de9ca8 100644 --- a/equipment/admin.py +++ b/equipment/admin.py @@ -63,8 +63,8 @@ class EquipmentAttributeValueInline(admin.TabularInline): class CategoryAdmin(admin.ModelAdmin): - readonly_fields = ['full_name'] - list_display = ['name', 'parent', "full_name"] + readonly_fields = ['full_name_p'] + list_display = ['name', 'parent', "full_name_p"] ordering = ['name', 'parent'] search_fields = ['name',] @@ -76,8 +76,39 @@ class EquipmentAttributeAdmin(admin.ModelAdmin): class EquipmentAdmin(admin.ModelAdmin): - readonly_fields = ['full_category', 'added_at', 'modified_at',] + readonly_fields = ['full_category_p', + 'added_at', + 'modified_at', + 'stock_aviable_p', + 'ids_aviable_p', + 'stock_lost_p', + 'ids_lost_p', + ] list_display = ['name', 'stock', 'owner', 'category', 'modified_at'] + fieldsets = ( + ('Général', { + 'fields': ('name', 'owner', 'stock', ) + }), + ('Info stock', + { + 'fields': ( + 'stock_aviable_p', + 'ids_aviable_p', + 'stock_lost_p', + 'ids_lost_p', + ), + }), + ('Catégorie', { + 'fields': ('category', 'full_category_p'), + }), + ('Description', { + 'fields': ('description', 'added_at', 'modified_at',), + }), + ) + + + + ordering = ['name', 'owner', 'category'] inlines = [EquipmentAttributeValueInline, EquipmentDefaultExtraInline, diff --git a/equipment/models.py b/equipment/models.py index 58145f7..a7625be 100644 --- a/equipment/models.py +++ b/equipment/models.py @@ -23,7 +23,7 @@ class EquipmentCategory(models.Model): help_text=_("merci de ne pas faire de référence cyclique"), ) - def full_name_property(self): + def full_name(self): if self.parent is None: return "-" current = self @@ -37,8 +37,8 @@ class EquipmentCategory(models.Model): current = current.parent return res - full_name_property.short_description = _("Chemin complet") - full_name = property(full_name_property) + full_name.short_description = _("Chemin complet") + full_name_p = property(full_name) class Meta: @@ -97,11 +97,45 @@ class Equipment(EventSpecificMixin, models.Model): auto_now=True, ) - def full_category_property(self): - return self.category.full_name_property() + def ids_aviable(self): + res = map(lambda x: x+1, range(self.stock)) + for lost in self.losts.all(): + res = [ x + for x in res + if x not in lost.ids ] + # TODO cassé + # TODO utilisés + return res - full_category_property.short_description = _("Chemin complet") - full_category= property(full_category_property) + def ids_lost(self): + res = [] + for lost in self.losts.all(): + res = res + [ x + for x in lost.ids + if x not in res] + return res + + def stock_aviable(self): + return len(self.ids_available()) + + def stock_lost(self): + return len(self.ids_lost()) + + def full_category(self): + return self.category.full_name() + + full_category.short_description = _("Chemin complet") + ids_aviable.short_description = _("disponibles") + ids_lost.short_description = _("perdus") + stock_aviable.short_description= _("quantité disponible") + stock_lost.short_description = _("quantité perdue") + + full_category_p= property(full_category) + ids_aviable_p= property(ids_aviable) + ids_lost_p= property(ids_lost) + stock_aviable_p= property(stock_aviable) + stock_lost_p = property(stock_lost) + class Meta: