Skip to content

Commit

Permalink
Merge pull request #182 from mlebreuil/171-make-it-possible-to-define…
Browse files Browse the repository at this point in the history
…-mandatory-dimensions-for-invoice-lines

Allow mandatory accounting dimensions
  • Loading branch information
mlebreuil authored Sep 8, 2024
2 parents 6961c90 + 616fec6 commit 5d7705f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 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 @@
* 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

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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': [],
}
}

Expand Down
1 change: 1 addition & 0 deletions src/netbox_contract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ContractsConfig(PluginConfig):
'hidden_contract_fields': [],
'mandatory_invoice_fields': [],
'hidden_invoice_fields': [],
'mandatory_dimensions': [],
}


Expand Down
6 changes: 6 additions & 0 deletions src/netbox_contract/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 5d7705f

Please sign in to comment.