mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #832 from SchrodingersGat/convert-variant
Convert variant
This commit is contained in:
commit
9ad54c6579
@ -1109,6 +1109,17 @@ class Part(MPTTModel):
|
||||
|
||||
return self.parameters.order_by('template__name')
|
||||
|
||||
@property
|
||||
def has_variants(self):
|
||||
""" Check if this Part object has variants underneath it. """
|
||||
|
||||
return self.get_all_variants().count() > 0
|
||||
|
||||
def get_all_variants(self):
|
||||
""" Return all Part object which exist as a variant under this part. """
|
||||
|
||||
return self.get_descendants(include_self=False)
|
||||
|
||||
|
||||
def attach_file(instance, filename):
|
||||
""" Function for storing a file for a PartAttachment
|
||||
|
@ -63,6 +63,18 @@ class EditStockLocationForm(HelperForm):
|
||||
]
|
||||
|
||||
|
||||
class ConvertStockItemForm(HelperForm):
|
||||
"""
|
||||
Form for converting a StockItem to a variant of its current part.
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = StockItem
|
||||
fields = [
|
||||
'part'
|
||||
]
|
||||
|
||||
|
||||
class CreateStockItemForm(HelperForm):
|
||||
""" Form for creating a new StockItem """
|
||||
|
||||
|
20
InvenTree/stock/migrations/0043_auto_20200525_0420.py
Normal file
20
InvenTree/stock/migrations/0043_auto_20200525_0420.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Generated by Django 3.0.5 on 2020-05-25 04:20
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('part', '0042_auto_20200518_0900'),
|
||||
('stock', '0042_auto_20200523_0121'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='stockitem',
|
||||
name='part',
|
||||
field=models.ForeignKey(help_text='Base part', limit_choices_to={'active': True, 'virtual': False}, on_delete=django.db.models.deletion.CASCADE, related_name='stock_items', to='part.Part', verbose_name='Base Part'),
|
||||
),
|
||||
]
|
@ -331,7 +331,6 @@ class StockItem(MPTTModel):
|
||||
verbose_name=_('Base Part'),
|
||||
related_name='stock_items', help_text=_('Base part'),
|
||||
limit_choices_to={
|
||||
'is_template': False,
|
||||
'active': True,
|
||||
'virtual': False
|
||||
})
|
||||
|
@ -93,6 +93,11 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
|
||||
<span class='fas fa-copy'/>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if item.part.has_variants %}
|
||||
<button type='button' class='btn btn-default' id='stock-convert' title="Convert stock to variant">
|
||||
<span class='fas fa-screwdriver'/>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if item.part.has_test_report_templates %}
|
||||
<button type='button' class='btn btn-default' id='stock-test-report' title='Generate test report'>
|
||||
<span class='fas fa-tasks'/>
|
||||
@ -324,6 +329,16 @@ function itemAdjust(action) {
|
||||
);
|
||||
}
|
||||
|
||||
{% if item.part.has_variants %}
|
||||
$("#stock-convert").click(function() {
|
||||
launchModalForm("{% url 'stock-item-convert' item.id %}",
|
||||
{
|
||||
reload: true,
|
||||
}
|
||||
);
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
$("#stock-move").click(function() {
|
||||
itemAdjust("move");
|
||||
});
|
||||
|
17
InvenTree/stock/templates/stock/stockitem_convert.html
Normal file
17
InvenTree/stock/templates/stock/stockitem_convert.html
Normal file
@ -0,0 +1,17 @@
|
||||
{% extends "modal_form.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block pre_form_content %}
|
||||
|
||||
<div class='alert alert-block alert-info'>
|
||||
<b>{% trans "Convert Stock Item" %}</b><br>
|
||||
{% trans "This stock item is current an instance of " %}<i>{{ item.part }}</i><br>
|
||||
{% trans "It can be converted to one of the part variants listed below." %}
|
||||
</div>
|
||||
|
||||
<div class='alert alert-block alert-warning'>
|
||||
<b>{% trans "Warning" %}</b>
|
||||
{% trans "This action cannot be easily undone" %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
@ -18,6 +18,7 @@ stock_location_detail_urls = [
|
||||
|
||||
stock_item_detail_urls = [
|
||||
url(r'^edit/', views.StockItemEdit.as_view(), name='stock-item-edit'),
|
||||
url(r'^convert/', views.StockItemConvert.as_view(), name='stock-item-convert'),
|
||||
url(r'^serialize/', views.StockItemSerialize.as_view(), name='stock-item-serialize'),
|
||||
url(r'^delete/', views.StockItemDelete.as_view(), name='stock-item-delete'),
|
||||
url(r'^qr_code/', views.StockItemQRCode.as_view(), name='stock-item-qr'),
|
||||
|
@ -887,6 +887,30 @@ class StockItemEdit(AjaxUpdateView):
|
||||
return form
|
||||
|
||||
|
||||
class StockItemConvert(AjaxUpdateView):
|
||||
"""
|
||||
View for 'converting' a StockItem to a variant of its current part.
|
||||
"""
|
||||
|
||||
model = StockItem
|
||||
form_class = StockForms.ConvertStockItemForm
|
||||
ajax_form_title = _('Convert Stock Item')
|
||||
ajax_template_name = 'stock/stockitem_convert.html'
|
||||
context_object_name = 'item'
|
||||
|
||||
def get_form(self):
|
||||
"""
|
||||
Filter the available parts.
|
||||
"""
|
||||
|
||||
form = super().get_form()
|
||||
item = self.get_object()
|
||||
|
||||
form.fields['part'].queryset = item.part.get_all_variants()
|
||||
|
||||
return form
|
||||
|
||||
|
||||
class StockLocationCreate(AjaxCreateView):
|
||||
"""
|
||||
View for creating a new StockLocation
|
||||
|
Loading…
Reference in New Issue
Block a user