Skip to content

Commit

Permalink
Merge pull request #213 from mlebreuil/develop
Browse files Browse the repository at this point in the history
v2.3
  • Loading branch information
mlebreuil authored Jan 13, 2025
2 parents 469e971 + e71cf8a commit 4858857
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 19,340 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
### Version 2.3.0

> [!WARNING]
> Accounting dimension json field will be removed. It is deprecated since v2.2.0. Refer to the [documentation](https://mlebreuil.github.io/netbox-contract/accounting_dimensions/)
> Accounting dimension json field removed. It is deprecated since v2.2.0. Refer to the [documentation](https://mlebreuil.github.io/netbox-contract/accounting_dimensions/)
* [206](https://github.com/mlebreuil/netbox-contract/issues/206) remove deprecated json accounting dimention field
* Add background color to status
* Script - fix check_contract_end with empty end date
* minor fix

### Version 2.2.11

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ FIELD_CHOICES = {
('pln', 'PLN'),
),
'netbox_contract.Contract.status': (
('Active', 'Active', 'green'),
('Cancled', 'Canceled', 'red'),
('active', 'Active', 'green'),
('canceled', 'Canceled', 'red'),
)
}

Expand Down
19 changes: 10 additions & 9 deletions scripts/netbox-contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,15 @@ def run(self, data, commit):

contracts = Contract.objects.filter(status=StatusChoices.STATUS_ACTIVE)
for contract in contracts:
if contract.notice_date <= date.today() + timedelta(
days=days_before_notice
):
self.log_info(
f'Contract {contract} end date: {contract.end_date} - notice : {contract.notice_period} days'
)
output.append(
f'{contract.name} - end date: {contract.end_date} - notice : {contract.notice_period} days'
)
if contract.end_date is not None:
if contract.notice_date <= date.today() + timedelta(
days=days_before_notice
):
self.log_info(
f'Contract {contract} end date: {contract.end_date} - notice : {contract.notice_period} days'
)
output.append(
f'{contract.name} - end date: {contract.end_date} - notice : {contract.notice_period} days'
)

return '\n'.join(output)
5 changes: 0 additions & 5 deletions src/netbox_contract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class ContractsConfig(PluginConfig):
required_settings = []
default_settings = {
'top_level_menu': False,
'default_accounting_dimensions': {
'account': '',
'project': '',
'cost center': '',
},
'mandatory_contract_fields': [],
'hidden_contract_fields': [],
'mandatory_invoice_fields': [],
Expand Down
5 changes: 0 additions & 5 deletions src/netbox_contract/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Meta:
'initial_term',
'renewal_term',
'currency',
'accounting_dimensions',
'mrc',
'yrc',
'nrc',
Expand Down Expand Up @@ -115,7 +114,6 @@ class Meta:
'initial_term',
'renewal_term',
'currency',
'accounting_dimensions',
'mrc',
'yrc',
'nrc',
Expand Down Expand Up @@ -144,7 +142,6 @@ class Meta:
'initial_term',
'renewal_term',
'currency',
'accounting_dimensions',
'mrc',
'yrc',
'nrc',
Expand Down Expand Up @@ -188,7 +185,6 @@ class Meta:
'period_start',
'period_end',
'currency',
'accounting_dimensions',
'amount',
'comments',
'tags',
Expand All @@ -207,7 +203,6 @@ class Meta:
'period_start',
'period_end',
'currency',
'accounting_dimensions',
'amount',
'comments',
)
Expand Down
36 changes: 2 additions & 34 deletions src/netbox_contract/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
CSVModelMultipleChoiceField,
DynamicModelChoiceField,
DynamicModelMultipleChoiceField,
JSONField,
SlugField,
TagFilterField,
)
Expand All @@ -41,20 +40,6 @@
)

plugin_settings = settings.PLUGINS_CONFIG['netbox_contract']
default_dimensions = plugin_settings.get('default_accounting_dimensions')

