mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add configurable option for controlling default "delete_on_deplete" behaviour
This commit is contained in:
parent
3bf5492cb6
commit
aa7fa89b0c
@ -1222,6 +1222,13 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
||||
'validator': bool,
|
||||
},
|
||||
|
||||
'STOCK_DELETE_DEPLETED_DEFAULT': {
|
||||
'name': _('Delete Depleted Stock'),
|
||||
'description': _('Determines default behaviour when a stock item is depleted'),
|
||||
'default': True,
|
||||
'validator': bool,
|
||||
},
|
||||
|
||||
'STOCK_BATCH_CODE_TEMPLATE': {
|
||||
'name': _('Batch Code Template'),
|
||||
'description': _('Template for generating default batch codes for stock items'),
|
||||
|
@ -0,0 +1,19 @@
|
||||
# Generated by Django 3.2.16 on 2022-12-24 12:29
|
||||
|
||||
from django.db import migrations, models
|
||||
import stock.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0090_stocklocation_structural'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='stockitem',
|
||||
name='delete_on_deplete',
|
||||
field=models.BooleanField(default=stock.models.default_delete_on_deplete, help_text='Delete this Stock Item when stock is depleted', verbose_name='Delete on deplete'),
|
||||
),
|
||||
]
|
@ -13,6 +13,7 @@ from django.db import models, transaction
|
||||
from django.db.models import Q, Sum
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.db.models.signals import post_delete, post_save, pre_delete
|
||||
from django.db.utils import IntegrityError, OperationalError
|
||||
from django.dispatch import receiver
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -251,6 +252,20 @@ def generate_batch_code():
|
||||
return Template(batch_template).render(context)
|
||||
|
||||
|
||||
def default_delete_on_deplete():
|
||||
"""Return a default value for the 'delete_on_deplete' field.
|
||||
|
||||
Prior to 2022-12-24, this field was set to True by default.
|
||||
Now, there is a user-configurable setting to govern default behaviour.
|
||||
"""
|
||||
|
||||
try:
|
||||
return common.models.InvenTreeSetting.get_setting('STOCK_DELETE_DEPLETED_DEFAULT', True)
|
||||
except (IntegrityError, OperationalError):
|
||||
# Revert to original default behaviour
|
||||
return True
|
||||
|
||||
|
||||
class StockItem(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel):
|
||||
"""A StockItem object represents a quantity of physical instances of a part.
|
||||
|
||||
@ -760,7 +775,10 @@ class StockItem(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel):
|
||||
|
||||
review_needed = models.BooleanField(default=False)
|
||||
|
||||
delete_on_deplete = models.BooleanField(default=True, verbose_name=_('Delete on deplete'), help_text=_('Delete this Stock Item when stock is depleted'))
|
||||
delete_on_deplete = models.BooleanField(
|
||||
default=default_delete_on_deplete,
|
||||
verbose_name=_('Delete on deplete'), help_text=_('Delete this Stock Item when stock is depleted')
|
||||
)
|
||||
|
||||
status = models.PositiveIntegerField(
|
||||
default=StockStatus.OK,
|
||||
|
@ -13,6 +13,7 @@
|
||||
<tbody>
|
||||
{% include "InvenTree/settings/setting.html" with key="SERIAL_NUMBER_GLOBALLY_UNIQUE" icon="fa-hashtag" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="SERIAL_NUMBER_AUTOFILL" icon="fa-magic" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="STOCK_DELETE_DEPLETED_DEFAULT" icon="fa-trash-alt" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="STOCK_BATCH_CODE_TEMPLATE" icon="fa-layer-group" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="STOCK_ENABLE_EXPIRY" icon="fa-stopwatch" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="STOCK_STALE_DAYS" icon="fa-calendar" %}
|
||||
|
Loading…
Reference in New Issue
Block a user