mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	Merge branch 'master' of https://github.com/inventree/InvenTree into plugin-2037
This commit is contained in:
		@@ -118,20 +118,31 @@ class InvenTreeMetadata(SimpleMetadata):
 | 
			
		||||
            # Iterate through simple fields
 | 
			
		||||
            for name, field in model_fields.fields.items():
 | 
			
		||||
 | 
			
		||||
                if field.has_default() and name in serializer_info.keys():
 | 
			
		||||
                if name in serializer_info.keys():
 | 
			
		||||
 | 
			
		||||
                    default = field.default
 | 
			
		||||
                    if field.has_default():
 | 
			
		||||
 | 
			
		||||
                    if callable(default):
 | 
			
		||||
                        try:
 | 
			
		||||
                            default = default()
 | 
			
		||||
                        except:
 | 
			
		||||
                            continue
 | 
			
		||||
                        default = field.default
 | 
			
		||||
 | 
			
		||||
                    serializer_info[name]['default'] = default
 | 
			
		||||
                        if callable(default):
 | 
			
		||||
                            try:
 | 
			
		||||
                                default = default()
 | 
			
		||||
                            except:
 | 
			
		||||
                                continue
 | 
			
		||||
 | 
			
		||||
                elif name in model_default_values:
 | 
			
		||||
                    serializer_info[name]['default'] = model_default_values[name]
 | 
			
		||||
                        serializer_info[name]['default'] = default
 | 
			
		||||
 | 
			
		||||
                    elif name in model_default_values:
 | 
			
		||||
                        serializer_info[name]['default'] = model_default_values[name]
 | 
			
		||||
 | 
			
		||||
                    # Attributes to copy from the model to the field (if they don't exist)
 | 
			
		||||
                    attributes = ['help_text']
 | 
			
		||||
 | 
			
		||||
                    for attr in attributes:
 | 
			
		||||
                        if attr not in serializer_info[name]:
 | 
			
		||||
 | 
			
		||||
                            if hasattr(field, attr):
 | 
			
		||||
                                serializer_info[name][attr] = getattr(field, attr)
 | 
			
		||||
 | 
			
		||||
            # Iterate through relations
 | 
			
		||||
            for name, relation in model_fields.relations.items():
 | 
			
		||||
 
 | 
			
		||||
