mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adds "convert_to_variant" function for the StockItem model
This commit is contained in:
parent
ab114b52e9
commit
87de7e4beb
@ -718,6 +718,30 @@ class StockItem(MPTTModel):
|
||||
help_text=_('Select Owner'),
|
||||
related_name='stock_items')
|
||||
|
||||
@transaction.atomic
|
||||
def convert_to_variant(self, variant, user, notes=None):
|
||||
"""
|
||||
Convert this StockItem instance to a "variant",
|
||||
i.e. change the "part" reference field
|
||||
"""
|
||||
|
||||
if not variant:
|
||||
# Ignore null values
|
||||
return
|
||||
|
||||
if variant == self.part:
|
||||
# Variant is the same as the current part
|
||||
return
|
||||
|
||||
self.part = variant
|
||||
self.save()
|
||||
|
||||
self.add_tracking_entry(
|
||||
StockHistoryCode.CONVERTED_TO_VARIANT,
|
||||
user,
|
||||
notes=notes
|
||||
)
|
||||
|
||||
def get_item_owner(self):
|
||||
"""
|
||||
Return the closest "owner" for this StockItem.
|
||||
|
Loading…
Reference in New Issue
Block a user