mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Finish function to install stock item(s)
This commit is contained in:
parent
45c888e13d
commit
9c27680202
@ -600,12 +600,12 @@ class StockItem(MPTTModel):
|
|||||||
return self.installedItemCount() > 0
|
return self.installedItemCount() > 0
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def installIntoStockItem(self, otherItem, quantity, user, notes):
|
def installStockItem(self, otherItem, quantity, user, notes):
|
||||||
"""
|
"""
|
||||||
Install this stock item into another stock item.
|
Install another stock item into this stock item.
|
||||||
|
|
||||||
Args
|
Args
|
||||||
otherItem: The stock item to install this item into
|
otherItem: The stock item to install into this stock item
|
||||||
quantity: The quantity of stock to install
|
quantity: The quantity of stock to install
|
||||||
user: The user performing the operation
|
user: The user performing the operation
|
||||||
notes: Any notes associated with the operation
|
notes: Any notes associated with the operation
|
||||||
@ -615,16 +615,19 @@ class StockItem(MPTTModel):
|
|||||||
if self.belongs_to is not None:
|
if self.belongs_to is not None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# TODO - Are there any other checks that need to be performed at this stage?
|
# If the quantity is less than the stock item, split the stock!
|
||||||
|
stock_item = otherItem.splitStock(quantity, None, user)
|
||||||
|
|
||||||
# Mark this stock item as belonging to the other one
|
if stock_item is None:
|
||||||
self.belongs_to = otherItem
|
stock_item = otherItem
|
||||||
|
|
||||||
self.save()
|
# Assign the other stock item into this one
|
||||||
|
stock_item.belongs_to = self
|
||||||
|
stock_item.save()
|
||||||
|
|
||||||
# Add a transaction note!
|
# Add a transaction note!
|
||||||
self.addTransactionNote(
|
stock_item.addTransactionNote(
|
||||||
_('Installed in stock item') + ' ' + str(otherItem.pk),
|
_('Installed into stock item') + ' ' + str(self.pk),
|
||||||
user,
|
user,
|
||||||
notes=notes
|
notes=notes
|
||||||
)
|
)
|
||||||
@ -839,20 +842,20 @@ class StockItem(MPTTModel):
|
|||||||
|
|
||||||
# Do not split a serialized part
|
# Do not split a serialized part
|
||||||
if self.serialized:
|
if self.serialized:
|
||||||
return
|
return self
|
||||||
|
|
||||||
try:
|
try:
|
||||||
quantity = Decimal(quantity)
|
quantity = Decimal(quantity)
|
||||||
except (InvalidOperation, ValueError):
|
except (InvalidOperation, ValueError):
|
||||||
return
|
return self
|
||||||
|
|
||||||
# Doesn't make sense for a zero quantity
|
# Doesn't make sense for a zero quantity
|
||||||
if quantity <= 0:
|
if quantity <= 0:
|
||||||
return
|
return self
|
||||||
|
|
||||||
# Also doesn't make sense to split the full amount
|
# Also doesn't make sense to split the full amount
|
||||||
if quantity >= self.quantity:
|
if quantity >= self.quantity:
|
||||||
return
|
return self
|
||||||
|
|
||||||
# Create a new StockItem object, duplicating relevant fields
|
# Create a new StockItem object, duplicating relevant fields
|
||||||
# Nullify the PK so a new record is created
|
# Nullify the PK so a new record is created
|
||||||
|
@ -716,8 +716,6 @@ class StockItemInstall(AjaxUpdateView):
|
|||||||
try:
|
try:
|
||||||
part = self.request.GET.get('part', None)
|
part = self.request.GET.get('part', None)
|
||||||
|
|
||||||
print(self.request.GET)
|
|
||||||
|
|
||||||
if part is not None:
|
if part is not None:
|
||||||
part = Part.objects.get(pk=part)
|
part = Part.objects.get(pk=part)
|
||||||
items = items.filter(part=part)
|
items = items.filter(part=part)
|
||||||
@ -750,14 +748,22 @@ class StockItemInstall(AjaxUpdateView):
|
|||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
valid = False
|
|
||||||
|
|
||||||
valid = form.is_valid() and valid
|
valid = form.is_valid()
|
||||||
|
|
||||||
if valid:
|
if valid:
|
||||||
pass
|
# We assume by this point that we have a valid stock_item and quantity values
|
||||||
|
data = form.cleaned_data
|
||||||
|
|
||||||
|
other_stock_item = data['stock_item']
|
||||||
|
quantity = data['quantity_to_install']
|
||||||
|
notes = data['notes']
|
||||||
|
|
||||||
|
# Install the other stock item into this one
|
||||||
|
this_stock_item = self.get_object()
|
||||||
|
|
||||||
|
this_stock_item.installStockItem(other_stock_item, quantity, request.user, notes)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'form_valid': valid,
|
'form_valid': valid,
|
||||||
|
Loading…
Reference in New Issue
Block a user