mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Save user who created a stock item
- Handled differently for batch or serialized parts
This commit is contained in:
parent
52ec213a28
commit
41c07fc423
@ -245,7 +245,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def post_save(self, **kwargs):
|
def post_save(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Hook for doing something with the created object after it is saved
|
Hook for doing something with the created object after it is saved
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
@ -129,13 +129,15 @@ class StockItem(models.Model):
|
|||||||
else:
|
else:
|
||||||
add_note = False
|
add_note = False
|
||||||
|
|
||||||
|
user = kwargs.pop('user', None)
|
||||||
|
|
||||||
super(StockItem, self).save(*args, **kwargs)
|
super(StockItem, self).save(*args, **kwargs)
|
||||||
|
|
||||||
if add_note:
|
if add_note:
|
||||||
# This StockItem is being saved for the first time
|
# This StockItem is being saved for the first time
|
||||||
self.addTransactionNote(
|
self.addTransactionNote(
|
||||||
'Created stock item',
|
'Created stock item',
|
||||||
None,
|
user,
|
||||||
notes="Created new stock item for part '{p}'".format(p=str(self.part)),
|
notes="Created new stock item for part '{p}'".format(p=str(self.part)),
|
||||||
system=True
|
system=True
|
||||||
)
|
)
|
||||||
|
@ -792,6 +792,8 @@ class StockItemCreate(AjaxCreateView):
|
|||||||
|
|
||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
|
||||||
valid = form.is_valid()
|
valid = form.is_valid()
|
||||||
|
|
||||||
if valid:
|
if valid:
|
||||||
@ -850,7 +852,7 @@ class StockItemCreate(AjaxCreateView):
|
|||||||
URL=data.get('URL'),
|
URL=data.get('URL'),
|
||||||
)
|
)
|
||||||
|
|
||||||
item.save()
|
item.save(user=request.user)
|
||||||
|
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
form.errors['serial_numbers'] = e.messages
|
form.errors['serial_numbers'] = e.messages
|
||||||
@ -861,11 +863,15 @@ class StockItemCreate(AjaxCreateView):
|
|||||||
# We need to call _post_clean() here because it is prevented in the form implementation
|
# We need to call _post_clean() here because it is prevented in the form implementation
|
||||||
form.clean()
|
form.clean()
|
||||||
form._post_clean()
|
form._post_clean()
|
||||||
form.save()
|
|
||||||
|
item = form.save(commit=False)
|
||||||
|
item.save(user=request.user)
|
||||||
|
|
||||||
data = {
|
data['pk'] = item.pk
|
||||||
'form_valid': valid,
|
data['url'] = item.get_absolute_url()
|
||||||
}
|
data['success'] = _("Created new stock item")
|
||||||
|
|
||||||
|
data['form_valid'] = valid
|
||||||
|
|
||||||
return self.renderJsonResponse(request, form, data=data)
|
return self.renderJsonResponse(request, form, data=data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user