Merge remote-tracking branch 'inventree/master'

This commit is contained in:
Oliver Walters 2019-06-18 22:26:47 +10:00
commit 346c713cd2
11 changed files with 362 additions and 26 deletions

View File

@ -101,11 +101,6 @@ class EditPartForm(HelperForm):
'default_supplier', 'default_supplier',
'units', 'units',
'minimum_stock', 'minimum_stock',
'assembly',
'component',
'trackable',
'purchaseable',
'salable',
'notes', 'notes',
] ]

View File

@ -0,0 +1,18 @@
# Generated by Django 2.2.2 on 2019-06-18 08:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('part', '0008_auto_20190618_0042'),
]
operations = [
migrations.AddField(
model_name='part',
name='virtual',
field=models.BooleanField(default=False, help_text='Is this a virtual part, such as a software product or license?'),
),
]

View File

@ -216,6 +216,7 @@ class Part(models.Model):
purchaseable: Can this part be purchased from suppliers? purchaseable: Can this part be purchased from suppliers?
trackable: Trackable parts can have unique serial numbers assigned, etc, etc trackable: Trackable parts can have unique serial numbers assigned, etc, etc
active: Is this part active? Parts are deactivated instead of being deleted active: Is this part active? Parts are deactivated instead of being deleted
virtual: Is this part "virtual"? e.g. a software product or similar
notes: Additional notes field for this part notes: Additional notes field for this part
""" """
@ -377,6 +378,8 @@ class Part(models.Model):
active = models.BooleanField(default=True, help_text='Is this part active?') active = models.BooleanField(default=True, help_text='Is this part active?')
virtual = models.BooleanField(default=False, help_text='Is this a virtual part, such as a software product or license?')
notes = models.TextField(blank=True) notes = models.TextField(blank=True)
bom_checksum = models.CharField(max_length=128, blank=True, help_text='Stored BOM checksum') bom_checksum = models.CharField(max_length=128, blank=True, help_text='Stored BOM checksum')

View File

@ -100,8 +100,10 @@ class PartSerializer(InvenTreeModelSerializer):
'assembly', 'assembly',
'component', 'component',
'trackable', 'trackable',
'purchaseable',
'salable', 'salable',
'active', 'active',
'virtual',
] ]

View File

