mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 03:00:54 +00:00
Add validation check to "Convert to Variant" form (#5583)
* Add validation check to "Convert to Variant" form - If a supplierpart is assigned, cannot convert stock item * Fix failing unit test
This commit is contained in:
@ -600,6 +600,21 @@ class ConvertStockItemSerializer(serializers.Serializer):
|
||||
|
||||
return part
|
||||
|
||||
def validate(self, data):
|
||||
"""Ensure that the stock item is valid for conversion:
|
||||
|
||||
- If a SupplierPart is assigned, we cannot convert!
|
||||
"""
|
||||
|
||||
data = super().validate(data)
|
||||
|
||||
stock_item = self.context['item']
|
||||
|
||||
if stock_item.supplier_part is not None:
|
||||
raise ValidationError(_("Cannot convert stock item with assigned SupplierPart"))
|
||||
|
||||
return data
|
||||
|
||||
def save(self):
|
||||
"""Save the serializer to convert the StockItem to the selected Part"""
|
||||
data = self.validated_data
|
||||
|
Reference in New Issue
Block a user