diff --git a/InvenTree/InvenTree/api_version.py b/InvenTree/InvenTree/api_version.py index 553ff85251..d462f759a2 100644 --- a/InvenTree/InvenTree/api_version.py +++ b/InvenTree/InvenTree/api_version.py @@ -2,11 +2,14 @@ # InvenTree API version -INVENTREE_API_VERSION = 78 +INVENTREE_API_VERSION = 79 """ Increment this API version number whenever there is a significant change to the API that any clients need to know about +v79 -> 2022-11-03 : https://github.com/inventree/InvenTree/pull/3895 + - Add metadata to Company + v78 -> 2022-10-25 : https://github.com/inventree/InvenTree/pull/3854 - Make PartCategory to be filtered by name and description diff --git a/InvenTree/company/api.py b/InvenTree/company/api.py index 83f6b34a08..3b194a9946 100644 --- a/InvenTree/company/api.py +++ b/InvenTree/company/api.py @@ -10,7 +10,9 @@ from rest_framework import filters from InvenTree.api import AttachmentMixin, ListCreateDestroyAPIView from InvenTree.filters import InvenTreeOrderingFilter from InvenTree.helpers import str2bool -from InvenTree.mixins import ListCreateAPI, RetrieveUpdateDestroyAPI +from InvenTree.mixins import (ListCreateAPI, RetrieveUpdateAPI, + RetrieveUpdateDestroyAPI) +from plugin.serializers import MetadataSerializer from .models import (Company, ManufacturerPart, ManufacturerPartAttachment, ManufacturerPartParameter, SupplierPart, @@ -83,6 +85,16 @@ class CompanyDetail(RetrieveUpdateDestroyAPI): return queryset +class CompanyMetadata(RetrieveUpdateAPI): + """API endpoint for viewing / updating Company metadata.""" + + def get_serializer(self, *args, **kwargs): + """Return MetadataSerializer instance for a Company""" + return MetadataSerializer(Company, *args, **kwargs) + + queryset = Company.objects.all() + + class ManufacturerPartFilter(rest_filters.FilterSet): """Custom API filters for the ManufacturerPart list endpoint.""" @@ -460,7 +472,11 @@ company_api_urls = [ re_path(r'^.*$', SupplierPriceBreakList.as_view(), name='api-part-supplier-price-list'), ])), - re_path(r'^(?P\d+)/?', CompanyDetail.as_view(), name='api-company-detail'), + re_path(r'^(?P\d+)/?', include([ + re_path(r'^metadata/', CompanyMetadata.as_view(), name='api-company-metadata'), + re_path(r'^.*$', CompanyDetail.as_view(), name='api-company-detail'), + ])), re_path(r'^.*$', CompanyList.as_view(), name='api-company-list'), + ] diff --git a/InvenTree/company/migrations/0049_company_metadata.py b/InvenTree/company/migrations/0049_company_metadata.py new file mode 100644 index 0000000000..de10f120cd --- /dev/null +++ b/InvenTree/company/migrations/0049_company_metadata.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.16 on 2022-11-02 17:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('company', '0048_auto_20220913_0312'), + ] + + operations = [ + migrations.AddField( + model_name='company', + name='metadata', + field=models.JSONField(blank=True, help_text='JSON metadata field, for use by external plugins', null=True, verbose_name='Plugin Metadata'), + ), + ] diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index 67b48a0e85..1198a583b1 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -23,6 +23,7 @@ from common.settings import currency_code_default from InvenTree.fields import InvenTreeURLField, RoundingDecimalField from InvenTree.models import InvenTreeAttachment, InvenTreeBarcodeMixin from InvenTree.status_codes import PurchaseOrderStatus +from plugin.models import MetadataMixin def rename_company_image(instance, filename): @@ -50,7 +51,7 @@ def rename_company_image(instance, filename): return os.path.join(base, fn) -class Company(models.Model): +class Company(MetadataMixin, models.Model): """A Company object represents an external company. It may be a supplier or a customer or a manufacturer (or a combination)