Skip to content

Commit

Permalink
Merge pull request #145 from mlebreuil/develop
Browse files Browse the repository at this point in the history
v2.2.0
  • Loading branch information
mlebreuil authored Jul 28, 2024
2 parents f51fbbd + b5a82dd commit 35e4368
Show file tree
Hide file tree
Showing 45 changed files with 20,920 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
rev: 23.11.0
hooks:
- id: black
language_version: python3.12
language_version: python3
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
Expand Down
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.0

* [140](https://github.com/mlebreuil/netbox-contract/issues/140) Add the "Invoice line" and "Accounting dimension" models. In order to simplify invoices creation, it is possible to selsct one invoice as the template for each contract; Its accounting lines will automatically be copied to the new invoices for the contract. The amount of the first line will be updated so that the sum of the amount for each invoice line match the invoice amount.

### Version 2.1.2

* [127](https://github.com/mlebreuil/netbox-contract/issues/135) Fix service provider creation issue
Expand Down
114 changes: 0 additions & 114 deletions UTILS.md

This file was deleted.

5 changes: 5 additions & 0 deletions docs/accounting_dimensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Accounting dimensions

![Accounting dimensions](img/accrounting_dimensions.png "accounting dimensions")


7 changes: 7 additions & 0 deletions docs/contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Contract

![Contract](img/contract.png "contract")

Linked objects:

![Contract linked objects](img/contract_linked_objects.png "contract linked objects")
Binary file added docs/img/accounting_dimensions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/contract.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/contract_linked_objects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/invoice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/invoice_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/invoice_linked_objects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/invoice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Invoice

![Invoice](img/invoice.png "invoice")

Linked objects:

![Invoice linked objects](img/invoice_linked_objects.png "invoice linked objects")
5 changes: 5 additions & 0 deletions docs/invoice_line.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Invoice line

![Invoice line](img/invoice_line.png "invoice line")


4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ repo_url: https://github.com/mlebreuil/netbox-contract
repo_name: netbox-contract
nav:
- Home: index.md
- Contract: contract.md
- Invoice: invoice.md
- Invoice line: invoice_line.md
- Accounting dimensions: accounting_dimensions.md
- Contributing: contributing.md
- Changelog: changelog.md
theme:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "netbox-contract"
version = "2.1.2"
version = "2.2.0"
authors = [
{ name="Marc Lebreuil", email="[email protected]" },
]
Expand All @@ -9,6 +9,7 @@ readme = "README.md"
requires-python = ">=3.10"
dependencies = [
'python-dateutil',
'drf_yasg',
]
classifiers = [
"Programming Language :: Python :: 3",
Expand Down
2 changes: 1 addition & 1 deletion src/netbox_contract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ContractsConfig(PluginConfig):
name = 'netbox_contract'
verbose_name = 'Netbox contract'
description = 'Contract management plugin for Netbox'
version = '2.1.2'
version = '2.2.0'
author = 'Marc Lebreuil'
author_email = '[email protected]'
base_url = 'contracts'
Expand Down
76 changes: 75 additions & 1 deletion src/netbox_contract/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
from tenancy.api.nested_serializers import NestedTenantSerializer
from utilities.api import get_serializer_for_model

from ..models import Contract, ContractAssignment, Invoice, ServiceProvider
from ..models import (
AccountingDimension,
Contract,
ContractAssignment,
Invoice,
InvoiceLine,
ServiceProvider,
)


class NestedServiceProviderSerializer(WritableNestedSerializer):
Expand Down Expand Up @@ -52,6 +59,28 @@ class Meta:
brief_fields = ('id', 'url', 'display', 'contract', 'content_object')


class NestedInvoicelineSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
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')


class NestedAccountingDimensionSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:AccountingDimension-detail'
)

class Meta:
model = AccountingDimension
fields = ('id', 'url', 'display', 'name', 'value')
brief_fields = ('id', 'url', 'display', 'name', 'value')


class ContractSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:contract-detail'
Expand Down Expand Up @@ -192,3 +221,48 @@ def get_content_object(self, instance):
)
context = {'request': self.context['request']}
return serializer(instance.content_object, context=context).data


class InvoiceLineSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:invoiceline-detail'
)

