Skip to content

Commit

Permalink
Merge pull request #143 from mlebreuil/140-add-the-invoice-lines-model
Browse files Browse the repository at this point in the history
140 add the invoice lines model
  • Loading branch information
mlebreuil authored Jul 28, 2024
2 parents 51ec844 + f4b9957 commit b5a82dd
Show file tree
Hide file tree
Showing 36 changed files with 1,087 additions and 98 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.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
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
2 changes: 1 addition & 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.3"
version = "2.2.0"
authors = [
{ name="Marc Lebreuil", email="[email protected]" },
]
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.3'
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 b5a82dd

Please sign in to comment.