mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Add database model for defining custom units (#5268)
* Add database model for defining custom units - Database model - DRF serializer - API endpoints * Add validation hook * Custom check for the 'definition' field * Add settings page for custom units - Table of units - Create / edit / delete buttons * Allow "unit" field to be empty - Not actually required for custom unit definition * Load custom unit definitions into global registry * Docs: add core concepts page(s) * Add some back links * Update docs * Add unit test for custom unit conversion * More unit testing * remove print statements * Add missing table rule
This commit is contained in:
21
InvenTree/templates/InvenTree/settings/physical_units.html
Normal file
21
InvenTree/templates/InvenTree/settings/physical_units.html
Normal file
@ -0,0 +1,21 @@
|
||||
{% extends "panel.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load inventree_extras %}
|
||||
|
||||
{% block label %}units{% endblock label %}
|
||||
|
||||
{% block heading %}{% trans "Physical Units" %}{% endblock heading %}
|
||||
{% block actions %}
|
||||
<button class='btn btn-success' id='custom-unit-create'>
|
||||
<span class='fas fa-plus-circle'></span>
|
||||
{% trans "Add Unit" %}
|
||||
</button>
|
||||
{% endblock actions %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<table class='table table-striped table-condensed' id='physical-units-table'>
|
||||
</table>
|
||||
|
||||
{% endblock content %}
|
@ -32,6 +32,7 @@
|
||||
{% include "InvenTree/settings/login.html" %}
|
||||
{% include "InvenTree/settings/barcode.html" %}
|
||||
{% include "InvenTree/settings/project_codes.html" %}
|
||||
{% include "InvenTree/settings/physical_units.html" %}
|
||||
{% include "InvenTree/settings/notifications.html" %}
|
||||
{% include "InvenTree/settings/label.html" %}
|
||||
{% include "InvenTree/settings/report.html" %}
|
||||
|
@ -52,6 +52,82 @@ onPanelLoad('pricing', function() {
|
||||
});
|
||||
});
|
||||
|
||||
// Javascript for units panel
|
||||
onPanelLoad('units', function() {
|
||||
|
||||
console.log("units panel");
|
||||
|
||||
// Construct the "units" table
|
||||
$('#physical-units-table').bootstrapTable({
|
||||
url: '{% url "api-custom-unit-list" %}',
|
||||
search: true,
|
||||
columns: [
|
||||
{
|
||||
field: 'name',
|
||||
title: '{% trans "Name" %}',
|
||||
},
|
||||
{
|
||||
field: 'definition',
|
||||
title: '{% trans "Definition" %}',
|
||||
},
|
||||
{
|
||||
field: 'symbol',
|
||||
title: '{% trans "Symbol" %}',
|
||||
formatter: function(value, row) {
|
||||
let html = value;
|
||||
let buttons = '';
|
||||
|
||||
buttons += makeEditButton('button-units-edit', row.pk, '{% trans "Edit" %}');
|
||||
buttons += makeDeleteButton('button-units-delete', row.pk, '{% trans "Delete" %}');
|
||||
|
||||
html += wrapButtons(buttons);
|
||||
return html;
|
||||
}
|
||||
},
|
||||
]
|
||||
});
|
||||
|
||||
// Callback to edit a custom unit
|
||||
$('#physical-units-table').on('click', '.button-units-edit', function() {
|
||||
let pk = $(this).attr('pk');
|
||||
|
||||
constructForm(`{% url "api-custom-unit-list" %}${pk}/`, {
|
||||
title: '{% trans "Edit Custom Unit" %}',
|
||||
fields: {
|
||||
name: {},
|
||||
definition: {},
|
||||
symbol: {},
|
||||
},
|
||||
refreshTable: '#physical-units-table',
|
||||
});
|
||||
});
|
||||
|
||||
// Callback to delete a custom unit
|
||||
$('#physical-units-table').on('click', '.button-units-delete', function() {
|
||||
let pk = $(this).attr('pk');
|
||||
|
||||
constructForm(`{% url "api-custom-unit-list" %}${pk}/`, {
|
||||
title: '{% trans "Delete Custom Unit" %}',
|
||||
method: 'DELETE',
|
||||
refreshTable: '#physical-units-table',
|
||||
});
|
||||
});
|
||||
|
||||
// Callback to create a new custom unit
|
||||
$('#custom-unit-create').click(function() {
|
||||
constructForm('{% url "api-custom-unit-list" %}', {
|
||||
fields: {
|
||||
name: {},
|
||||
definition: {},
|
||||
symbol: {},
|
||||
},
|
||||
title: '{% trans "New Custom Unit" %}',
|
||||
method: 'POST',
|
||||
refreshTable: '#physical-units-table',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Javascript for project codes panel
|
||||
onPanelLoad('project-codes', function() {
|
||||
|
||||
|
@ -32,6 +32,8 @@
|
||||
{% include "sidebar_item.html" with label='barcodes' text=text icon="fa-qrcode" %}
|
||||
{% trans "Project Codes" as text %}
|
||||
{% include "sidebar_item.html" with label='project-codes' text=text icon="fa-list" %}
|
||||
{% trans "Physical Units" as text %}
|
||||
{% include "sidebar_item.html" with label='units' text=text icon="fa-balance-scale" %}
|
||||
{% trans "Notifications" as text %}
|
||||
{% include "sidebar_item.html" with label='global-notifications' text=text icon="fa-bell" %}
|
||||
{% trans "Pricing" as text %}
|
||||
|
Reference in New Issue
Block a user