Merge pull request #345 from SchrodingersGat/stocktake-confirmation

Stocktake confirmation
This commit is contained in:
Oliver 2019-05-16 23:14:45 +10:00 committed by GitHub
commit 183871f3cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 120 additions and 129 deletions

View File

@ -25,7 +25,25 @@ class CompanySerializer(serializers.ModelSerializer):
""" Serializer for Company object (full detail) """
url = serializers.CharField(source='get_absolute_url', read_only=True)
part_count = serializers.CharField(read_only=True)
class Meta:
model = Company
fields = '__all__'
fields = [
'id',
'url',
'name',
'description',
'website',
'name',
'phone',
'address',
'email',
'contact',
'URL',
'image',
'notes',
'is_customer',
'is_supplier',
'part_count'
]

View File

@ -7,19 +7,20 @@
<h3>Supplier Stock</h3>
<table class='table table-striped table-condensed' id='stock-table'>
</table>
{% include "stock_table.html" %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadStockTable($('#stock-table'),
{
loadStockTable($('#stock-table'), {
url: "{% url 'api-stock-list' %}",
params: {
supplier: {{ company.id }},
}
},
buttons: [
'#stock-options',
]
});
{% endblock %}

View File

@ -73,7 +73,14 @@ InvenTree | Supplier List
}
return '';
}
},
{
field: 'part_count',
title: 'Parts',
formatter: function(value, row, index, field) {
return renderLink(value, row.url + 'parts/');
}
},
],
url: "{% url 'api-company-list' %}"
});

View File

@ -13,25 +13,7 @@
</div>
<hr>
<div id='button-toolbar'>
{% if part.active %}
<button class='btn btn-success' id='add-stock-item'>New Stock Item</button>
{% endif %}
<div id='opt-dropdown' class="dropdown" style='float: right;'>
<button id='stock-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Options
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href='#' id='multi-item-take' title='Take items from stock'>Take items</a></li>
<li><a href='#' id='multi-item-give' title='Give items to stock'>Add items</a></li>
<li><a href="#" id='multi-item-stocktake' title='Stocktake selected stock items'>Stocktake</a></li>
<li><a href='#' id='multi-item-move' title='Move selected stock items'>Move items</a></li>
</ul>
</div>
</div>
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='stock-table'>
</table>
{% include "stock_table.html" %}
{% endblock %}
@ -62,43 +44,4 @@
url: "{% url 'api-stock-list' %}",
});
function selectedStock() {
return $("#stock-table").bootstrapTable('getSelections');
}
$("#multi-item-move").click(function() {
var items = selectedStock();
moveStockItems(items,
{
success: function() {
$("#stock-table").bootstrapTable('refresh');
}
});
return false;
});
$("#multi-item-stocktake").click(function() {
updateStockItems({
action: 'stocktake'
});
return false;
});
$("#multi-item-take").click(function() {
updateStockItems({
action: 'remove',
});
return false;
});
$("#multi-item-give").click(function() {
updateStockItems({
action: 'add',
});
return false;
})
{% endblock %}

View File

