Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/inventree/InvenTree into …
Browse files Browse the repository at this point in the history
…pui-scan-page
  • Loading branch information
matmair committed Sep 14, 2023
2 parents a5cf9aa + 56fdbc0 commit ad4a782
Show file tree
Hide file tree
Showing 118 changed files with 17,118 additions and 8,692 deletions.
6 changes: 6 additions & 0 deletions InvenTree/InvenTree/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ class AttachmentMixin:

filter_backends = SEARCH_ORDER_FILTER

search_fields = [
'attachment',
'comment',
'link',
]

def perform_create(self, serializer):
"""Save the user information when a file is uploaded."""
attachment = serializer.save()
Expand Down
11 changes: 10 additions & 1 deletion InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@


# InvenTree API version
INVENTREE_API_VERSION = 131
INVENTREE_API_VERSION = 134

"""
Increment this API version number whenever there is a significant change to the API that any clients need to know about
v134 -> 2023-09-11 : https://github.com/inventree/InvenTree/pull/5525
- Allow "Attachment" list endpoints to be searched by attachment, link and comment fields
v133 -> 2023-09-08 : https://github.com/inventree/InvenTree/pull/5518
- Add extra optional fields which can be used for StockAdjustment endpoints
v132 -> 2023-09-07 : https://github.com/inventree/InvenTree/pull/5515
- Add 'issued_by' filter to BuildOrder API list endpoint
v131 -> 2023-08-09 : https://github.com/inventree/InvenTree/pull/5415
- Annotate 'available_variant_stock' to the SalesOrderLine serializer
Expand Down
4 changes: 2 additions & 2 deletions InvenTree/InvenTree/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def convert_physical_value(value: str, unit: str = None, strip_units=True):
val = ureg.Quantity(value, unit)
else:
# Convert to the provided unit (may raise an exception)
val = val.to(unit)
val = val.to(ureg.Unit(unit))

# At this point we *should* have a valid pint value
# To double check, look at the maginitude
Expand Down Expand Up @@ -134,7 +134,7 @@ def convert_physical_value(value: str, unit: str = None, strip_units=True):
# So, we ensure that it is converted to a floating point value
# If we wish to return a "raw" value, some trickery is required
if unit:
magnitude = ureg.Quantity(val.to(unit)).magnitude
magnitude = ureg.Quantity(val.to(ureg.Unit(unit))).magnitude
else:
magnitude = ureg.Quantity(val.to_base_units()).magnitude

Expand Down
5 changes: 1 addition & 4 deletions InvenTree/build/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Meta:
'parent',
'sales_order',
'part',
'issued_by',
]

status = rest_filters.NumberFilter(label='Status')
Expand Down Expand Up @@ -582,10 +583,6 @@ class BuildAttachmentList(AttachmentMixin, ListCreateDestroyAPIView):
queryset = BuildOrderAttachment.objects.all()
serializer_class = build.serializers.BuildAttachmentSerializer

filter_backends = [
DjangoFilterBackend,
]

filterset_fields = [
'build',
]
Expand Down
6 changes: 3 additions & 3 deletions InvenTree/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def save(self, *args, **kwargs):

do_cache = kwargs.pop('cache', True)

self.clean(**kwargs)
self.clean()
self.validate_unique()

# Execute before_save action
Expand Down Expand Up @@ -604,7 +604,7 @@ def units(self):
"""Return units for setting."""
return self.__class__.get_setting_units(self.key, **self.get_filters_for_instance())

def clean(self, **kwargs):
def clean(self):
"""If a validator (or multiple validators) are defined for a particular setting key, run them against the 'value' field."""
super().clean()

Expand All @@ -615,7 +615,7 @@ def clean(self, **kwargs):
elif self.is_bool():
self.value = self.as_bool()

validator = self.__class__.get_setting_validator(self.key, **kwargs)
validator = self.__class__.get_setting_validator(self.key, **self.get_filters_for_instance())

if validator is not None:
self.run_validator(validator)
Expand Down
31 changes: 31 additions & 0 deletions InvenTree/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from django.contrib.auth import get_user_model
from django.core.cache import cache
from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import Client, TestCase
from django.urls import reverse
Expand Down Expand Up @@ -142,6 +143,36 @@ def mocked(key, **kwargs):
InvenTreeSetting.set_setting('CD', "world", self.user)
self.assertEqual(InvenTreeSetting.check_all_settings(), (True, []))

@mock.patch("common.models.InvenTreeSetting.get_setting_definition")
def test_settings_validator(self, get_setting_definition):
"""Make sure that the validator function gets called on set setting."""

def validator(x):
if x == "hello":
return x

raise ValidationError(f"{x} is not valid")

mock_validator = mock.Mock(side_effect=validator)

# define partial schema
settings_definition = {
"AB": { # key that's has not already been accessed
"validator": mock_validator,
},
}

def mocked(key, **kwargs):
return settings_definition.get(key, {})
get_setting_definition.side_effect = mocked

InvenTreeSetting.set_setting("AB", "hello", self.user)
mock_validator.assert_called_with("hello")

with self.assertRaises(ValidationError):
InvenTreeSetting.set_setting("AB", "world", self.user)
mock_validator.assert_called_with("world")

def run_settings_check(self, key, setting):
"""Test that all settings are valid.
Expand Down
9 changes: 0 additions & 9 deletions InvenTree/company/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.urls import include, path, re_path

from django_filters import rest_framework as rest_filters
from django_filters.rest_framework import DjangoFilterBackend

import part.models
from InvenTree.api import (AttachmentMixin, ListCreateDestroyAPIView,
Expand Down Expand Up @@ -89,10 +88,6 @@ class CompanyAttachmentList(AttachmentMixin, ListCreateDestroyAPIView):
queryset = CompanyAttachment.objects.all()
serializer_class = CompanyAttachmentSerializer

filter_backends = [
DjangoFilterBackend,
]

filterset_fields = [
'company',
]
Expand Down Expand Up @@ -246,10 +241,6 @@ class ManufacturerPartAttachmentList(AttachmentMixin, ListCreateDestroyAPIView):
queryset = ManufacturerPartAttachment.objects.all()
serializer_class = ManufacturerPartAttachmentSerializer

filter_backends = [
DjangoFilterBackend,
]

filterset_fields = [
'manufacturer_part',
]
Expand Down
Loading

0 comments on commit ad4a782

Please sign in to comment.