@@ -296,3 +296,17 @@ class InvenTreeImageSerializerField(serializers.ImageField):
 | 
			
		||||
            return None
 | 
			
		||||
 | 
			
		||||
        return os.path.join(str(settings.MEDIA_URL), str(value))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class InvenTreeDecimalField(serializers.FloatField):
 | 
			
		||||
    """
 | 
			
		||||
    Custom serializer for decimal fields. Solves the following issues:
 | 
			
		||||
 | 
			
		||||
    - The normal DRF DecimalField renders values with trailing zeros
 | 
			
		||||
    - Using a FloatField can result in rounding issues: https://code.djangoproject.com/ticket/30290
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    def to_internal_value(self, data):
 | 
			
		||||
 | 
			
		||||
        # Convert the value to a string, and then a decimal
 | 
			
		||||
        return Decimal(str(data))
 | 
			
		||||
 
 | 
			
		||||
@@ -316,7 +316,7 @@ MIDDLEWARE = CONFIG.get('middleware', [
 | 
			
		||||
    'django.contrib.messages.middleware.MessageMiddleware',
 | 
			
		||||
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
 | 
			
		||||
    'InvenTree.middleware.AuthRequiredMiddleware',
 | 
			
		||||
    'maintenance_mode.middleware.MaintenanceModeMiddleware'
 | 
			
		||||
    'maintenance_mode.middleware.MaintenanceModeMiddleware',
 | 
			
		||||
])
 | 
			
		||||
 | 
			
		||||
# Error reporting middleware
 | 
			
		||||
@@ -680,6 +680,7 @@ LANGUAGES = [
 | 
			
		||||
    ('el', _('Greek')),
 | 
			
		||||
    ('en', _('English')),
 | 
			
		||||
    ('es', _('Spanish')),
 | 
			
		||||
    ('es-mx', _('Spanish (Mexican')),
 | 
			
		||||
    ('fr', _('French')),
 | 
			
		||||
    ('he', _('Hebrew')),
 | 
			
		||||
    ('it', _('Italian')),
 | 
			
		||||
 
 | 
			
		||||
@@ -18,8 +18,9 @@ from rest_framework.serializers import ValidationError
 | 
			
		||||
from InvenTree.serializers import InvenTreeModelSerializer, InvenTreeAttachmentSerializer
 | 
			
		||||
from InvenTree.serializers import InvenTreeAttachmentSerializerField, UserSerializerBrief
 | 
			
		||||
 | 
			
		||||
from InvenTree.status_codes import StockStatus
 | 
			
		||||
import InvenTree.helpers
 | 
			
		||||
from InvenTree.serializers import InvenTreeDecimalField
 | 
			
		||||
from InvenTree.status_codes import StockStatus
 | 
			
		||||
 | 
			
		||||
from stock.models import StockItem, StockLocation
 | 
			
		||||
from stock.serializers import StockItemSerializerBrief, LocationSerializer
 | 
			
		||||
@@ -41,7 +42,7 @@ class BuildSerializer(InvenTreeModelSerializer):
 | 
			
		||||
 | 
			
		||||
    part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
 | 
			
		||||
 | 
			
		||||
    quantity = serializers.FloatField()
 | 
			
		||||
    quantity = InvenTreeDecimalField()
 | 
			
		||||
 | 
			
		||||
    overdue = serializers.BooleanField(required=False, read_only=True)
 | 
			
		||||
 | 
			
		||||
@@ -473,7 +474,7 @@ class BuildItemSerializer(InvenTreeModelSerializer):
 | 
			
		||||
    stock_item_detail = StockItemSerializerBrief(source='stock_item', read_only=True)
 | 
			
		||||
    location_detail = LocationSerializer(source='stock_item.location', read_only=True)
 | 
			
		||||
 | 
			
		||||
    quantity = serializers.FloatField()
 | 
			
		||||
    quantity = InvenTreeDecimalField()
 | 
			
		||||
 | 
			
		||||
    def __init__(self, *args, **kwargs):
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,9 +8,10 @@ from rest_framework import serializers
 | 
			
		||||
 | 
			
		||||
from sql_util.utils import SubqueryCount
 | 
			
		||||
 | 
			
		||||
from InvenTree.serializers import InvenTreeDecimalField
 | 
			
		||||
from InvenTree.serializers import InvenTreeImageSerializerField
 | 
			
		||||
from InvenTree.serializers import InvenTreeModelSerializer
 | 
			
		||||
from InvenTree.serializers import InvenTreeMoneySerializer
 | 
			
		||||
from InvenTree.serializers import InvenTreeImageSerializerField
 | 
			
		||||
 | 
			
		||||
from part.serializers import PartBriefSerializer
 | 
			
		||||
 | 
			
		||||
@@ -255,7 +256,7 @@ class SupplierPartSerializer(InvenTreeModelSerializer):
 | 
			
		||||
class SupplierPriceBreakSerializer(InvenTreeModelSerializer):
 | 
			
		||||
    """ Serializer for SupplierPriceBreak object """
 | 
			
		||||
 | 
			
		||||
    quantity = serializers.FloatField()
 | 
			
		||||
    quantity = InvenTreeDecimalField()
 | 
			
		||||
 | 
			
		||||
    price = InvenTreeMoneySerializer(
 | 
			
		||||
        allow_null=True,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								InvenTree/locale/es_MX/LC_MESSAGES/django.mo
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								InvenTree/locale/es_MX/LC_MESSAGES/django.mo
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										8451
									
								
								InvenTree/locale/es_MX/LC_MESSAGES/django.po
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8451
									
								
								InvenTree/locale/es_MX/LC_MESSAGES/django.po
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -17,8 +17,9 @@ from rest_framework.serializers import ValidationError
 | 
			
		||||
 | 
			
		||||
from sql_util.utils import SubqueryCount
 | 
			
		||||
 | 
			
		||||
from InvenTree.serializers import InvenTreeModelSerializer
 | 
			
		||||
from InvenTree.serializers import InvenTreeAttachmentSerializer
 | 
			
		||||
from InvenTree.serializers import InvenTreeModelSerializer
 | 
			
		||||
from InvenTree.serializers import InvenTreeDecimalField
 | 
			
		||||
from InvenTree.serializers import InvenTreeMoneySerializer
 | 
			
		||||
from InvenTree.serializers import InvenTreeAttachmentSerializerField
 | 
			
		||||
 | 
			
		||||
@@ -551,8 +552,8 @@ class SOLineItemSerializer(InvenTreeModelSerializer):
 | 
			
		||||
    part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
 | 
			
		||||
    allocations = SalesOrderAllocationSerializer(many=True, read_only=True, location_detail=True)
 | 
			
		||||
 | 
			
		||||
    quantity = serializers.FloatField()
 | 
			
		||||
 | 
			
		||||
    quantity = InvenTreeDecimalField()
 | 
			
		||||
    
 | 
			
		||||
    allocated = serializers.FloatField(source='allocated_quantity', read_only=True)
 | 
			
		||||
    fulfilled = serializers.FloatField(source='fulfilled_quantity', read_only=True)
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ from sql_util.utils import SubqueryCount, SubquerySum
 | 
			
		||||
from djmoney.contrib.django_rest_framework import MoneyField
 | 
			
		||||
 | 
			
		||||
from InvenTree.serializers import (InvenTreeAttachmentSerializerField,
 | 
			
		||||
                                   InvenTreeDecimalField,
 | 
			
		||||
                                   InvenTreeImageSerializerField,
 | 
			
		||||
                                   InvenTreeModelSerializer,
 | 
			
		||||
                                   InvenTreeAttachmentSerializer,
 | 
			
		||||
@@ -120,7 +121,7 @@ class PartSalePriceSerializer(InvenTreeModelSerializer):
 | 
			
		||||
    Serializer for sale prices for Part model.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    quantity = serializers.FloatField()
 | 
			
		||||
    quantity = InvenTreeDecimalField()
 | 
			
		||||
 | 
			
		||||
    price = InvenTreeMoneySerializer(
 | 
			
		||||
        allow_null=True
 | 
			
		||||
@@ -144,7 +145,7 @@ class PartInternalPriceSerializer(InvenTreeModelSerializer):
 | 
			
		||||
    Serializer for internal prices for Part model.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    quantity = serializers.FloatField()
 | 
			
		||||
    quantity = InvenTreeDecimalField()
 | 
			
		||||
 | 
			
		||||
    price = InvenTreeMoneySerializer(
 | 
			
		||||
        allow_null=True
 | 
			
		||||
@@ -428,7 +429,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
 | 
			
		||||
 | 
			
		||||
    price_range = serializers.CharField(read_only=True)
 | 
			
		||||
 | 
			
		||||
    quantity = serializers.FloatField()
 | 
			
		||||
    quantity = InvenTreeDecimalField()
 | 
			
		||||
 | 
			
		||||
    part = serializers.PrimaryKeyRelatedField(queryset=Part.objects.filter(assembly=True))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -69,6 +69,13 @@ class StockDetail(generics.RetrieveUpdateDestroyAPIView):
 | 
			
		||||
 | 
			
		||||
        return queryset
 | 
			
		||||
 | 
			
		||||
    def get_serializer_context(self):
 | 
			
		||||
 | 
			
		||||
        ctx = super().get_serializer_context()
 | 
			
		||||
        ctx['user'] = getattr(self.request, 'user', None)
 | 
			
		||||
 | 
			
		||||
        return ctx
 | 
			
		||||
 | 
			
		||||
    def get_serializer(self, *args, **kwargs):
 | 
			
		||||
 | 
			
		||||
        kwargs['part_detail'] = True
 | 
			
		||||
@@ -79,16 +86,6 @@ class StockDetail(generics.RetrieveUpdateDestroyAPIView):
 | 
			
		||||
 | 
			
		||||
        return self.serializer_class(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def update(self, request, *args, **kwargs):
 | 
			
		||||
        """
 | 
			
		||||
        Record the user who updated the item
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        # TODO: Record the user!
 | 
			
		||||
        # user = request.user
 | 
			
		||||
 | 
			
		||||
        return super().update(request, *args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def perform_destroy(self, instance):
 | 
			
		||||
        """
 | 
			
		||||
        Instead of "deleting" the StockItem
 | 
			
		||||
@@ -392,6 +389,13 @@ class StockList(generics.ListCreateAPIView):
 | 
			
		||||
    queryset = StockItem.objects.all()
 | 
			
		||||
    filterset_class = StockFilter
 | 
			
		||||
 | 
			
		||||
    def get_serializer_context(self):
 | 
			
		||||
 | 
			
		||||
        ctx = super().get_serializer_context()
 | 
			
		||||
        ctx['user'] = getattr(self.request, 'user', None)
 | 
			
		||||
 | 
			
		||||
        return ctx
 | 
			
		||||
 | 
			
		||||
    def create(self, request, *args, **kwargs):
 | 
			
		||||
        """
 | 
			
		||||
        Create a new StockItem object via the API.
 | 
			
		||||
 
 | 
			
		||||
@@ -265,15 +265,15 @@ class StockItem(MPTTModel):
 | 
			
		||||
 | 
			
		||||
        user = kwargs.pop('user', None)
 | 
			
		||||
 | 
			
		||||
        if user is None:
 | 
			
		||||
            user = getattr(self, '_user', None)
 | 
			
		||||
 | 
			
		||||
        # If 'add_note = False' specified, then no tracking note will be added for item creation
 | 
			
		||||
        add_note = kwargs.pop('add_note', True)
 | 
			
		||||
 | 
			
		||||
        notes = kwargs.pop('notes', '')
 | 
			
		||||
 | 
			
		||||
        if not self.pk:
 | 
			
		||||
            # StockItem has not yet been saved
 | 
			
		||||
            add_note = add_note and True
 | 
			
		||||
        else:
 | 
			
		||||
        
 | 
			
		||||
        if self.pk:
 | 
			
		||||
            # StockItem has already been saved
 | 
			
		||||
 | 
			
		||||
            # Check if "interesting" fields have been changed
 | 
			
		||||
@@ -301,11 +301,10 @@ class StockItem(MPTTModel):
 | 
			
		||||
            except (ValueError, StockItem.DoesNotExist):
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
            add_note = False
 | 
			
		||||
 | 
			
		||||
        super(StockItem, self).save(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
        if add_note:
 | 
			
		||||
        # If user information is provided, and no existing note exists, create one!
 | 
			
		||||
        if user and self.tracking_info.count() == 0:
 | 
			
		||||
 | 
			
		||||
            tracking_info = {
 | 
			
		||||
                'status': self.status,
 | 
			
		||||
 
 | 
			
		||||
@@ -32,6 +32,7 @@ from company.serializers import SupplierPartSerializer
 | 
			
		||||
 | 
			
		||||
import InvenTree.helpers
 | 
			
		||||
import InvenTree.serializers
 | 
			
		||||
from InvenTree.serializers import InvenTreeDecimalField
 | 
			
		||||
 | 
			
		||||
from part.serializers import PartBriefSerializer
 | 
			
		||||
 | 
			
		||||
@@ -55,7 +56,8 @@ class StockItemSerializerBrief(InvenTree.serializers.InvenTreeModelSerializer):
 | 
			
		||||
 | 
			
		||||
    location_name = serializers.CharField(source='location', read_only=True)
 | 
			
		||||
    part_name = serializers.CharField(source='part.full_name', read_only=True)
 | 
			
		||||
    quantity = serializers.FloatField()
 | 
			
		||||
    
 | 
			
		||||
    quantity = InvenTreeDecimalField()
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = StockItem
 | 
			
		||||
@@ -79,6 +81,15 @@ class StockItemSerializer(InvenTree.serializers.InvenTreeModelSerializer):
 | 
			
		||||
    - Includes serialization for the item location
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    def update(self, instance, validated_data):
 | 
			
		||||
        """
 | 
			
		||||
        Custom update method to pass the user information through to the instance
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        instance._user = self.context['user']
 | 
			
		||||
 | 
			
		||||
        return super().update(instance, validated_data)
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def annotate_queryset(queryset):
 | 
			
		||||
        """
 | 
			
		||||
@@ -136,7 +147,7 @@ class StockItemSerializer(InvenTree.serializers.InvenTreeModelSerializer):
 | 
			
		||||
 | 
			
		||||
    tracking_items = serializers.IntegerField(source='tracking_info_count', read_only=True, required=False)
 | 
			
		||||
 | 
			
		||||
    # quantity = serializers.FloatField()
 | 
			
		||||
    quantity = InvenTreeDecimalField()
 | 
			
		||||
 | 
			
		||||
    allocated = serializers.FloatField(source='allocation_count', required=False)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user