Skip to content

Commit

Permalink
Merge pull request #194 from mlebreuil/167-in-gui-invoice-edit-view-c…
Browse files Browse the repository at this point in the history
…ontracts-dropdown-box-search-doesnt-work-properly

Add selector to object dynamic selection box.
  • Loading branch information
mlebreuil authored Dec 9, 2024
2 parents 1bcea7f + bc0ef97 commit 953bdf0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

## Version 2

### Version 2.2.8

* [167](https://github.com/mlebreuil/netbox-contract/issues/167) Add selector to object dynamic selection box.

### Version 2.2.7

* fix migration dependency
Expand Down
75 changes: 53 additions & 22 deletions src/netbox_contract/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ class ContractForm(NetBoxModelForm):
widget=HTMXSelect(),
)
external_partie_object = forms.ModelChoiceField(queryset=None)
tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(), required=False)
parent = DynamicModelChoiceField(queryset=Contract.objects.all(), required=False)
tenant = DynamicModelChoiceField(
queryset=Tenant.objects.all(), required=False, selector=True
)
parent = DynamicModelChoiceField(
queryset=Contract.objects.all(), required=False, selector=True
)
accounting_dimensions = Dimensions(required=False)

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -157,15 +161,19 @@ def clean(self):
)


class ContractFilterSetForm(NetBoxModelFilterSetForm):
class ContractFilterForm(NetBoxModelFilterSetForm):
model = Contract

tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(), required=False)
tenant = DynamicModelChoiceField(
queryset=Tenant.objects.all(), required=False, selector=True
)
external_reference = forms.CharField(required=False)
internal_partie = forms.ChoiceField(choices=InternalEntityChoices, required=False)
status = forms.ChoiceField(choices=StatusChoices, required=False)
currency = forms.ChoiceField(choices=CurrencyChoices, required=False)
parent = DynamicModelChoiceField(queryset=Contract.objects.all(), required=False)
parent = DynamicModelChoiceField(
queryset=Contract.objects.all(), required=False, selector=True
)
tag = TagFilterField(model)


Expand Down Expand Up @@ -233,10 +241,18 @@ class ContractBulkEditForm(NetBoxModelBulkEditForm):
name = forms.CharField(max_length=100, required=False)
external_reference = forms.CharField(max_length=100, required=False)
internal_partie = forms.ChoiceField(choices=InternalEntityChoices, required=False)
tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(), required=False)
tenant = DynamicModelChoiceField(
queryset=Tenant.objects.all(),
required=False,
selector=True,
)
accounting_dimensions = Dimensions(required=False)
comments = CommentField(required=False)
parent = DynamicModelChoiceField(queryset=Contract.objects.all(), required=False)
parent = DynamicModelChoiceField(
queryset=Contract.objects.all(),
required=False,
selector=True,
)

nullable_fields = (
'accounting_dimensions',
Expand All @@ -254,7 +270,7 @@ class InvoiceForm(NetBoxModelForm):
help_text='Invoice template name will be overriden to _invoice_template_contract name',
)
contracts = DynamicModelMultipleChoiceField(
queryset=Contract.objects.all(), required=False
queryset=Contract.objects.all(), required=False, selector=True
)
accounting_dimensions = Dimensions(required=False)

Expand Down Expand Up @@ -360,15 +376,17 @@ class Meta:
}


class InvoiceFilterSetForm(NetBoxModelFilterSetForm):
class InvoiceFilterForm(NetBoxModelFilterSetForm):
model = Invoice
number = forms.CharField(required=False)
template = forms.NullBooleanField(
required=False, widget=forms.Select(choices=BOOLEAN_WITH_BLANK_CHOICES)
)
currency = forms.ChoiceField(choices=CurrencyChoices, required=False)
contracts = DynamicModelMultipleChoiceField(
queryset=Contract.objects.all(), required=False
queryset=Contract.objects.all(),
required=False,
selector=True,
)
tag = TagFilterField(model)

Expand Down Expand Up @@ -403,7 +421,9 @@ class InvoiceBulkEditForm(NetBoxModelBulkEditForm):
template = forms.BooleanField(required=False)
date = forms.DateField(required=False)
contracts = DynamicModelMultipleChoiceField(
queryset=Contract.objects.all(), required=False
queryset=Contract.objects.all(),
required=False,
selector=True,
)
period_start = forms.DateField(required=False)
period_end = forms.DateField(required=False)
Expand Down Expand Up @@ -432,7 +452,7 @@ class Meta:
fields = ('name', 'slug', 'portal_url', 'comments', 'tags')


class ServiceProviderFilterSetForm(NetBoxModelFilterSetForm):
class ServiceProviderFilterForm(NetBoxModelFilterSetForm):
model = ServiceProvider
name = forms.CharField(required=False)
tag = TagFilterField(model)
Expand All @@ -458,7 +478,7 @@ class ServiceProviderBulkEditForm(NetBoxModelBulkEditForm):


class ContractAssignmentForm(NetBoxModelForm):
contract = DynamicModelChoiceField(queryset=Contract.objects.all())
contract = DynamicModelChoiceField(queryset=Contract.objects.all(), selector=True)