# Dimensions
# Deprecated. To be removed in version 2.3.0


class Dimensions(JSONField):
"""
Custom wrapper around Netbox's JSONField
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.widget.attrs['placeholder'] = str(default_dimensions)


# Contract
Expand All @@ -81,7 +66,6 @@ class ContractForm(NetBoxModelForm):
selector=True,
label=_('Parent'),
)
accounting_dimensions = Dimensions(required=False, label=_('Accounting dimensions'))

def __init__(self, *args, **kwargs):
initial = kwargs.get('initial', None)
Expand Down Expand Up @@ -147,7 +131,6 @@ class Meta:
'renewal_term',
'notice_period',
'currency',
'accounting_dimensions',
'yrc',
'mrc',
'nrc',
Expand Down Expand Up @@ -237,7 +220,6 @@ class Meta:
'initial_term',
'renewal_term',
'currency',
'accounting_dimensions',
'yrc',
'mrc',
'nrc',
Expand Down Expand Up @@ -270,7 +252,6 @@ class ContractBulkEditForm(NetBoxModelBulkEditForm):
tenant = DynamicModelChoiceField(
queryset=Tenant.objects.all(), required=False, selector=True, label=_('Tenant')
)
accounting_dimensions = Dimensions(required=False, label=_('Accounting dimensions'))
comments = CommentField(required=False, label=_('Comments'))
parent = DynamicModelChoiceField(
queryset=Contract.objects.all(),
Expand All @@ -279,10 +260,7 @@ class ContractBulkEditForm(NetBoxModelBulkEditForm):
label=_('Parent'),
)

nullable_fields = (
'accounting_dimensions',
'comments',
)
nullable_fields = ('comments',)
model = Contract


Expand All @@ -301,7 +279,6 @@ class InvoiceForm(NetBoxModelForm):
selector=True,
label=_('Contracts'),
)
accounting_dimensions = Dimensions(required=False, label=_('Accounting dimensions'))

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -392,7 +369,6 @@ class Meta:
'period_start',
'period_end',
'currency',
'accounting_dimensions',
'amount',
'documents',
'comments',
Expand Down Expand Up @@ -446,7 +422,6 @@ class Meta:
'period_start',
'period_end',
'currency',
'accounting_dimensions',
'amount',
'documents',
'comments',
Expand Down Expand Up @@ -483,10 +458,6 @@ class InvoiceBulkEditForm(NetBoxModelBulkEditForm):
required=False,
label=_('Currency'),
)
accounting_dimensions = Dimensions(
required=False,
label=_('Accounting dimensions'),
)
amount = forms.DecimalField(
max_digits=10,
decimal_places=2,
Expand All @@ -501,10 +472,7 @@ class InvoiceBulkEditForm(NetBoxModelBulkEditForm):
comments = CommentField(
label=_('Comments'),
)
nullable_fields = (
'accounting_dimensions',
'comments',
)
nullable_fields = ('comments',)

model = Invoice

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.0.10 on 2025-01-05 11:13

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
(
'netbox_contract',
'0037_contract_notice_period_alter_contract_currency_and_more',
),
]

operations = [
migrations.AlterModelOptions(
name='accountingdimension',
options={'ordering': ('name', 'value')},
),
migrations.AlterModelOptions(
name='invoiceline',
options={'ordering': ('invoice',)},
),
migrations.RemoveField(
model_name='contract',
name='accounting_dimensions',
),
migrations.RemoveField(
model_name='invoice',
name='accounting_dimensions',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.10 on 2025-01-13 20:31

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('netbox_contract', '0038_alter_accountingdimension_options_and_more'),
]

operations = [
migrations.AlterField(
model_name='accountingdimension',
name='status',
field=models.CharField(default='active', max_length=50),
),
migrations.AlterField(
model_name='contract',
name='status',
field=models.CharField(default='active', max_length=50),
),
]
22 changes: 9 additions & 13 deletions src/netbox_contract/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
class StatusChoices(ChoiceSet):
key = 'Contract.status'

STATUS_ACTIVE = 'Active'
STATUS_CANCELED = 'Cancled'
STATUS_ACTIVE = 'active'
STATUS_CANCELED = 'canceled'

CHOICES = [
(STATUS_ACTIVE, 'Active', 'green'),
Expand All @@ -26,8 +26,8 @@ class StatusChoices(ChoiceSet):
class AccountingDimensionStatusChoices(ChoiceSet):
key = 'AccountingDimension.status'

STATUS_ACTIVE = 'Active'
STATUS_INACTIVE = 'Inactive'
STATUS_ACTIVE = 'active'
STATUS_INACTIVE = 'inactive'

CHOICES = [
(STATUS_ACTIVE, 'Active', 'green'),
Expand Down Expand Up @@ -84,6 +84,9 @@ def dimension(self):
def __str__(self):
return self.dimension

def get_status_color(self):
return AccountingDimensionStatusChoices.colors.get(self.status)

class Meta:
constraints = [
models.UniqueConstraint(
Expand Down Expand Up @@ -201,12 +204,6 @@ class Contract(NetBoxModel):
default=CURRENCY_DEFAULT,
verbose_name=_('currency'),
)
accounting_dimensions = models.JSONField(
null=True,
blank=True,
verbose_name=_('accounting dimensions'),
help_text=_('This field is deprecated and will be removed in version 2.3'),
)
yrc = models.DecimalField(
verbose_name=_('yearly recuring cost'),
max_digits=10,
Expand Down Expand Up @@ -249,6 +246,8 @@ class Contract(NetBoxModel):
def get_absolute_url(self):
return reverse('plugins:netbox_contract:contract', args=[self.pk])

def get_status_color(self):
return StatusChoices.colors.get(self.status)
class Meta:
ordering = ('name',)
indexes = [
Expand Down Expand Up @@ -290,9 +289,6 @@ class Invoice(NetBoxModel):
default=CURRENCY_DEFAULT,
verbose_name=_('currency'),
)
accounting_dimensions = models.JSONField(
null=True, verbose_name=_('accounting dimensions')
)
amount = models.DecimalField(
max_digits=10, decimal_places=2, verbose_name=_('amount')
)
Expand Down
10 changes: 8 additions & 2 deletions src/netbox_contract/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class ContractListTable(NetBoxTable):
external_partie_object = tables.Column(verbose_name='External partie', linkify=True)
parent = tables.Column(linkify=True)
yrc = tables.Column(verbose_name='Yerly recuring costs')
status = columns.ChoiceFieldColumn(
verbose_name=('Status'),
)

class Meta(NetBoxTable.Meta):
model = Contract
Expand All @@ -118,7 +121,6 @@ class Meta(NetBoxTable.Meta):
'initial_term',
'renewal_term',
'currency',
'accounting_dimensions',
'mrc',
'yrc',
'nrc',
Expand Down Expand Up @@ -173,7 +175,6 @@ class Meta(NetBoxTable.Meta):
'period_start',
'period_end',
'currency',
'accounting_dimensions',
'amount',
'documents',
'comments',
Expand Down Expand Up @@ -225,16 +226,21 @@ class Meta(NetBoxTable.Meta):


class AccountingDimensionListTable(NetBoxTable):
status = columns.ChoiceFieldColumn(
verbose_name=('Status'),
)
class Meta(NetBoxTable.Meta):
model = AccountingDimension
fields = (
'pk',
'name',
'value',
'comments',
'status',
)
default_columns = (
'name',
'value',
'comments',
'status',
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h5 class="card-header">{% trans "Accounting dimension" %}</h5>
</tr>
<tr>
<th scope="row">{% trans "Status" %}</th>
<td>{{ object.status }}</td>
<td>{% badge object.get_status_display bg_color=object.get_status_color %}</td>
</tr>
</table>
</div>
Expand Down
Loading

0 comments on commit 4858857

Please sign in to comment.