2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

Update definition for StockItemAllocation model

- Limit foreignkey choices
- Error checking
- Check if a StockItem is over-allocated
- Fix API serialization and filtering
This commit is contained in:
Oliver Walters
2020-04-22 13:11:19 +10:00
parent 2cb1b076f6
commit 1373425c29
10 changed files with 181 additions and 23 deletions

View File

@ -393,6 +393,15 @@ class BuildItem(models.Model):
q=self.stock_item.quantity
))]
if self.stock_item.quantity - self.stock_item.allocation_count() < self.quantity:
errors['quantity'] = _('StockItem is over-allocated')
if self.quantity <= 0:
errors['quantity'] = _('Allocation quantity must be greater than zero')
if self.stock_item.serial and not self.quantity == 1:
errors['quantity'] = _('Quantity must be 1 for serialized stock')
except StockItem.DoesNotExist:
pass