Skip to content

Commit fe1b8cb

Browse files
authored
Add metadata model to Company (inventree#3895)
* Add Metadata mixin to Company model * Add migration file * Lint * Fixes due to style * Syntax error * Lint * as this exposes a new endpoint to the API, increment the API version number with a brief description:
1 parent 278e9cf commit fe1b8cb

4 files changed

Lines changed: 42 additions & 4 deletions

File tree

InvenTree/InvenTree/api_version.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33

44
# InvenTree API version
5-
INVENTREE_API_VERSION = 78
5+
INVENTREE_API_VERSION = 79
66

77
"""
88
Increment this API version number whenever there is a significant change to the API that any clients need to know about
99
10+
v79 -> 2022-11-03 : https://github.com/inventree/InvenTree/pull/3895
11+
- Add metadata to Company
12+
1013
v78 -> 2022-10-25 : https://github.com/inventree/InvenTree/pull/3854
1114
- Make PartCategory to be filtered by name and description
1215

InvenTree/company/api.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
from InvenTree.api import AttachmentMixin, ListCreateDestroyAPIView
1111
from InvenTree.filters import InvenTreeOrderingFilter
1212
from InvenTree.helpers import str2bool
13-
from InvenTree.mixins import ListCreateAPI, RetrieveUpdateDestroyAPI
13+
from InvenTree.mixins import (ListCreateAPI, RetrieveUpdateAPI,
14+
RetrieveUpdateDestroyAPI)
15+
from plugin.serializers import MetadataSerializer
1416

1517
from .models import (Company, ManufacturerPart, ManufacturerPartAttachment,
1618
ManufacturerPartParameter, SupplierPart,
@@ -83,6 +85,16 @@ def get_queryset(self):
8385
return queryset
8486

8587

88+
class CompanyMetadata(RetrieveUpdateAPI):
89+
"""API endpoint for viewing / updating Company metadata."""
90+
91+
def get_serializer(self, *args, **kwargs):
92+
"""Return MetadataSerializer instance for a Company"""
93+
return MetadataSerializer(Company, *args, **kwargs)
94+
95+
queryset = Company.objects.all()
96+
97+
8698
class ManufacturerPartFilter(rest_filters.FilterSet):
8799
"""Custom API filters for the ManufacturerPart list endpoint."""
88100

@@ -460,7 +472,11 @@ class SupplierPriceBreakDetail(RetrieveUpdateDestroyAPI):
460472
re_path(r'^.*$', SupplierPriceBreakList.as_view(), name='api-part-supplier-price-list'),
461473
])),
462474

463-
re_path(r'^(?P<pk>\d+)/?', CompanyDetail.as_view(), name='api-company-detail'),
475+
re_path(r'^(?P<pk>\d+)/?', include([
476+
re_path(r'^metadata/', CompanyMetadata.as_view(), name='api-company-metadata'),
477+
re_path(r'^.*$', CompanyDetail.as_view(), name='api-company-detail'),
478+
])),
464479

465480
re_path(r'^.*$', CompanyList.as_view(), name='api-company-list'),
481+
466482
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.2.16 on 2022-11-02 17:53
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('company', '0048_auto_20220913_0312'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='company',
15+
name='metadata',
16+
field=models.JSONField(blank=True, help_text='JSON metadata field, for use by external plugins', null=True, verbose_name='Plugin Metadata'),
17+
),
18+
]

InvenTree/company/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from InvenTree.fields import InvenTreeURLField, RoundingDecimalField
2424
from InvenTree.models import InvenTreeAttachment, InvenTreeBarcodeMixin
2525
from InvenTree.status_codes import PurchaseOrderStatus
26+
from plugin.models import MetadataMixin
2627

2728

2829
def rename_company_image(instance, filename):
@@ -50,7 +51,7 @@ def rename_company_image(instance, filename):
5051
return os.path.join(base, fn)
5152

5253

53-
class Company(models.Model):
54+
class Company(MetadataMixin, models.Model):
5455
"""A Company object represents an external company.
5556
5657
It may be a supplier or a customer or a manufacturer (or a combination)

0 commit comments

Comments
 (0)