Skip to content

Commit

Permalink
accounting lin and dimension search fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mlebreuil committed Aug 18, 2024
1 parent 84883fa commit 8e3e865
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
25 changes: 22 additions & 3 deletions src/netbox_contract/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ class NestedInvoicelineSerializer(WritableNestedSerializer):

class Meta:
model = InvoiceLine
fields = ('id', 'url', 'display', 'invoice', 'amount')
brief_fields = ('id', 'url', 'display', 'invoice', 'amount')
fields = ('id', 'url', 'display', 'invoice', 'accounting_dimensions', 'amount')
brief_fields = (
'id',
'url',
'display',
'invoice',
'accounting_dimensions',
'amount',
)


class NestedAccountingDimensionSerializer(WritableNestedSerializer):
Expand Down Expand Up @@ -227,6 +234,10 @@ class InvoiceLineSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:invoiceline-detail'
)
invoice = NestedInvoiceSerializer(many=False, required=False)
accounting_dimensions = NestedAccountingDimensionSerializer(
many=True, required=False
)

class Meta:
model = InvoiceLine
Expand All @@ -237,13 +248,21 @@ class Meta:
'invoice',
'amount',
'currency',
'accounting_dimensions',
'comments',
'tags',
'custom_fields',
'created',
'last_updated',
)
brief_fields = ('invoice', 'amount', 'url', 'display', 'name')
brief_fields = (
'invoice',
'accounting_dimensions',
'amount',
'url',
'display',
'name',
)


class AccountingDimensionSerializer(NetBoxModelSerializer):
Expand Down
4 changes: 3 additions & 1 deletion src/netbox_contract/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class ContractAssignmentViewSet(NetBoxModelViewSet):


class InvoiceLineViewSet(NetBoxModelViewSet):
queryset = models.InvoiceLine.objects.prefetch_related('invoice', 'tags')
queryset = models.InvoiceLine.objects.prefetch_related(
'invoice', 'accounting_dimensions', 'tags'
)
serializer_class = InvoiceLineSerializer


Expand Down
6 changes: 2 additions & 4 deletions src/netbox_contract/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Meta:

def search(self, queryset, name, value):
return queryset.filter(
Q(comments__icontains=value) | Q(invoice__name__icontains=value)
Q(comments__icontains=value) | Q(invoice__number__icontains=value)
)


Expand All @@ -71,6 +71,4 @@ class Meta:
fields = ('name', 'value')

def search(self, queryset, name, value):
return queryset.filter(
Q(comments__icontains=value) | Q(invoice__name__icontains=value)
)
return queryset.filter(Q(comments__icontains=value) | Q(name__icontains=value))
10 changes: 6 additions & 4 deletions src/netbox_contract/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .constants import SERVICE_PROVIDER_MODELS
from .models import (
AccountingDimension,
AccountingDimensionStatusChoices,
Contract,
ContractAssignment,
InternalEntityChoices,
Expand Down Expand Up @@ -488,10 +489,7 @@ class Meta:

class InvoiceLineFilterSetForm(NetBoxModelFilterSetForm):
model = InvoiceLine
invoice = DynamicModelChoiceField(queryset=Invoice.objects.all())
accounting_dimensions = DynamicModelMultipleChoiceField(
queryset=AccountingDimension.objects.all()
)
invoice = DynamicModelChoiceField(queryset=Invoice.objects.all(), required=False)


class InvoiceLineImportForm(NetBoxModelImportForm):
Expand Down Expand Up @@ -544,6 +542,10 @@ class Meta:
class AccountingDimensionFilterSetForm(NetBoxModelFilterSetForm):
model = AccountingDimension

name = forms.CharField(required=False)
value = forms.CharField(required=False)
status = forms.ChoiceField(choices=AccountingDimensionStatusChoices, required=False)


class AccountingDimensionImportForm(NetBoxModelImportForm):
status = CSVChoiceField(choices=StatusChoices, help_text='Contract status')
Expand Down

0 comments on commit 8e3e865

Please sign in to comment.