@ -6,7 +6,6 @@
<div class='row'> <div class='row'>
<div class='col-sm-6'> <div class='col-sm-6'>
<h4>Part Details</h4>
</div> </div>
<div class='col-sm-6'> <div class='col-sm-6'>
<div class="btn-group" style="float: right;"> <div class="btn-group" style="float: right;">
@ -30,10 +29,9 @@
</div> </div>
</div> </div>
<hr>
<div class='row'> <div class='row'>
<div class='col-sm-6'> <div class='col-sm-6'>
<h4>Part Details</h4>
<table class='table table-striped'> <table class='table table-striped'>
<tr> <tr>
<td><b>Part name</b></td> <td><b>Part name</b></td>
@ -102,37 +100,62 @@
</table> </table>
</div> </div>
<div class='col-sm-6'> <div class='col-sm-6'>
<h4>Part Type</h4>
<table class='table table-striped'> <table class='table table-striped'>
{% if part.assembly %} <tr>
<td><b>Virtual</b></td>
<td>{% include "slide.html" with state=part.virtual field='virtual' %}</td>
{% if part.virtual %}
<td>Part is virtual (not a physical part)</td>
{% else %}
<td><i>Part is not a virtual part</i></td>
{% endif %}
</tr>
<tr> <tr>
<td><b>Assembly</b></td> <td><b>Assembly</b></td>
<td><i>This part can be assembled from other parts</i></td> <td>{% include "slide.html" with state=part.assembly field='assembly' %}</td>
</tr> {% if part.assembly %}
<td>Part can be assembled from other parts</td>
{% else %}
<td><i>Part cannot be assembled from other parts</i></td>
{% endif %} {% endif %}
{% if part.component %} </tr>
<tr> <tr>
<td><b>Component</b></td> <td><b>Component</b></td>
<td><i>This part can be used in assemblies</i></td> <td>{% include "slide.html" with state=part.component field='component' %}</td>
</tr> {% if part.component %}
<td>Part can be used in assemblies</td>
{% else %}
<td><i>Part cannot be used in assemblies</i></td>
{% endif %} {% endif %}
{% if part.trackable %} </tr>
<tr> <tr>
<td><b>Trackable</b></td> <td><b>Trackable</b></td>
<td><i>Stock for this part will be tracked by (serial or batch)</i></td> <td>{% include "slide.html" with state=part.trackable field='trackable' %}</td>
</tr> {% if part.trackable %}
<td>Part stock will be tracked by (serial or batch)</td>
{% else %}
<td><i>Part stock will not be tracked by</i></td>
{% endif %} {% endif %}
{% if part.purchaseable %} </tr>
<tr> <tr>
<td><b>Purchaseable</b></td> <td><b>Purchaseable</b></td>
<td><i>This part can be purchased from external suppliers</i></td> <td>{% include "slide.html" with state=part.purchaseable field='purchaseable' %}</td>
</tr> {% if part.purchaseable %}
<td>Part can be purchased from external suppliers</td>
{% else %}
<td><i>Part can be purchased from external suppliers</i></td>
{% endif %} {% endif %}
{% if part.salable %} </tr>
<tr> <tr>
<td><b>Salable</b></td> <td><b>Sellable</b></td>
<td><i>This part can be sold to customers</i></td> <td>{% include "slide.html" with state=part.salable field='salable' %}</td>
</tr> {% if part.salable %}
<td>Part can be sold to customers</td>
{% else %}
<td><i>Part cannot be sold to customers</i></td>
{% endif %} {% endif %}
</tr>
</table> </table>
</div> </div>
</div> </div>
@ -153,6 +176,25 @@
{% block js_ready %} {% block js_ready %}
{{ block.super }} {{ block.super }}
$(".slidey").change(function() {
var field = $(this).attr('field');
var checked = $(this).prop('checked');
var data = {};
data[field] = checked;
// Update the particular field
inventreePut("/api/part/{{ part.id }}/",
data,
{
method: 'PATCH',
reloadOnSuccess: true,
},
);
});
$("#duplicate-part").click(function() { $("#duplicate-part").click(function() {
launchModalForm( launchModalForm(
"{% url 'part-duplicate' part.id %}", "{% url 'part-duplicate' part.id %}",

View File

@ -0,0 +1,83 @@
/*! ========================================================================
* Bootstrap Toggle: bootstrap-toggle.css v2.2.0
* http://www.bootstraptoggle.com
* ========================================================================
* Copyright 2014 Min Hur, The New York Times Company
* Licensed under MIT
* ======================================================================== */
.checkbox label .toggle,
.checkbox-inline .toggle {
margin-left: -20px;
margin-right: 5px;
}
.toggle {
position: relative;
overflow: hidden;
}
.toggle input[type="checkbox"] {
display: none;
}
.toggle-group {
position: absolute;
width: 200%;
top: 0;
bottom: 0;
left: 0;
transition: left 0.35s;
-webkit-transition: left 0.35s;
-moz-user-select: none;
-webkit-user-select: none;
}
.toggle.off .toggle-group {
left: -100%;
}
.toggle-on {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 50%;
margin: 0;
border: 0;
border-radius: 0;
}
.toggle-off {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
right: 0;
margin: 0;
border: 0;
border-radius: 0;
}
.toggle-handle {
position: relative;
margin: 0 auto;
padding-top: 0px;
padding-bottom: 0px;
height: 100%;
width: 0px;
border-width: 0 1px;
}
.toggle.btn { min-width: 59px; min-height: 34px; }
.toggle-on.btn { padding-right: 24px; }
.toggle-off.btn { padding-left: 24px; }
.toggle.btn-lg { min-width: 79px; min-height: 45px; }
.toggle-on.btn-lg { padding-right: 31px; }
.toggle-off.btn-lg { padding-left: 31px; }
.toggle-handle.btn-lg { width: 40px; }
.toggle.btn-sm { border-radius: 15px; min-width: 50px; min-height: 20px; max-height: 25px;}
.toggle-on.btn-sm { padding-right: 20px; }
.toggle-off.btn-sm { padding-left: 20px; }
.toggle.btn-xs { min-width: 35px; min-height: 22px;}
.toggle-on.btn-xs { padding-right: 12px; }
.toggle-off.btn-xs { padding-left: 12px; }

View File

@ -22,6 +22,14 @@
color: rgb(13, 245, 25); color: rgb(13, 245, 25);
} }
.glyphicon-ok {
color: #5f5;
}
.glyphicon-remove {
color: #f55;
}
/* CSS overrides for treeview */ /* CSS overrides for treeview */
.expand-icon { .expand-icon {
font-size: 11px; font-size: 11px;

View File

@ -0,0 +1,180 @@
/*! ========================================================================
* Bootstrap Toggle: bootstrap-toggle.js v2.2.0
* http://www.bootstraptoggle.com
* ========================================================================
* Copyright 2014 Min Hur, The New York Times Company
* Licensed under MIT
* ======================================================================== */
+function ($) {
'use strict';
// TOGGLE PUBLIC CLASS DEFINITION
// ==============================
var Toggle = function (element, options) {
this.$element = $(element)
this.options = $.extend({}, this.defaults(), options)
this.render()
}
Toggle.VERSION = '2.2.0'
Toggle.DEFAULTS = {
on: '',
off: '',
onstyle: 'primary',
offstyle: 'default',
size: 'normal',
style: '',
width: null,
height: null
}
Toggle.prototype.defaults = function() {
return {
on: this.$element.attr('data-on') || Toggle.DEFAULTS.on,
off: this.$element.attr('data-off') || Toggle.DEFAULTS.off,
onstyle: this.$element.attr('data-onstyle') || Toggle.DEFAULTS.onstyle,
offstyle: this.$element.attr('data-offstyle') || Toggle.DEFAULTS.offstyle,
size: this.$element.attr('data-size') || Toggle.DEFAULTS.size,
style: this.$element.attr('data-style') || Toggle.DEFAULTS.style,
width: this.$element.attr('data-width') || Toggle.DEFAULTS.width,
height: this.$element.attr('data-height') || Toggle.DEFAULTS.height
}
}
Toggle.prototype.render = function () {
this._onstyle = 'btn-' + this.options.onstyle
this._offstyle = 'btn-' + this.options.offstyle
var size = this.options.size === 'large' ? 'btn-lg'
: this.options.size === 'small' ? 'btn-sm'
: this.options.size === 'mini' ? 'btn-xs'
: ''
var $toggleOn = $('<label class="btn">').html(this.options.on)
.addClass(this._onstyle + ' ' + size)
var $toggleOff = $('<label class="btn">').html(this.options.off)
.addClass(this._offstyle + ' ' + size + ' active')
var $toggleHandle = $('<span class="toggle-handle btn btn-default">')
.addClass(size)
var $toggleGroup = $('<div class="toggle-group">')
.append($toggleOn, $toggleOff, $toggleHandle)
var $toggle = $('<div class="toggle btn" data-toggle="toggle">')
.addClass( this.$element.prop('checked') ? this._onstyle : this._offstyle+' off' )
.addClass(size).addClass(this.options.style)
this.$element.wrap($toggle)
$.extend(this, {
$toggle: this.$element.parent(),
$toggleOn: $toggleOn,
$toggleOff: $toggleOff,
$toggleGroup: $toggleGroup
})
this.$toggle.append($toggleGroup)
var width = this.options.width || Math.max($toggleOn.outerWidth(), $toggleOff.outerWidth())+($toggleHandle.outerWidth()/2)
var height = this.options.height || Math.max($toggleOn.outerHeight(), $toggleOff.outerHeight())
$toggleOn.addClass('toggle-on')
$toggleOff.addClass('toggle-off')
this.$toggle.css({ width: width, height: height })
if (this.options.height) {
$toggleOn.css('line-height', $toggleOn.height() + 'px')
$toggleOff.css('line-height', $toggleOff.height() + 'px')
}
this.update(true)
this.trigger(true)
}
Toggle.prototype.toggle = function () {
if (this.$element.prop('checked')) this.off()
else this.on()
}
Toggle.prototype.on = function (silent) {
if (this.$element.prop('disabled')) return false
this.$toggle.removeClass(this._offstyle + ' off').addClass(this._onstyle)
this.$element.prop('checked', true)
if (!silent) this.trigger()
}
Toggle.prototype.off = function (silent) {
if (this.$element.prop('disabled')) return false
this.$toggle.removeClass(this._onstyle).addClass(this._offstyle + ' off')
this.$element.prop('checked', false)
if (!silent) this.trigger()
}
Toggle.prototype.enable = function () {
this.$toggle.removeAttr('disabled')
this.$element.prop('disabled', false)
}
Toggle.prototype.disable = function () {
this.$toggle.attr('disabled', 'disabled')
this.$element.prop('disabled', true)
}
Toggle.prototype.update = function (silent) {
if (this.$element.prop('disabled')) this.disable()
else this.enable()
if (this.$element.prop('checked')) this.on(silent)
else this.off(silent)
}
Toggle.prototype.trigger = function (silent) {
this.$element.off('change.bs.toggle')
if (!silent) this.$element.change()
this.$element.on('change.bs.toggle', $.proxy(function() {
this.update()
}, this))
}
Toggle.prototype.destroy = function() {
this.$element.off('change.bs.toggle')
this.$toggleGroup.remove()
this.$element.removeData('bs.toggle')
this.$element.unwrap()
}
// TOGGLE PLUGIN DEFINITION
// ========================
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.toggle')
var options = typeof option == 'object' && option
if (!data) $this.data('bs.toggle', (data = new Toggle(this, options)))
if (typeof option == 'string' && data[option]) data[option]()
})
}
var old = $.fn.bootstrapToggle
$.fn.bootstrapToggle = Plugin
$.fn.bootstrapToggle.Constructor = Toggle
// TOGGLE NO CONFLICT
// ==================
$.fn.toggle.noConflict = function () {
$.fn.bootstrapToggle = old
return this
}
// TOGGLE DATA-API
// ===============
$(function() {
$('input[type=checkbox][data-toggle^=toggle]').bootstrapToggle()
})
$(document).on('click.bs.toggle', 'div[data-toggle^=toggle]', function(e) {
var $checkbox = $(this).find('input[type=checkbox]')
$checkbox.bootstrapToggle('toggle')
e.preventDefault()
})
}(jQuery);

View File

@ -33,6 +33,7 @@
<link rel="stylesheet" href="{% static 'css/bootstrap-table-group-by.css' %}"> <link rel="stylesheet" href="{% static 'css/bootstrap-table-group-by.css' %}">
<link rel="stylesheet" href="{% static 'css/select2.css' %}"> <link rel="stylesheet" href="{% static 'css/select2.css' %}">
<link rel="stylesheet" href="{% static 'css/select2-bootstrap.css' %}"> <link rel="stylesheet" href="{% static 'css/select2-bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'css/bootstrap-toggle.css' %}">
<link rel="stylesheet" href="{% static 'css/inventree.css' %}"> <link rel="stylesheet" href="{% static 'css/inventree.css' %}">
{% block css %} {% block css %}
@ -91,6 +92,7 @@ InvenTree
<script type='text/javascript' src="{% static 'script/bootstrap/bootstrap-table.js' %}"></script> <script type='text/javascript' src="{% static 'script/bootstrap/bootstrap-table.js' %}"></script>
<script type='text/javascript' src="{% static 'script/bootstrap/bootstrap-table-en-US.min.js' %}"></script> <script type='text/javascript' src="{% static 'script/bootstrap/bootstrap-table-en-US.min.js' %}"></script>
<script type='text/javascript' src="{% static 'script/bootstrap/bootstrap-table-group-by.js' %}"></script> <script type='text/javascript' src="{% static 'script/bootstrap/bootstrap-table-group-by.js' %}"></script>
<script type='text/javascript' src="{% static 'script/bootstrap/bootstrap-toggle.js' %}"></script>
<script type="text/javascript" src="{% static 'script/select2/select2.js' %}"></script> <script type="text/javascript" src="{% static 'script/select2/select2.js' %}"></script>
<script type='text/javascript' src="{% static 'script/moment.js' %}"></script> <script type='text/javascript' src="{% static 'script/moment.js' %}"></script>

View File

@ -0,0 +1,3 @@
<div>
<input field='{{ field }}' class='slidey' type="checkbox" data-onstyle="success" data-size='small' data-toggle="toggle" {% if disabled %}disabled="disabled" {% endif %}{% if state %}checked="checked"{% endif %}>
</div>

View File

@ -1,6 +1,6 @@
<div id='button-toolbar'> <div id='button-toolbar'>
<div class='button-toolbar container-fluid' style='float: right;'> <div class='button-toolbar container-fluid' style='float: right;'>
{% if part.is_template == False %} {% if not part or part.is_template == False %}
<button class="btn btn-success" id='item-create'>New Stock Item</button> <button class="btn btn-success" id='item-create'>New Stock Item</button>
{% endif %} {% endif %}
<div class="dropdown" style='float: right;'> <div class="dropdown" style='float: right;'>