Skip to content

Commit

Permalink
Merge pull request #124 from ArnesSI/purchase-deliveries
Browse files Browse the repository at this point in the history
show deliveries on purchase view
  • Loading branch information
matejv authored Sep 3, 2023
2 parents a6a4e45 + c44b9d7 commit 9b52b04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions netbox_inventory/templates/netbox_inventory/purchase.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ <h5 class="card-header">Purchase</h5>
</div>
<div class="row mb-3">
<div class="col col-md-12">
<div class="card">
<h5 class="card-header">Deliveries</h5>
<div class="card-body table-responsive">
{% render_table delivery_table 'inc/table.html' %}
{% include 'inc/paginator.html' with paginator=delivery_table.paginator page=delivery_table.page %}
</div>
</div>
<div class="card">
<h5 class="card-header">Purchased Assets</h5>
<div class="card-body table-responsive">
Expand Down
11 changes: 11 additions & 0 deletions netbox_inventory/views/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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(),
}

Expand Down

0 comments on commit 9b52b04

Please sign in to comment.