class Meta:
model = ContractAssignment
Expand All @@ -469,9 +489,12 @@ class Meta:
}


class ContractAssignmentFilterSetForm(NetBoxModelFilterSetForm):
class ContractAssignmentFilterForm(NetBoxModelFilterSetForm):
model = ContractAssignment
contract = DynamicModelChoiceField(queryset=Contract.objects.all())
contract = DynamicModelChoiceField(
queryset=Contract.objects.all(),
selector=True,
)


class ContractAssignmentImportForm(NetBoxModelImportForm):
Expand All @@ -492,9 +515,9 @@ class Meta:


class InvoiceLineForm(NetBoxModelForm):
invoice = DynamicModelChoiceField(queryset=Invoice.objects.all())
invoice = DynamicModelChoiceField(queryset=Invoice.objects.all(), selector=True)
accounting_dimensions = DynamicModelMultipleChoiceField(
queryset=AccountingDimension.objects.all(), required=False
queryset=AccountingDimension.objects.all(), required=False, selector=True
)

def clean(self):
Expand Down Expand Up @@ -527,11 +550,17 @@ class Meta:
]


class InvoiceLineFilterSetForm(NetBoxModelFilterSetForm):
class InvoiceLineFilterForm(NetBoxModelFilterSetForm):
model = InvoiceLine
invoice = DynamicModelChoiceField(queryset=Invoice.objects.all(), required=False)
invoice = DynamicModelChoiceField(
queryset=Invoice.objects.all(),
required=False,
selector=True,
)
accounting_dimensions = DynamicModelMultipleChoiceField(
queryset=AccountingDimension.objects.all(), required=False
queryset=AccountingDimension.objects.all(),
required=False,
selector=True,
)
currency = forms.ChoiceField(choices=CurrencyChoices, required=False)
tag = TagFilterField(model)
Expand Down Expand Up @@ -564,7 +593,9 @@ class Meta:
class InvoiceLineBulkEditForm(NetBoxModelBulkEditForm):
invoice = DynamicModelChoiceField(queryset=Invoice.objects.all(), required=False)
accounting_dimensions = DynamicModelMultipleChoiceField(
queryset=AccountingDimension.objects.all(), required=False
queryset=AccountingDimension.objects.all(),
required=False,
selector=True,
)
model = InvoiceLine

Expand All @@ -584,7 +615,7 @@ class Meta:
]


class AccountingDimensionFilterSetForm(NetBoxModelFilterSetForm):
class AccountingDimensionFilterForm(NetBoxModelFilterSetForm):
model = AccountingDimension

name = forms.CharField(required=False)
Expand Down
12 changes: 6 additions & 6 deletions src/netbox_contract/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ServiceProviderListView(generic.ObjectListView):
queryset = ServiceProvider.objects.all()
table = tables.ServiceProviderListTable
filterset = filtersets.ServiceProviderFilterSet
filterset_form = forms.ServiceProviderFilterSetForm
filterset_form = forms.ServiceProviderFilterForm


class ServiceProviderEditView(generic.ObjectEditView):
Expand Down Expand Up @@ -84,7 +84,7 @@ class ContractAssignmentListView(generic.ObjectListView):
queryset = ContractAssignment.objects.all()
table = tables.ContractAssignmentListTable
filterset = filtersets.ContractAssignmentFilterSet
filterset_form = forms.ContractAssignmentFilterSetForm
filterset_form = forms.ContractAssignmentFilterForm
actions = {
'import': {'add'},
'export': set(),
Expand Down Expand Up @@ -184,7 +184,7 @@ class ContractListView(generic.ObjectListView):
)
table = tables.ContractListTable
filterset = filtersets.ContractFilterSet
filterset_form = forms.ContractFilterSetForm
filterset_form = forms.ContractFilterForm


class ContractEditView(generic.ObjectEditView):
Expand Down Expand Up @@ -270,7 +270,7 @@ class InvoiceListView(generic.ObjectListView):
queryset = Invoice.objects.all()
table = tables.InvoiceListTable
filterset = filtersets.InvoiceFilterSet
filterset_form = forms.InvoiceFilterSetForm
filterset_form = forms.InvoiceFilterForm


class InvoiceEditView(generic.ObjectEditView):
Expand Down Expand Up @@ -377,7 +377,7 @@ class InvoiceLineListView(generic.ObjectListView):
queryset = InvoiceLine.objects.all()
table = tables.InvoiceLineListTable
filterset = filtersets.InvoiceLineFilterSet
filterset_form = forms.InvoiceLineFilterSetForm
filterset_form = forms.InvoiceLineFilterForm


class InvoiceLineEditView(generic.ObjectEditView):
Expand Down Expand Up @@ -453,7 +453,7 @@ class AccountingDimensionListView(generic.ObjectListView):
queryset = AccountingDimension.objects.all()
table = tables.AccountingDimensionListTable
filterset = filtersets.AccountingDimensionFilterSet
filterset_form = forms.AccountingDimensionFilterSetForm
filterset_form = forms.AccountingDimensionFilterForm


class AccountingDimensionEditView(generic.ObjectEditView):
Expand Down

0 comments on commit 953bdf0

Please sign in to comment.