@ -43,6 +43,7 @@ function updateStock(items, options={}) {
html += '<th>Item</th>';
html += '<th>Location</th>';
html += '<th>Quantity</th>';
html += '<th>' + options.action + '</th>';
html += '</thead><tbody>';
@ -71,6 +72,9 @@ function updateStock(items, options={}) {
} else {
html += '<td><i>No location set</i></td>';
}
html += '<td>' + item.quantity + '</td>';
html += "<td><input class='form-control' ";
html += "value='" + vCur + "' ";
html += "min='" + vMin + "' ";
@ -87,8 +91,18 @@ function updateStock(items, options={}) {
html += '</tbody></table>';
html += "<hr><input type='text' id='stocktake-notes' placeholder='Notes'/>";
html += "<p class='help-inline' id='note-warning'><strong>Note field must be filled</strong></p>";
html += `
<hr>
<div class='control-group'>
<label class='checkbox'>
<input type='checkbox' id='stocktake-confirm' placeholder='Confirm'/>
Confirm Stocktake
</label>
<p class='help-inline' id='confirm-warning'><strong>Confirm stock count</strong></p>
</div>`;
html += "<p class='warning-msg' id='note-warning'><i>Note field must be filled</i></p>";
var title = '';
@ -109,6 +123,7 @@ function updateStock(items, options={}) {
});
$(modal).find('#note-warning').hide();
$(modal).find('#confirm-warning').hide();
modalEnable(modal, true);
@ -116,13 +131,23 @@ function updateStock(items, options={}) {
var stocktake = [];
var notes = $(modal).find('#stocktake-notes').val();
var confirm = $(modal).find('#stocktake-confirm').is(':checked');
var valid = true;
if (!notes) {
$(modal).find('#note-warning').show();
return false;
valid = false;
}
var valid = true;
if (!confirm) {
$(modal).find('#confirm-warning').show();
valid = false;
}
if (!valid) {
return false;
}
// Form stocktake data
for (idx = 0; idx < items.length; idx++) {
@ -413,6 +438,42 @@ function loadStockTable(table, options) {
if (options.buttons) {
linkButtonsToSelection(table, options.buttons);
}
// Automatically link button callbacks
$('#multi-item-stocktake').click(function() {
updateStockItems({
action: 'stocktake',
});
return false;
});
$('#multi-item-remove').click(function() {
updateStockItems({
action: 'remove',
});
return false;
});
$('#multi-item-add').click(function() {
updateStockItems({
action: 'add',
});
return false;
});
$("#multi-item-move").click(function() {
var items = $("#stock-table").bootstrapTable('getSelections');
moveStockItems(items,
{
success: function() {
$("#stock-table").bootstrapTable('refresh');
}
});
return false;
});
}

View File

@ -44,24 +44,7 @@
<hr>
<div id='button-toolbar'>
<div class='button-toolbar container-fluid' style='float: right;'>
<button class="btn btn-success" id='item-create'>New Stock Item</button>
<div class="dropdown" style='float: right;'>
<button id='stock-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Options<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" id='multi-item-add' title='Add to selected stock items'>Add stock</a></li>
<li><a href="#" id='multi-item-remove' title='Remove from selected stock items'>Remove stock</a></li>
<li><a href="#" id='multi-item-stocktake' title='Stocktake selected stock items'>Stocktake</a></li>
<li><a href='#' id='multi-item-move' title='Move selected stock items'>Move</a></li>
</ul>
</div>
</div>
</div>
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='stock-table'>
</table>
{% include "stock_table.html" %}
{% include 'modals.html' %}
@ -150,45 +133,6 @@
return false;
});
function selectedStock() {
return $("#stock-table").bootstrapTable('getSelections');
}
$("#multi-item-move").click(function() {
var items = selectedStock();
moveStockItems(items,
{
success: function() {
$("#stock-table").bootstrapTable('refresh');
}
});
return false;
});
$('#multi-item-stocktake').click(function() {
updateStockItems({
action: 'stocktake',
});
return false;
});
$('#multi-item-remove').click(function() {
updateStockItems({
action: 'remove',
});
return false;
});
$('#multi-item-add').click(function() {
updateStockItems({
action: 'add',
});
return false;
});
loadStockTable($("#stock-table"), {
buttons: [
'#stock-options',

View File

@ -0,0 +1,17 @@
<div id='button-toolbar'>
<div class='button-toolbar container-fluid' style='float: right;'>
<button class="btn btn-success" id='item-create'>New Stock Item</button>
<div class="dropdown" style='float: right;'>
<button id='stock-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Options<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" id='multi-item-add' title='Add to selected stock items'>Add stock</a></li>
<li><a href="#" id='multi-item-remove' title='Remove from selected stock items'>Remove stock</a></li>
<li><a href="#" id='multi-item-stocktake' title='Stocktake selected stock items'>Stocktake</a></li>
<li><a href='#' id='multi-item-move' title='Move selected stock items'>Move</a></li>
</ul>
</div>
</div>
</div>
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='stock-table'>
</table>