mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adds metadata mixin class for adding JSON field to internal tables
- Add metadata field to stocklocation - Add metadata field to stockitem
This commit is contained in:
parent
818be32e31
commit
097afed78e
@ -16,6 +16,30 @@ import common.models
|
||||
from plugin import InvenTreePlugin, registry
|
||||
|
||||
|
||||
class MetadataMixin(models.Model):
|
||||
"""
|
||||
Model mixin class which adds a JSON metadata field to a model,
|
||||
for use by any (and all) plugins.
|
||||
|
||||
The intent of this mixin is to provide a metadata field on a model instance,
|
||||
for plugins to read / modify as required, to store any extra information.
|
||||
|
||||
The assumptions for models implementing this mixin are:
|
||||
|
||||
- The internal InvenTree business logic will make no use of this field
|
||||
- Multiple plugins may read / write to this metadata field, and not assume they have sole rights
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
metadata = models.JSONField(
|
||||
blank=True, null=True,
|
||||
verbose_name=_('Plugin Metadata'),
|
||||
help_text=_('JSON metadata field, for use by external plugins'),
|
||||
)
|
||||
|
||||
|
||||
class PluginConfig(models.Model):
|
||||
"""
|
||||
A PluginConfig object holds settings for plugins.
|
||||
|
27
InvenTree/stock/migrations/0075_auto_20220515_1440.py
Normal file
27
InvenTree/stock/migrations/0075_auto_20220515_1440.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Generated by Django 3.2.13 on 2022-05-15 14:40
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0074_alter_stockitem_batch'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='stockitem',
|
||||
name='metadata',
|
||||
field=models.JSONField(blank=True, help_text='JSON metadata field, for use by external plugins', null=True, verbose_name='Plugin Metadata'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='stocklocation',
|
||||
name='metadata',
|
||||
field=models.JSONField(blank=True, help_text='JSON metadata field, for use by external plugins', null=True, verbose_name='Plugin Metadata'),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='stocklocation',
|
||||
unique_together=set(),
|
||||
),
|
||||
]
|
@ -38,6 +38,7 @@ import common.models
|
||||
import report.models
|
||||
import label.models
|
||||
|
||||
from plugin.models import MetadataMixin
|
||||
from plugin.events import trigger_event
|
||||
|
||||
from InvenTree.status_codes import StockStatus, StockHistoryCode
|
||||
@ -51,7 +52,7 @@ from company import models as CompanyModels
|
||||
from part import models as PartModels
|
||||
|
||||
|
||||
class StockLocation(InvenTreeTree):
|
||||
class StockLocation(MetadataMixin, InvenTreeTree):
|
||||
""" Organization tree for StockItem objects
|
||||
A "StockLocation" can be considered a warehouse, or storage location
|
||||
Stock locations can be heirarchical as required
|
||||
@ -242,7 +243,7 @@ def generate_batch_code():
|
||||
return Template(batch_template).render(context)
|
||||
|
||||
|
||||
class StockItem(MPTTModel):
|
||||
class StockItem(MetadataMixin, MPTTModel):
|
||||
"""
|
||||
A StockItem object represents a quantity of physical instances of a part.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user