Skip to content

Commit

Permalink
Merge pull request #158 from mlebreuil/151-accounting-dimensions-sear…
Browse files Browse the repository at this point in the history
…ch-is-failing

accounting lin and dimension search fixed
  • Loading branch information
mlebreuil authored Aug 18, 2024
2 parents 84883fa + 2bed2d6 commit 298137c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [154](https://github.com/mlebreuil/netbox-contract/issues/154) Fix edit and delete bulk operations on dimensions and invoice lines.
* [153](https://github.com/mlebreuil/netbox-contract/issues/153) Enforce uniquness of accounting dimensions.
* Adds a status ( Active or Inactive ) to accounitng dimensions.
* [151](https://github.com/mlebreuil/netbox-contract/issues/151) Fix accounting line and dimensions search.

### Version 2.2.1

Expand Down
31 changes: 25 additions & 6 deletions src/netbox_contract/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Meta:

class NestedContractAssignmentSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:ContractAssignment-detail'
view_name='plugins-api:netbox_contract-api:contractassignment-detail'
)

class Meta:
Expand All @@ -61,18 +61,25 @@ class Meta:

class NestedInvoicelineSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:InvoiceLine-detail'
view_name='plugins-api:netbox_contract-api:invoiceline-detail'
)

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):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:AccountingDimension-detail'
view_name='plugins-api:netbox_contract-api:accountingdimension-detail'
)

class Meta:
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.6 on 2024-08-18 19:37

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('netbox_contract', '0035_accountingdimension_status_and_more'),
]

operations = [
migrations.AlterField(
model_name='invoiceline',
name='accounting_dimensions',
field=models.ManyToManyField(
blank=True, to='netbox_contract.accountingdimension'
),
),
]
4 changes: 1 addition & 3 deletions src/netbox_contract/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ class InvoiceLine(NetBoxModel):
max_length=3, choices=CurrencyChoices, default=CurrencyChoices.CURRENCY_USD
)
amount = models.DecimalField(max_digits=10, decimal_places=2)
accounting_dimensions = models.ManyToManyField(
AccountingDimension, related_name='invoicelines', blank=True
)
accounting_dimensions = models.ManyToManyField(AccountingDimension, blank=True)
comments = models.TextField(blank=True)

def get_absolute_url(self):
Expand Down

0 comments on commit 298137c

Please sign in to comment.