class Meta:
model = InvoiceLine
fields = (
'id',
'url',
'display',
'invoice',
'amount',
'currency',
'comments',
'tags',
'custom_fields',
'created',
'last_updated',
)
brief_fields = ('invoice', 'amount', 'url', 'display', 'name')


class AccountingDimensionSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:accountingdimension-detail'
)

class Meta:
model = AccountingDimension
fields = (
'id',
'url',
'display',
'name',
'value',
'comments',
'tags',
'custom_fields',
'created',
'last_updated',
)
brief_fields = ('name', 'value', 'url', 'display')
2 changes: 2 additions & 0 deletions src/netbox_contract/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
router.register('invoices', views.InvoiceViewSet)
router.register('serviceproviders', views.ServiceProviderViewSet)
router.register('contractassignment', views.ContractAssignmentViewSet)
router.register('invoiceline', views.InvoiceLineViewSet)
router.register('accountingdimension', views.AccountingDimensionViewSet)

urlpatterns = router.urls
12 changes: 12 additions & 0 deletions src/netbox_contract/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from .. import filtersets, models
from .serializers import (
AccountingDimensionSerializer,
ContractAssignmentSerializer,
ContractSerializer,
InvoiceLineSerializer,
InvoiceSerializer,
ServiceProviderSerializer,
)
Expand All @@ -31,3 +33,13 @@ class ServiceProviderViewSet(NetBoxModelViewSet):
class ContractAssignmentViewSet(NetBoxModelViewSet):
queryset = models.ContractAssignment.objects.prefetch_related('contract', 'tags')
serializer_class = ContractAssignmentSerializer


class InvoiceLineViewSet(NetBoxModelViewSet):
queryset = models.InvoiceLine.objects.prefetch_related('invoice', 'tags')
serializer_class = InvoiceLineSerializer


class AccountingDimensionViewSet(NetBoxModelViewSet):
queryset = models.AccountingDimension.objects.prefetch_related('tags')
serializer_class = AccountingDimensionSerializer
36 changes: 32 additions & 4 deletions src/netbox_contract/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from django.db.models import Q
from netbox.filtersets import NetBoxModelFilterSet

from .models import Contract, ContractAssignment, Invoice, ServiceProvider
from .models import (
AccountingDimension,
Contract,
ContractAssignment,
Invoice,
InvoiceLine,
ServiceProvider,
)


class ContractFilterSet(NetBoxModelFilterSet):
Expand All @@ -14,7 +21,7 @@ def search(self, queryset, name, value):
Q(name__icontains=value)
| Q(external_reference__icontains=value)
| Q(comments__icontains=value),
Q(status__iexact='Active')
Q(status__iexact='Active'),
)


Expand All @@ -25,8 +32,7 @@ class Meta:

def search(self, queryset, name, value):
return queryset.filter(
Q(number__icontains=value)
| Q(contracts__name__icontains=value)
Q(number__icontains=value) | Q(contracts__name__icontains=value)
)


Expand All @@ -46,3 +52,25 @@ class Meta:

def search(self, queryset, name, value):
return queryset.filter(Q(contract__name__icontains=value))


class InvoiceLineFilterSet(NetBoxModelFilterSet):
class Meta:
model = InvoiceLine
fields = ('id', 'invoice')

def search(self, queryset, name, value):
return queryset.filter(
Q(comments__icontains=value) | Q(invoice__name__icontains=value)
)


class AccountingDimensionFilterSet(NetBoxModelFilterSet):
class Meta:
model = AccountingDimension
fields = ('name', 'value')

def search(self, queryset, name, value):
return queryset.filter(
Q(comments__icontains=value) | Q(invoice__name__icontains=value)
)
Loading

0 comments on commit 35e4368

Please sign in to comment.