mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fixes for stock modal and notes propagation to tracking items
This commit is contained in:
parent
1d0dd04ca4
commit
6687661928
@ -1211,7 +1211,7 @@ class StockItem(MPTTModel):
|
|||||||
# We need to split the stock!
|
# We need to split the stock!
|
||||||
|
|
||||||
# Split the existing StockItem in two
|
# Split the existing StockItem in two
|
||||||
self.splitStock(quantity, location, user)
|
self.splitStock(quantity, location, user, **{'notes': notes})
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -810,6 +810,20 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
def get_stock_action_titles(self):
|
||||||
|
|
||||||
|
# Choose form title and action column based on the action
|
||||||
|
titles = {
|
||||||
|
'move': [_('Move Stock Items'), _('Move')],
|
||||||
|
'count': [_('Count Stock Items'), _('Count')],
|
||||||
|
'take': [_('Remove From Stock'), _('Take')],
|
||||||
|
'add': [_('Add Stock Items'), _('Add')],
|
||||||
|
'delete': [_('Delete Stock Items'), _('Delete')],
|
||||||
|
}
|
||||||
|
|
||||||
|
self.ajax_form_title = titles[self.stock_action][0]
|
||||||
|
self.stock_action_title = titles[self.stock_action][1]
|
||||||
|
|
||||||
def get_context_data(self):
|
def get_context_data(self):
|
||||||
|
|
||||||
context = super().get_context_data()
|
context = super().get_context_data()
|
||||||
@ -818,6 +832,7 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
|
|
||||||
context['stock_action'] = self.stock_action.strip().lower()
|
context['stock_action'] = self.stock_action.strip().lower()
|
||||||
|
|
||||||
|
self.get_stock_action_titles()
|
||||||
context['stock_action_title'] = self.stock_action_title
|
context['stock_action_title'] = self.stock_action_title
|
||||||
|
|
||||||
# Quantity column will be read-only in some circumstances
|
# Quantity column will be read-only in some circumstances
|
||||||
@ -846,18 +861,6 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
if self.stock_action not in ['move', 'count', 'take', 'add', 'delete']:
|
if self.stock_action not in ['move', 'count', 'take', 'add', 'delete']:
|
||||||
self.stock_action = 'count'
|
self.stock_action = 'count'
|
||||||
|
|
||||||
# Choose form title and action column based on the action
|
|
||||||
titles = {
|
|
||||||
'move': [_('Move Stock Items'), _('Move')],
|
|
||||||
'count': [_('Count Stock Items'), _('Count')],
|
|
||||||
'take': [_('Remove From Stock'), _('Take')],
|
|
||||||
'add': [_('Add Stock Items'), _('Add')],
|
|
||||||
'delete': [_('Delete Stock Items'), _('Delete')],
|
|
||||||
}
|
|
||||||
|
|
||||||
self.ajax_form_title = titles[self.stock_action][0]
|
|
||||||
self.stock_action_title = titles[self.stock_action][1]
|
|
||||||
|
|
||||||
# Save list of items!
|
# Save list of items!
|
||||||
self.stock_items = self.get_GET_items()
|
self.stock_items = self.get_GET_items()
|
||||||
|
|
||||||
@ -908,7 +911,7 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if valid:
|
if valid:
|
||||||
result = self.do_action()
|
result = self.do_action(note=form.cleaned_data['note'])
|
||||||
|
|
||||||
data['success'] = result
|
data['success'] = result
|
||||||
|
|
||||||
@ -925,9 +928,9 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
# Instruct the form to redirect
|
# Instruct the form to redirect
|
||||||
data['url'] = reverse('stock-index')
|
data['url'] = reverse('stock-index')
|
||||||
|
|
||||||
return self.renderJsonResponse(request, form, data=data)
|
return self.renderJsonResponse(request, form, data=data, context=self.get_context_data())
|
||||||
|
|
||||||
def do_action(self):
|
def do_action(self, note=None):
|
||||||
""" Perform stock adjustment action """
|
""" Perform stock adjustment action """
|
||||||
|
|
||||||
if self.stock_action == 'move':
|
if self.stock_action == 'move':
|
||||||
@ -942,27 +945,26 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return self.do_move(destination, set_default_loc)
|
return self.do_move(destination, set_default_loc, note=note)
|
||||||
|
|
||||||
elif self.stock_action == 'add':
|
elif self.stock_action == 'add':
|
||||||
return self.do_add()
|
return self.do_add(note=note)
|
||||||
|
|
||||||
elif self.stock_action == 'take':
|
elif self.stock_action == 'take':
|
||||||
return self.do_take()
|
return self.do_take(note=note)
|
||||||
|
|
||||||
elif self.stock_action == 'count':
|
elif self.stock_action == 'count':
|
||||||
return self.do_count()
|
return self.do_count(note=note)
|
||||||
|
|
||||||
elif self.stock_action == 'delete':
|
elif self.stock_action == 'delete':
|
||||||
return self.do_delete()
|
return self.do_delete(note=note)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return _('No action performed')
|
return _('No action performed')
|
||||||
|
|
||||||
def do_add(self):
|
def do_add(self, note=None):
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
note = self.request.POST['note']
|
|
||||||
|
|
||||||
for item in self.stock_items:
|
for item in self.stock_items:
|
||||||
if item.new_quantity <= 0:
|
if item.new_quantity <= 0:
|
||||||
@ -974,10 +976,9 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
|
|
||||||
return _('Added stock to {n} items').format(n=count)
|
return _('Added stock to {n} items').format(n=count)
|
||||||
|
|
||||||
def do_take(self):
|
def do_take(self, note=None):
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
note = self.request.POST['note']
|
|
||||||
|
|
||||||
for item in self.stock_items:
|
for item in self.stock_items:
|
||||||
if item.new_quantity <= 0:
|
if item.new_quantity <= 0:
|
||||||
@ -989,10 +990,9 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
|
|
||||||
return _('Removed stock from {n} items').format(n=count)
|
return _('Removed stock from {n} items').format(n=count)
|
||||||
|
|
||||||
def do_count(self):
|
def do_count(self, note=None):
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
note = self.request.POST['note']
|
|
||||||
|
|
||||||
for item in self.stock_items:
|
for item in self.stock_items:
|
||||||
|
|
||||||
@ -1002,13 +1002,11 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
|
|
||||||
return _("Counted stock for {n} items".format(n=count))
|
return _("Counted stock for {n} items".format(n=count))
|
||||||
|
|
||||||
def do_move(self, destination, set_loc=None):
|
def do_move(self, destination, set_loc=None, note=None):
|
||||||
""" Perform actual stock movement """
|
""" Perform actual stock movement """
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
note = self.request.POST['note']
|
|
||||||
|
|
||||||
for item in self.stock_items:
|
for item in self.stock_items:
|
||||||
# Avoid moving zero quantity
|
# Avoid moving zero quantity
|
||||||
if item.new_quantity <= 0:
|
if item.new_quantity <= 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user