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
|
||||
|
||||
def post_save(self, **kwargs):
|
||||
"""
|
||||
"""
|
||||
Hook for doing something with the created object after it is saved
|
||||
"""
|
||||
pass
|
||||
|
@ -129,13 +129,15 @@ class StockItem(models.Model):
|
||||
else:
|
||||
add_note = False
|
||||
|
||||
user = kwargs.pop('user', None)
|
||||
|
||||
super(StockItem, self).save(*args, **kwargs)
|
||||
|
||||
if add_note:
|
||||
# This StockItem is being saved for the first time
|
||||
self.addTransactionNote(
|
||||
'Created stock item',
|
||||
None,
|
||||
user,
|
||||
notes="Created new stock item for part '{p}'".format(p=str(self.part)),
|
||||
system=True
|
||||
)
|
||||
|
@ -792,6 +792,8 @@ class StockItemCreate(AjaxCreateView):
|
||||
|
||||
form = self.get_form()
|
||||
|
||||
data = {}
|
||||
|
||||
valid = form.is_valid()
|
||||
|
||||
if valid:
|
||||
@ -850,7 +852,7 @@ class StockItemCreate(AjaxCreateView):
|
||||
URL=data.get('URL'),
|
||||
)
|
||||
|
||||
item.save()
|
||||
item.save(user=request.user)
|
||||
|
||||
except ValidationError as e:
|
||||
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
|
||||
form.clean()
|
||||
form._post_clean()
|
||||
form.save()
|
||||
|
||||
item = form.save(commit=False)
|
||||
item.save(user=request.user)
|
||||
|
||||
data = {
|
||||
'form_valid': valid,
|
||||
}
|
||||
data['pk'] = item.pk
|
||||
data['url'] = item.get_absolute_url()
|
||||
data['success'] = _("Created new stock item")
|
||||
|
||||
data['form_valid'] = valid
|
||||
|
||||
return self.renderJsonResponse(request, form, data=data)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user