mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Merge pull request #1761 from eeintech/stock_move_modal_notes
Fixes for stock modal and notes propagation to tracking items
This commit is contained in:
		| @@ -1211,7 +1211,7 @@ class StockItem(MPTTModel): | ||||
|             # We need to split the stock! | ||||
|  | ||||
|             # Split the existing StockItem in two | ||||
|             self.splitStock(quantity, location, user) | ||||
|             self.splitStock(quantity, location, user, **{'notes': notes}) | ||||
|  | ||||
|             return True | ||||
|  | ||||
|   | ||||
| @@ -810,6 +810,20 @@ class StockAdjust(AjaxView, FormMixin): | ||||
|  | ||||
|         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): | ||||
|  | ||||
|         context = super().get_context_data() | ||||
| @@ -818,6 +832,7 @@ class StockAdjust(AjaxView, FormMixin): | ||||
|  | ||||
|         context['stock_action'] = self.stock_action.strip().lower() | ||||
|  | ||||
|         self.get_stock_action_titles() | ||||
|         context['stock_action_title'] = self.stock_action_title | ||||
|  | ||||
|         # 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']: | ||||
|             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! | ||||
|         self.stock_items = self.get_GET_items() | ||||
|  | ||||
| @@ -908,7 +911,7 @@ class StockAdjust(AjaxView, FormMixin): | ||||
|         } | ||||
|  | ||||
|         if valid: | ||||
|             result = self.do_action() | ||||
|             result = self.do_action(note=form.cleaned_data['note']) | ||||
|  | ||||
|             data['success'] = result | ||||
|  | ||||
| @@ -925,9 +928,9 @@ class StockAdjust(AjaxView, FormMixin): | ||||
|                     # Instruct the form to redirect | ||||
|                     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 """ | ||||
|  | ||||
|         if self.stock_action == 'move': | ||||
| @@ -942,27 +945,26 @@ class StockAdjust(AjaxView, FormMixin): | ||||
|             except ValueError: | ||||
|                 pass | ||||
|  | ||||
|             return self.do_move(destination, set_default_loc) | ||||
|             return self.do_move(destination, set_default_loc, note=note) | ||||
|  | ||||
|         elif self.stock_action == 'add': | ||||
|             return self.do_add() | ||||
|             return self.do_add(note=note) | ||||
|  | ||||
|         elif self.stock_action == 'take': | ||||
|             return self.do_take() | ||||
|             return self.do_take(note=note) | ||||
|  | ||||
|         elif self.stock_action == 'count': | ||||
|             return self.do_count() | ||||
|             return self.do_count(note=note) | ||||
|  | ||||
|         elif self.stock_action == 'delete': | ||||
|             return self.do_delete() | ||||
|             return self.do_delete(note=note) | ||||
|  | ||||
|         else: | ||||
|             return _('No action performed') | ||||
|  | ||||
|     def do_add(self): | ||||
|     def do_add(self, note=None): | ||||
|  | ||||
|         count = 0 | ||||
|         note = self.request.POST['note'] | ||||
|  | ||||
|         for item in self.stock_items: | ||||
|             if item.new_quantity <= 0: | ||||
| @@ -974,10 +976,9 @@ class StockAdjust(AjaxView, FormMixin): | ||||
|  | ||||
|         return _('Added stock to {n} items').format(n=count) | ||||
|  | ||||
|     def do_take(self): | ||||
|     def do_take(self, note=None): | ||||
|  | ||||
|         count = 0 | ||||
|         note = self.request.POST['note'] | ||||
|  | ||||
|         for item in self.stock_items: | ||||
|             if item.new_quantity <= 0: | ||||
| @@ -989,10 +990,9 @@ class StockAdjust(AjaxView, FormMixin): | ||||
|  | ||||
|         return _('Removed stock from {n} items').format(n=count) | ||||
|  | ||||
|     def do_count(self): | ||||
|     def do_count(self, note=None): | ||||
|  | ||||
|         count = 0 | ||||
|         note = self.request.POST['note'] | ||||
|  | ||||
|         for item in self.stock_items: | ||||
|  | ||||
| @@ -1002,13 +1002,11 @@ class StockAdjust(AjaxView, FormMixin): | ||||
|  | ||||
|         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 """ | ||||
|  | ||||
|         count = 0 | ||||
|  | ||||
|         note = self.request.POST['note'] | ||||
|  | ||||
|         for item in self.stock_items: | ||||
|             # Avoid moving zero quantity | ||||
|             if item.new_quantity <= 0: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user