mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
commit
efd0caba6e
@ -233,6 +233,13 @@ class InvenTreeSetting(models.Model):
|
||||
'validator': bool,
|
||||
},
|
||||
|
||||
'PART_CREATE_INITIAL': {
|
||||
'name': _('Create initial stock'),
|
||||
'description': _('Create initial stock on part creation'),
|
||||
'default': False,
|
||||
'validator': bool,
|
||||
},
|
||||
|
||||
'PART_INTERNAL_PRICE': {
|
||||
'name': _('Internal Prices'),
|
||||
'description': _('Enable internal prices for parts'),
|
||||
|
@ -217,6 +217,11 @@ class EditPartForm(HelperForm):
|
||||
label=_('Include parent categories parameter templates'),
|
||||
widget=forms.HiddenInput())
|
||||
|
||||
initial_stock = forms.IntegerField(required=False,
|
||||
initial=0,
|
||||
label=_('Initial stock amount'),
|
||||
help_text=_('Create stock for this part'))
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
fields = [
|
||||
@ -238,6 +243,7 @@ class EditPartForm(HelperForm):
|
||||
'default_expiry',
|
||||
'units',
|
||||
'minimum_stock',
|
||||
'initial_stock',
|
||||
'component',
|
||||
'assembly',
|
||||
'is_template',
|
||||
|
@ -44,7 +44,7 @@ from common.files import FileManager
|
||||
from common.views import FileManagementFormView, FileManagementAjaxView
|
||||
from common.forms import UploadFileForm, MatchFieldForm
|
||||
|
||||
from stock.models import StockLocation
|
||||
from stock.models import StockItem, StockLocation
|
||||
|
||||
import common.settings as inventree_settings
|
||||
|
||||
@ -487,6 +487,10 @@ class PartCreate(AjaxCreateView):
|
||||
if not inventree_settings.stock_expiry_enabled():
|
||||
form.fields['default_expiry'].widget = HiddenInput()
|
||||
|
||||
# Hide the "initial stock amount" field if the feature is not enabled
|
||||
if not InvenTreeSetting.get_setting('PART_CREATE_INITIAL'):
|
||||
form.fields['initial_stock'].widget = HiddenInput()
|
||||
|
||||
# Hide the default_supplier field (there are no matching supplier parts yet!)
|
||||
form.fields['default_supplier'].widget = HiddenInput()
|
||||
|
||||
@ -547,6 +551,14 @@ class PartCreate(AjaxCreateView):
|
||||
# Save part and pass category template settings
|
||||
part.save(**{'add_category_templates': add_category_templates})
|
||||
|
||||
# Add stock if set
|
||||
init_stock = int(request.POST.get('initial_stock', 0))
|
||||
if init_stock:
|
||||
stock = StockItem(part=part,
|
||||
quantity=init_stock,
|
||||
location=part.default_location)
|
||||
stock.save()
|
||||
|
||||
data['pk'] = part.pk
|
||||
data['text'] = str(part)
|
||||
|
||||
|
@ -23,7 +23,8 @@
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_PRICE_IN_FORMS" icon="fa-dollar-sign" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_RELATED" icon="fa-random" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_RECENT_COUNT" icon="fa-clock" %}
|
||||
<tr><td colspan='5 '></td></tr>
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_CREATE_INITIAL" icon="fa-boxes" %}
|
||||
<tr><td colspan='5'></td></tr>
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_TEMPLATE" icon="fa-clone" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_ASSEMBLY" icon="fa-tools" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_COMPONENT" icon="fa-th"%}
|
||||
|
Loading…
Reference in New Issue
Block a user