コード例 #1
0
ファイル: barcode.py プロジェクト: renatovelasquez/InvenTree
    def renderStockLocation(self, loc):
        """
        Render a stock location to a JSON response
        """

        serializer = LocationSerializer(loc)
        return serializer.data
コード例 #2
0
ファイル: barcode.py プロジェクト: jnewlands/InvenTree
    def render_stock_location(self, loc):
        """
        Render a StockLocation object to JSON
        Use the existing serializer to do this.
        """

        serializer = LocationSerializer(loc)

        return serializer.data
コード例 #3
0
class BuildItemSerializer(InvenTreeModelSerializer):
    """Serializes a BuildItem object."""

    bom_part = serializers.IntegerField(source='bom_item.sub_part.pk',
                                        read_only=True)
    part = serializers.IntegerField(source='stock_item.part.pk',
                                    read_only=True)
    location = serializers.IntegerField(source='stock_item.location.pk',
                                        read_only=True)

    # Extra (optional) detail fields
    part_detail = PartSerializer(source='stock_item.part',
                                 many=False,
                                 read_only=True)
    build_detail = BuildSerializer(source='build', many=False, read_only=True)
    stock_item_detail = StockItemSerializerBrief(source='stock_item',
                                                 read_only=True)
    location_detail = LocationSerializer(source='stock_item.location',
                                         read_only=True)

    quantity = InvenTreeDecimalField()

    def __init__(self, *args, **kwargs):
        """Determine which extra details fields should be included"""
        build_detail = kwargs.pop('build_detail', False)
        part_detail = kwargs.pop('part_detail', False)
        location_detail = kwargs.pop('location_detail', False)

        super().__init__(*args, **kwargs)

        if not build_detail:
            self.fields.pop('build_detail')

        if not part_detail:
            self.fields.pop('part_detail')

        if not location_detail:
            self.fields.pop('location_detail')

    class Meta:
        """Serializer metaclass"""
        model = BuildItem
        fields = [
            'pk', 'bom_part', 'build', 'build_detail', 'install_into',
            'location', 'location_detail', 'part', 'part_detail', 'stock_item',
            'stock_item_detail', 'quantity'
        ]
コード例 #4
0
ファイル: serializers.py プロジェクト: sfabris/InvenTree
class SalesOrderAllocationSerializer(InvenTreeModelSerializer):
    """
    Serializer for the SalesOrderAllocation model.
    This includes some fields from the related model objects.
    """

    part = serializers.PrimaryKeyRelatedField(source='item.part',
                                              read_only=True)
    order = serializers.PrimaryKeyRelatedField(source='line.order',
                                               many=False,
                                               read_only=True)
    serial = serializers.CharField(source='get_serial', read_only=True)
    quantity = serializers.FloatField(read_only=True)
    location = serializers.PrimaryKeyRelatedField(source='item.location',
                                                  many=False,
                                                  read_only=True)

    # Extra detail fields
    order_detail = SalesOrderSerializer(source='line.order',
                                        many=False,
                                        read_only=True)
    part_detail = PartBriefSerializer(source='item.part',
                                      many=False,
                                      read_only=True)
    item_detail = StockItemSerializer(source='item',
                                      many=False,
                                      read_only=True)
    location_detail = LocationSerializer(source='item.location',
                                         many=False,
                                         read_only=True)

    def __init__(self, *args, **kwargs):

        order_detail = kwargs.pop('order_detail', False)
        part_detail = kwargs.pop('part_detail', False)
        item_detail = kwargs.pop('item_detail', False)
        location_detail = kwargs.pop('location_detail', False)

        super().__init__(*args, **kwargs)

        if not order_detail:
            self.fields.pop('order_detail')

        if not part_detail:
            self.fields.pop('part_detail')

        if not item_detail:
            self.fields.pop('item_detail')

        if not location_detail:
            self.fields.pop('location_detail')

    class Meta:
        model = SalesOrderAllocation

        fields = [
            'pk',
            'line',
            'serial',
            'quantity',
            'location',
            'location_detail',
            'item',
            'item_detail',
            'order',
            'order_detail',
            'part',
            'part_detail',
        ]