diff --git a/CHANGELOG.md b/CHANGELOG.md index f2b3009..5ae7410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Generally improve filtering options * [178](https://github.com/mlebreuil/netbox-contract/issues/178) Add the possibility to filter on invoice number, and contract name through the API. * [176](https://github.com/mlebreuil/netbox-contract/issues/176) Order accounting dimensions in tables alphabetically. +* [171](https://github.com/mlebreuil/netbox-contract/issues/171) It is now poaaible to define madatory accounting dimension by specifying their names in the 'mandatory_dimensions' list in the plugin settings. (see the "Customize the plugin" paragraph in the README.md file) ### Version 2.2.4 diff --git a/README.md b/README.md index 7018f6e..011d8ab 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,11 @@ PLUGINS_CONFIG = { "project": "", "cost center": "" }, - 'mandatory_contract_fields': ['accounting_dimensions'], + 'mandatory_contract_fields': [], 'hidden_contract_fields': [], - 'mandatory_invoice_fields': ['accounting_dimensions'], + 'mandatory_invoice_fields': [], 'hidden_invoice_fields': [], + 'mandatory_dimensions': [], } } diff --git a/src/netbox_contract/__init__.py b/src/netbox_contract/__init__.py index d98e980..11568ca 100644 --- a/src/netbox_contract/__init__.py +++ b/src/netbox_contract/__init__.py @@ -22,6 +22,7 @@ class ContractsConfig(PluginConfig): 'hidden_contract_fields': [], 'mandatory_invoice_fields': [], 'hidden_invoice_fields': [], + 'mandatory_dimensions': [], } diff --git a/src/netbox_contract/forms.py b/src/netbox_contract/forms.py index c4185be..e7682b3 100644 --- a/src/netbox_contract/forms.py +++ b/src/netbox_contract/forms.py @@ -509,6 +509,12 @@ def clean(self): else: dimensions_names.append(dimension.name) + # Make sure mandatory dimensions are present + mandatory_dimensions = plugin_settings.get('mandatory_dimensions') + for dimension in mandatory_dimensions: + if dimension not in dimensions_names: + raise ValidationError(f'dimension {dimension} missing') + class Meta: model = InvoiceLine fields = [