diff --git a/InvenTree/InvenTree/metadata.py b/InvenTree/InvenTree/metadata.py index 611b12101c..85815d2558 100644 --- a/InvenTree/InvenTree/metadata.py +++ b/InvenTree/InvenTree/metadata.py @@ -6,6 +6,7 @@ import logging from rest_framework import serializers from rest_framework.metadata import SimpleMetadata +from rest_framework.utils import model_meta import users.models @@ -41,11 +42,11 @@ class InvenTreeMetadata(SimpleMetadata): try: # Extract the model name associated with the view - model = view.serializer_class.Meta.model + self.model = view.serializer_class.Meta.model # Construct the 'table name' from the model - app_label = model._meta.app_label - tbl_label = model._meta.model_name + app_label = self.model._meta.app_label + tbl_label = self.model._meta.model_name table = f"{app_label}_{tbl_label}" @@ -83,6 +84,37 @@ class InvenTreeMetadata(SimpleMetadata): return metadata + def get_serializer_info(self, serializer): + """ + Override get_serializer_info so that we can add 'default' values + to any fields whose Meta.model specifies a default value + """ + + field_info = super().get_serializer_info(serializer) + + try: + ModelClass = serializer.Meta.model + + model_fields = model_meta.get_field_info(ModelClass) + + for name, field in model_fields.fields.items(): + + if field.has_default() and name in field_info.keys(): + + default = field.default + + if callable(default): + try: + default = default() + except: + continue + + field_info[name]['default'] = default + except AttributeError: + pass + + return field_info + def get_field_info(self, field): """ Given an instance of a serializer field, return a dictionary diff --git a/InvenTree/company/templates/company/index.html b/InvenTree/company/templates/company/index.html index 3a3168f24e..2f7319fb74 100644 --- a/InvenTree/company/templates/company/index.html +++ b/InvenTree/company/templates/company/index.html @@ -15,10 +15,13 @@ {% if pagetype == 'manufacturers' and roles.purchase_order.add or pagetype == 'suppliers' and roles.purchase_order.add or pagetype == 'customers' and roles.sales_order.add %}
+ +
-
{% endif %} @@ -35,6 +38,22 @@ }); }); + $('#new-company-2').click(function() { + constructForm( + '{% url "api-company-list" %}', + { + method: 'POST', + fields: [ + 'name', + 'description', + 'is_supplier', + 'is_manufacturer', + 'is_customer', + ] + } + ); + }); + loadCompanyTable("#company-table", "{% url 'api-company-list' %}", { pagetype: '{{ pagetype }}', diff --git a/RELEASE.md b/RELEASE.md index 90fb027a62..7d6d0fba23 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -21,3 +21,7 @@ Create new release for the [inventree documentation](https://github.com/inventre ### Python Library Release Create new release for the [inventree python library](https://github.com/inventree/inventree-python) + +## App Release + +Create new versioned release for the InvenTree mobile app.