mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-20 05:46:34 +00:00
Merge branch 'master' of github.com:inventree/InvenTree into part_main_details
This commit is contained in:
@ -118,9 +118,17 @@ class CategoryList(generics.ListCreateAPIView):
|
||||
|
||||
ordering_fields = [
|
||||
'name',
|
||||
'level',
|
||||
'tree_id',
|
||||
'lft',
|
||||
]
|
||||
|
||||
ordering = 'name'
|
||||
# Use hierarchical ordering by default
|
||||
ordering = [
|
||||
'tree_id',
|
||||
'lft',
|
||||
'name'
|
||||
]
|
||||
|
||||
search_fields = [
|
||||
'name',
|
||||
|
@ -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',
|
||||
|
@ -32,6 +32,8 @@ class CategorySerializer(InvenTreeModelSerializer):
|
||||
|
||||
parts = serializers.IntegerField(source='item_count', read_only=True)
|
||||
|
||||
level = serializers.IntegerField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = PartCategory
|
||||
fields = [
|
||||
@ -40,10 +42,11 @@ class CategorySerializer(InvenTreeModelSerializer):
|
||||
'description',
|
||||
'default_location',
|
||||
'default_keywords',
|
||||
'pathstring',
|
||||
'url',
|
||||
'level',
|
||||
'parent',
|
||||
'parts',
|
||||
'pathstring',
|
||||
'url',
|
||||
]
|
||||
|
||||
|
||||
|
@ -370,6 +370,16 @@
|
||||
sub_part_detail: true,
|
||||
});
|
||||
|
||||
// Load the BOM table data in the pricing view
|
||||
loadBomTable($("#bom-pricing-table"), {
|
||||
editable: {{ editing_enabled }},
|
||||
bom_url: "{% url 'api-bom-list' %}",
|
||||
part_url: "{% url 'api-part-list' %}",
|
||||
parent_id: {{ part.id }} ,
|
||||
sub_part_detail: true,
|
||||
});
|
||||
|
||||
|
||||
linkButtonsToSelection($("#bom-table"),
|
||||
[
|
||||
"#bom-item-delete",
|
||||
@ -634,17 +644,9 @@
|
||||
});
|
||||
|
||||
$("#stock-export").click(function() {
|
||||
launchModalForm("{% url 'stock-export-options' %}", {
|
||||
submit_text: "{% trans 'Export' %}",
|
||||
success: function(response) {
|
||||
var url = "{% url 'stock-export' %}";
|
||||
|
||||
url += "?format=" + response.format;
|
||||
url += "&cascade=" + response.cascade;
|
||||
url += "&part={{ part.id }}";
|
||||
|
||||
location.href = url;
|
||||
},
|
||||
exportStock({
|
||||
part: {{ part.pk }}
|
||||
});
|
||||
});
|
||||
|
||||
@ -801,45 +803,41 @@
|
||||
)
|
||||
});
|
||||
|
||||
function reloadSupplierPartTable() {
|
||||
$('#supplier-part-table').bootstrapTable('refresh');
|
||||
}
|
||||
|
||||
$('#supplier-create').click(function () {
|
||||
launchModalForm(
|
||||
"{% url 'supplier-part-create' %}",
|
||||
{
|
||||
reload: true,
|
||||
data: {
|
||||
part: {{ part.id }}
|
||||
},
|
||||
secondary: [
|
||||
{
|
||||
field: 'supplier',
|
||||
label: '{% trans "New Supplier" %}',
|
||||
title: '{% trans "Create new supplier" %}',
|
||||
},
|
||||
{
|
||||
field: 'manufacturer',
|
||||
label: '{% trans "New Manufacturer" %}',
|
||||
title: '{% trans "Create new manufacturer" %}',
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
createSupplierPart({
|
||||
part: {{ part.pk }},
|
||||
onSuccess: reloadSupplierPartTable,
|
||||
});
|
||||
});
|
||||
|
||||
$("#supplier-part-delete").click(function() {
|
||||
|
||||
var selections = $("#supplier-part-table").bootstrapTable("getSelections");
|
||||
|
||||
var parts = [];
|
||||
var requests = [];
|
||||
|
||||
selections.forEach(function(item) {
|
||||
parts.push(item.pk);
|
||||
});
|
||||
|
||||
launchModalForm("{% url 'supplier-part-delete' %}", {
|
||||
data: {
|
||||
parts: parts,
|
||||
},
|
||||
reload: true,
|
||||
});
|
||||
showQuestionDialog(
|
||||
'{% trans "Delete Supplier Parts?" %}',
|
||||
'{% trans "All selected supplier parts will be deleted" %}',
|
||||
{
|
||||
accept: function() {
|
||||
selections.forEach(function(part) {
|
||||
var url = `/api/company/part/${part.pk}/`;
|
||||
|
||||
requests.push(inventreeDelete(url));
|
||||
});
|
||||
|
||||
$.when.apply($, requests).then(function() {
|
||||
reloadSupplierPartTable();
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
loadSupplierPartTable(
|
||||
@ -883,21 +881,10 @@
|
||||
});
|
||||
|
||||
$('#manufacturer-create').click(function () {
|
||||
|
||||
constructForm('{% url "api-manufacturer-part-list" %}', {
|
||||
fields: {
|
||||
part: {
|
||||
value: {{ part.pk }},
|
||||
hidden: true,
|
||||
},
|
||||
manufacturer: {},
|
||||
MPN: {},
|
||||
description: {},
|
||||
link: {},
|
||||
},
|
||||
method: 'POST',
|
||||
title: '{% trans "Add Manufacturer Part" %}',
|
||||
onSuccess: function() {
|
||||
|
||||
createManufacturerPart({
|
||||
part: {{ part.pk }},
|
||||
onSuccess: function() {
|
||||
$("#manufacturer-part-table").bootstrapTable("refresh");
|
||||
}
|
||||
});
|
||||
|
@ -217,7 +217,7 @@
|
||||
<div class='panel-content'>
|
||||
<div class="row">
|
||||
<div class="col col-md-6">
|
||||
<table class='table table-bom table-condensed' data-toolbar="#button-toolbar" id='bom-table'></table>
|
||||
<table class='table table-bom table-condensed' data-toolbar="#button-toolbar" id='bom-pricing-table'></table>
|
||||
</div>
|
||||
|
||||
{% if part.bom_count > 0 %}
|
||||
|
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user