Record the user when updating stock items

This commit is contained in:
Oliver Walters 2021-05-12 10:42:09 +10:00
parent 30ff48d803
commit 3b252b8409
2 changed files with 22 additions and 5 deletions

View File

@ -366,10 +366,7 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
'date',
'deltas',
'label',
'link',
'notes',
'quantity',
'title',
'tracking_type',
'user',
'user_detail',
@ -378,8 +375,6 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
read_only_fields = [
'date',
'user',
'system',
'quantity',
'label',
'tracking_type',
]

View File

@ -1221,6 +1221,17 @@ class StockItemEditStatus(AjaxUpdateView):
form_class = StockForms.EditStockItemStatusForm
ajax_form_title = _('Edit Stock Item Status')
def save(self, object, form, **kwargs):
"""
Override the save method, to track the user who updated the model
"""
item = form.save(commit=False)
item.save(user=self.request.user)
return item
class StockItemEdit(AjaxUpdateView):
"""
@ -1331,6 +1342,17 @@ class StockItemEdit(AjaxUpdateView):
if not owner and not self.request.user.is_superuser:
form.add_error('owner', _('Owner is required (ownership control is enabled)'))
def save(self, object, form, **kwargs):
"""
Override the save method, to track the user who updated the model
"""
item = form.save(commit=False)
item.save(user=self.request.user)
return item
class StockItemConvert(AjaxUpdateView):
"""