From c44b9d7ea47e860f63c7e3e923adedbe2e68cb68 Mon Sep 17 00:00:00 2001 From: Matej Vadnjal Date: Sun, 3 Sep 2023 10:27:28 +0200 Subject: [PATCH] show deliveries on purchase view --- .../templates/netbox_inventory/purchase.html | 7 +++++++ netbox_inventory/views/purchase.py | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/netbox_inventory/templates/netbox_inventory/purchase.html b/netbox_inventory/templates/netbox_inventory/purchase.html index aa6f20c..5065f64 100644 --- a/netbox_inventory/templates/netbox_inventory/purchase.html +++ b/netbox_inventory/templates/netbox_inventory/purchase.html @@ -72,6 +72,13 @@
Purchase
+
+
Deliveries
+
+ {% render_table delivery_table 'inc/table.html' %} + {% include 'inc/paginator.html' with paginator=delivery_table.paginator page=delivery_table.page %} +
+
Purchased Assets
diff --git a/netbox_inventory/views/purchase.py b/netbox_inventory/views/purchase.py index 0c614b3..6b223dc 100644 --- a/netbox_inventory/views/purchase.py +++ b/netbox_inventory/views/purchase.py @@ -16,9 +16,19 @@ class PurchaseView(generic.ObjectView): queryset = models.Purchase.objects.all() def get_extra_context(self, request, instance): + purchase_deliveries = models.Delivery.objects.restrict(request.user, 'view').filter( + purchase=instance + ) purchase_assets = models.Asset.objects.restrict(request.user, 'view').filter( purchase=instance ) + + delivery_table = tables.DeliveryTable(purchase_deliveries, user=request.user) + delivery_table.columns.hide('purchase') + delivery_table.columns.hide('purchase_date') + delivery_table.columns.hide('supplier') + delivery_table.configure(request) + asset_table = tables.AssetTable(purchase_assets, user=request.user) asset_table.columns.hide('purchase') asset_table.columns.hide('purchase_date') @@ -28,6 +38,7 @@ def get_extra_context(self, request, instance): return { 'asset_table': asset_table, 'asset_count': models.Asset.objects.filter(purchase=instance).count(), + 'delivery_table': delivery_table, 'delivery_count': models.Delivery.objects.filter(purchase=instance).count(), }