2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-09 07:00:56 +00:00
- Add StockHistoryCode to custom context
- Add simple form for editing stock item history
- Add tracking entry when stock status is changed
This commit is contained in:
Oliver Walters
2021-05-11 23:38:26 +10:00
parent 84bfffd5a7
commit 03a231bffb
11 changed files with 119 additions and 16 deletions

View File

@ -183,20 +183,46 @@ class StockItem(MPTTModel):
self.validate_unique()
self.clean()
user = kwargs.pop('user', None)
# If 'add_note = False' specified, then no tracking note will be added for item creation
add_note = kwargs.pop('add_note', True)
notes = kwargs.pop('notes', '')
if not self.pk:
# StockItem has not yet been saved
add_note = add_note and True
else:
# StockItem has already been saved
# Check if "interesting" fields have been changed
# (we wish to record these as historical records)
try:
old = StockItem.objects.get(pk=self.pk)
deltas = {}
# Status changed?
if not old.status == self.status:
deltas['status'] = self.status
# TODO - Other interesting changes we are interested in...
if add_note and len(deltas) > 0:
self.add_tracking_entry(
StockHistoryCode.EDITED,
user,
deltas=deltas,
notes=notes,
)
except (ValueError, StockItem.DoesNotExist):
pass
add_note = False
user = kwargs.pop('user', None)
add_note = add_note and kwargs.pop('note', True)
super(StockItem, self).save(*args, **kwargs)
if add_note:
@ -209,6 +235,7 @@ class StockItem(MPTTModel):
StockHistoryCode.CREATED,
user,
deltas=tracking_info,
notes=notes,
location=self.location,
quantity=float(self.quantity),
)