mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-03 13:58:47 +00:00
Various small code quality cleanups (#7626)
* fix possible access to None value * fix possible access to empty valie * fix possible access to empty value * define exception * remove old todo * fix trigger on none * merge condition * remove empty object pattern * fix typo * fix usage of var * add missing import * use for of itterator instead * use let instead of var * move declaration to ensure logger is accessible * Revert "remove empty object pattern" This reverts commit 4701cc97ec30dac38bc63806142859a67a9ba8d7.
This commit is contained in:
parent
5d1f2b3ac0
commit
3d8235423a
@ -22,9 +22,6 @@ from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExport
|
|||||||
import InvenTree.ready
|
import InvenTree.ready
|
||||||
from InvenTree.version import inventreeVersion
|
from InvenTree.version import inventreeVersion
|
||||||
|
|
||||||
# Logger configuration
|
|
||||||
logger = logging.getLogger('inventree')
|
|
||||||
|
|
||||||
|
|
||||||
def setup_tracing(
|
def setup_tracing(
|
||||||
endpoint: str,
|
endpoint: str,
|
||||||
@ -46,6 +43,9 @@ def setup_tracing(
|
|||||||
if InvenTree.ready.isImportingData() or InvenTree.ready.isRunningMigrations():
|
if InvenTree.ready.isImportingData() or InvenTree.ready.isRunningMigrations():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Logger configuration
|
||||||
|
logger = logging.getLogger('inventree')
|
||||||
|
|
||||||
if resources_input is None:
|
if resources_input is None:
|
||||||
resources_input = {}
|
resources_input = {}
|
||||||
if auth is None:
|
if auth is None:
|
||||||
|
@ -84,6 +84,9 @@ def getNewestMigrationFile(app, exclude_extension=True):
|
|||||||
newest_num = num
|
newest_num = num
|
||||||
newest_file = f
|
newest_file = f
|
||||||
|
|
||||||
|
if not newest_file: # pragma: no cover
|
||||||
|
return newest_file
|
||||||
|
|
||||||
if exclude_extension:
|
if exclude_extension:
|
||||||
newest_file = newest_file.replace('.py', '')
|
newest_file = newest_file.replace('.py', '')
|
||||||
|
|
||||||
|
@ -51,6 +51,9 @@ class MatchFieldForm(forms.Form):
|
|||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
if not file_manager: # pragma: no cover
|
||||||
|
return
|
||||||
|
|
||||||
# Setup FileManager
|
# Setup FileManager
|
||||||
file_manager.setup()
|
file_manager.setup()
|
||||||
# Get columns
|
# Get columns
|
||||||
@ -87,6 +90,9 @@ class MatchItemForm(forms.Form):
|
|||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
if not file_manager: # pragma: no cover
|
||||||
|
return
|
||||||
|
|
||||||
# Setup FileManager
|
# Setup FileManager
|
||||||
file_manager.setup()
|
file_manager.setup()
|
||||||
|
|
||||||
|
@ -714,8 +714,6 @@ class StockItem(
|
|||||||
self.delete_on_deplete = False
|
self.delete_on_deplete = False
|
||||||
|
|
||||||
except PartModels.Part.DoesNotExist:
|
except PartModels.Part.DoesNotExist:
|
||||||
# This gets thrown if self.supplier_part is null
|
|
||||||
# TODO - Find a test than can be performed...
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Ensure that the item cannot be assigned to itself
|
# Ensure that the item cannot be assigned to itself
|
||||||
@ -1109,7 +1107,11 @@ class StockItem(
|
|||||||
|
|
||||||
item.add_tracking_entry(code, user, deltas, notes=notes)
|
item.add_tracking_entry(code, user, deltas, notes=notes)
|
||||||
|
|
||||||
trigger_event('stockitem.assignedtocustomer', id=self.id, customer=customer.id)
|
trigger_event(
|
||||||
|
'stockitem.assignedtocustomer',
|
||||||
|
id=self.id,
|
||||||
|
customer=customer.id if customer else None,
|
||||||
|
)
|
||||||
|
|
||||||
# Return the reference to the stock item
|
# Return the reference to the stock item
|
||||||
return item
|
return item
|
||||||
@ -1773,7 +1775,7 @@ class StockItem(
|
|||||||
price = convert_money(price, base_currency)
|
price = convert_money(price, base_currency)
|
||||||
total_price += price * qty
|
total_price += price * qty
|
||||||
quantity += qty
|
quantity += qty
|
||||||
except:
|
except Exception:
|
||||||
# Skip this entry, cannot convert to base currency
|
# Skip this entry, cannot convert to base currency
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/* globals
|
/* globals
|
||||||
|
inventreeGet,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* exported
|
/* exported
|
||||||
@ -25,8 +26,8 @@ function activatePanel(label, panel_name, options={}) {
|
|||||||
panel_name = panel_name.replace('/', '');
|
panel_name = panel_name.replace('/', '');
|
||||||
|
|
||||||
// Find the target panel
|
// Find the target panel
|
||||||
var panel = `#panel-${panel_name}`;
|
let panel = `#panel-${panel_name}`;
|
||||||
var select = `#select-${panel_name}`;
|
let select = `#select-${panel_name}`;
|
||||||
|
|
||||||
// Check that the selected panel (and select) exist
|
// Check that the selected panel (and select) exist
|
||||||
if ($(panel).exists() && $(panel).length && $(select).length) {
|
if ($(panel).exists() && $(panel).length && $(select).length) {
|
||||||
@ -37,7 +38,7 @@ function activatePanel(label, panel_name, options={}) {
|
|||||||
panel_name = null;
|
panel_name = null;
|
||||||
|
|
||||||
$('.sidebar-selector').each(function() {
|
$('.sidebar-selector').each(function() {
|
||||||
var name = $(this).attr('id').replace('select-', '');
|
const name = $(this).attr('id').replace('select-', '');
|
||||||
|
|
||||||
if ($(`#panel-${name}`).length && (panel_name == null)) {
|
if ($(`#panel-${name}`).length && (panel_name == null)) {
|
||||||
panel_name = name;
|
panel_name = name;
|
||||||
@ -64,7 +65,7 @@ function activatePanel(label, panel_name, options={}) {
|
|||||||
$('.list-group-item').removeClass('active');
|
$('.list-group-item').removeClass('active');
|
||||||
|
|
||||||
// Find the associated selector
|
// Find the associated selector
|
||||||
var selector = `#select-${panel_name}`;
|
const selector = `#select-${panel_name}`;
|
||||||
|
|
||||||
$(selector).addClass('active');
|
$(selector).addClass('active');
|
||||||
}
|
}
|
||||||
@ -75,7 +76,7 @@ function onPanelLoad(panel, callback) {
|
|||||||
// Used to implement lazy-loading, rather than firing
|
// Used to implement lazy-loading, rather than firing
|
||||||
// multiple AJAX queries when the page is first loaded.
|
// multiple AJAX queries when the page is first loaded.
|
||||||
|
|
||||||
var panelId = `#panel-${panel}`;
|
const panelId = `#panel-${panel}`;
|
||||||
|
|
||||||
$(panelId).on('fadeInStarted', function() {
|
$(panelId).on('fadeInStarted', function() {
|
||||||
|
|
||||||
@ -96,10 +97,10 @@ function enableSidebar(label, options={}) {
|
|||||||
|
|
||||||
// Enable callbacks for sidebar buttons
|
// Enable callbacks for sidebar buttons
|
||||||
$('.sidebar-selector').click(function() {
|
$('.sidebar-selector').click(function() {
|
||||||
var el = $(this);
|
const el = $(this);
|
||||||
|
|
||||||
// Find the matching panel element to display
|
// Find the matching panel element to display
|
||||||
var panel_name = el.attr('id').replace('select-', '');
|
const panel_name = el.attr('id').replace('select-', '');
|
||||||
|
|
||||||
activatePanel(label, panel_name, options);
|
activatePanel(label, panel_name, options);
|
||||||
});
|
});
|
||||||
@ -111,16 +112,16 @@ function enableSidebar(label, options={}) {
|
|||||||
* - Third preference = default
|
* - Third preference = default
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var selected_panel = $.urlParam('display') || localStorage.getItem(`inventree-selected-panel-${label}`) || options.default;
|
const selected_panel = $.urlParam('display') || localStorage.getItem(`inventree-selected-panel-${label}`) || options.default;
|
||||||
|
|
||||||
if (selected_panel) {
|
if (selected_panel) {
|
||||||
activatePanel(label, selected_panel);
|
activatePanel(label, selected_panel);
|
||||||
} else {
|
} else {
|
||||||
// Find the "first" available panel (according to the sidebar)
|
// Find the "first" available panel (according to the sidebar)
|
||||||
var selector = $('.sidebar-selector').first();
|
const selector = $('.sidebar-selector').first();
|
||||||
|
|
||||||
if (selector.exists()) {
|
if (selector.exists()) {
|
||||||
var panel_name = selector.attr('id').replace('select-', '');
|
const panel_name = selector.attr('id').replace('select-', '');
|
||||||
activatePanel(label, panel_name);
|
activatePanel(label, panel_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +134,7 @@ function enableSidebar(label, options={}) {
|
|||||||
// Add callback to "collapse" and "expand" the sidebar
|
// Add callback to "collapse" and "expand" the sidebar
|
||||||
|
|
||||||
// By default, the menu is "expanded"
|
// By default, the menu is "expanded"
|
||||||
var state = localStorage.getItem(`inventree-menu-state-${label}`) || 'expanded';
|
const state = localStorage.getItem(`inventree-menu-state-${label}`) || 'expanded';
|
||||||
|
|
||||||
// We wish to "toggle" the state!
|
// We wish to "toggle" the state!
|
||||||
setSidebarState(label, state == 'expanded' ? 'collapsed' : 'expanded');
|
setSidebarState(label, state == 'expanded' ? 'collapsed' : 'expanded');
|
||||||
@ -141,7 +142,7 @@ function enableSidebar(label, options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the initial state (default = expanded)
|
// Set the initial state (default = expanded)
|
||||||
var state = localStorage.getItem(`inventree-menu-state-${label}`) || 'expanded';
|
const state = localStorage.getItem(`inventree-menu-state-${label}`) || 'expanded';
|
||||||
|
|
||||||
setSidebarState(label, state);
|
setSidebarState(label, state);
|
||||||
|
|
||||||
@ -161,10 +162,8 @@ function enableSidebar(label, options={}) {
|
|||||||
function generateTreeStructure(data, options) {
|
function generateTreeStructure(data, options) {
|
||||||
const nodes = {};
|
const nodes = {};
|
||||||
const roots = [];
|
const roots = [];
|
||||||
let node = null;
|
|
||||||
|
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (let node of data) {
|
||||||
node = data[i];
|
|
||||||
nodes[node.pk] = node;
|
nodes[node.pk] = node;
|
||||||
node.selectable = false;
|
node.selectable = false;
|
||||||
|
|
||||||
@ -178,9 +177,7 @@ function generateTreeStructure(data, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (let node of data) {
|
||||||
node = data[i];
|
|
||||||
|
|
||||||
if (node.parent != null) {
|
if (node.parent != null) {
|
||||||
if (nodes[node.parent].nodes) {
|
if (nodes[node.parent].nodes) {
|
||||||
nodes[node.parent].nodes.push(node);
|
nodes[node.parent].nodes.push(node);
|
||||||
@ -208,14 +205,14 @@ function generateTreeStructure(data, options) {
|
|||||||
*/
|
*/
|
||||||
function enableBreadcrumbTree(options) {
|
function enableBreadcrumbTree(options) {
|
||||||
|
|
||||||
var label = options.label;
|
const label = options.label;
|
||||||
|
|
||||||
if (!label) {
|
if (!label) {
|
||||||
console.error('enableBreadcrumbTree called without supplying label');
|
console.error('enableBreadcrumbTree called without supplying label');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var filters = options.filters || {};
|
const filters = options.filters || {};
|
||||||
|
|
||||||
inventreeGet(
|
inventreeGet(
|
||||||
options.url,
|
options.url,
|
||||||
@ -283,7 +280,7 @@ function setSidebarState(label, state) {
|
|||||||
*/
|
*/
|
||||||
function addSidebarItem(options={}) {
|
function addSidebarItem(options={}) {
|
||||||
|
|
||||||
var html = `
|
const html = `
|
||||||
<a href='#' id='select-${options.label}' title='${options.text}' class='list-group-item sidebar-list-group-item border-end d-inline-block text-truncate sidebar-selector' data-bs-parent='#sidebar'>
|
<a href='#' id='select-${options.label}' title='${options.text}' class='list-group-item sidebar-list-group-item border-end d-inline-block text-truncate sidebar-selector' data-bs-parent='#sidebar'>
|
||||||
<i class='bi bi-bootstrap'></i>
|
<i class='bi bi-bootstrap'></i>
|
||||||
${options.content_before || ''}
|
${options.content_before || ''}
|
||||||
@ -302,7 +299,7 @@ function addSidebarItem(options={}) {
|
|||||||
*/
|
*/
|
||||||
function addSidebarHeader(options={}) {
|
function addSidebarHeader(options={}) {
|
||||||
|
|
||||||
var html = `
|
const html = `
|
||||||
<span title='${options.text}' class="list-group-item sidebar-list-group-item border-end d-inline-block text-truncate" data-bs-parent="#sidebar">
|
<span title='${options.text}' class="list-group-item sidebar-list-group-item border-end d-inline-block text-truncate" data-bs-parent="#sidebar">
|
||||||
<h6>
|
<h6>
|
||||||
<i class="bi bi-bootstrap"></i>
|
<i class="bi bi-bootstrap"></i>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Keep track of the current user permissions
|
// Keep track of the current user permissions
|
||||||
var user_roles = null;
|
let user_roles = null;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -20,8 +20,12 @@ export function CopyButton({
|
|||||||
size="compact-md"
|
size="compact-md"
|
||||||
>
|
>
|
||||||
<IconCopy size={10} />
|
<IconCopy size={10} />
|
||||||
{label && <div> </div>}
|
{label && (
|
||||||
{label && label}
|
<>
|
||||||
|
<div> </div>
|
||||||
|
{label}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</MantineCopyButton>
|
</MantineCopyButton>
|
||||||
|
@ -112,7 +112,8 @@ export function GroupTable() {
|
|||||||
}),
|
}),
|
||||||
RowDeleteAction({
|
RowDeleteAction({
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setSelectedGroup(record.pk), deleteGroup.open();
|
setSelectedGroup(record.pk);
|
||||||
|
deleteGroup.open();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user