mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add validation checks for the PurchaseOrderLineItem serializer
This commit is contained in:
parent
b4f8136142
commit
64bbcd2570
@ -164,8 +164,23 @@ class POLineItemSerializer(InvenTreeModelSerializer):
|
|||||||
if order_detail is not True:
|
if order_detail is not True:
|
||||||
self.fields.pop('order_detail')
|
self.fields.pop('order_detail')
|
||||||
|
|
||||||
quantity = serializers.FloatField(default=1)
|
quantity = serializers.FloatField(min_value=0, required=True)
|
||||||
received = serializers.FloatField(default=0)
|
|
||||||
|
def validate_quantity(self, quantity):
|
||||||
|
|
||||||
|
if quantity <= 0:
|
||||||
|
raise ValidationError(_("Quantity must be greater than zero"))
|
||||||
|
|
||||||
|
return quantity
|
||||||
|
|
||||||
|
def validate_purchase_order(self, purchase_order):
|
||||||
|
|
||||||
|
if purchase_order.status not in PurchaseOrderStatus.OPEN:
|
||||||
|
raise ValidationError(_('Order is not open'))
|
||||||
|
|
||||||
|
return purchase_order
|
||||||
|
|
||||||
|
received = serializers.FloatField(default=0, read_only=True)
|
||||||
|
|
||||||
overdue = serializers.BooleanField(required=False, read_only=True)
|
overdue = serializers.BooleanField(required=False, read_only=True)
|
||||||
|
|
||||||
@ -189,6 +204,22 @@ class POLineItemSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
order_detail = POSerializer(source='order', read_only=True, many=False)
|
order_detail = POSerializer(source='order', read_only=True, many=False)
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
|
||||||
|
data = super().validate(data)
|
||||||
|
|
||||||
|
supplier_part = data['part']
|
||||||
|
purchase_order = data['order']
|
||||||
|
|
||||||
|
# Check that the supplier part and purchase order match
|
||||||
|
if supplier_part is not None and supplier_part.supplier != purchase_order.supplier:
|
||||||
|
raise ValidationError({
|
||||||
|
'part': _('Supplier must match purchase order'),
|
||||||
|
'order': _('Purchase order must match supplier'),
|
||||||
|
})
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = order.models.PurchaseOrderLineItem
|
model = order.models.PurchaseOrderLineItem
|
||||||
|
|
||||||
@ -349,7 +380,7 @@ class POReceiveSerializer(serializers.Serializer):
|
|||||||
Serializer for receiving items against a purchase order
|
Serializer for receiving items against a purchase order
|
||||||
"""
|
"""
|
||||||
|
|
||||||
items = POLineItemReceiveSerializer(many=True)
|
items = POLineItemReceiveSerializer(many=True, required=True)
|
||||||
|
|
||||||
location = serializers.PrimaryKeyRelatedField(
|
location = serializers.PrimaryKeyRelatedField(
|
||||||
queryset=stock.models.StockLocation.objects.all(),
|
queryset=stock.models.StockLocation.objects.all(),
|
||||||
|
Loading…
Reference in New Issue
Block a user