mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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
|
||||
from InvenTree.version import inventreeVersion
|
||||
|
||||
# Logger configuration
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
def setup_tracing(
|
||||
endpoint: str,
|
||||
@ -46,6 +43,9 @@ def setup_tracing(
|
||||
if InvenTree.ready.isImportingData() or InvenTree.ready.isRunningMigrations():
|
||||
return
|
||||
|
||||
# Logger configuration
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
if resources_input is None:
|
||||
resources_input = {}
|
||||
if auth is None:
|
||||
|
@ -84,6 +84,9 @@ def getNewestMigrationFile(app, exclude_extension=True):
|
||||
newest_num = num
|
||||
newest_file = f
|
||||
|
||||
if not newest_file: # pragma: no cover
|
||||
return newest_file
|
||||
|
||||
if exclude_extension:
|
||||
newest_file = newest_file.replace('.py', '')
|
||||
|
||||
|
@ -51,6 +51,9 @@ class MatchFieldForm(forms.Form):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if not file_manager: # pragma: no cover
|
||||
return
|
||||
|
||||
# Setup FileManager
|
||||
file_manager.setup()
|
||||
# Get columns
|
||||
@ -87,6 +90,9 @@ class MatchItemForm(forms.Form):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if not file_manager: # pragma: no cover
|
||||
return
|
||||
|
||||
# Setup FileManager
|
||||
file_manager.setup()
|
||||
|
||||
|
@ -714,8 +714,6 @@ class StockItem(
|
||||
self.delete_on_deplete = False
|
||||
|
||||
except PartModels.Part.DoesNotExist:
|
||||
# This gets thrown if self.supplier_part is null
|
||||
# TODO - Find a test than can be performed...
|
||||
pass
|
||||
|
||||
# Ensure that the item cannot be assigned to itself
|
||||
@ -1109,7 +1107,11 @@ class StockItem(
|
||||
|
||||
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 item
|
||||
@ -1773,7 +1775,7 @@ class StockItem(
|
||||
price = convert_money(price, base_currency)
|
||||
total_price += price * qty
|
||||
quantity += qty
|
||||
except:
|
||||
except Exception:
|
||||
# Skip this entry, cannot convert to base currency
|
||||
continue
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* globals
|
||||
inventreeGet,
|
||||
*/
|
||||
|
||||
/* exported
|
||||
@ -25,8 +26,8 @@ function activatePanel(label, panel_name, options={}) {
|
||||
panel_name = panel_name.replace('/', '');
|
||||
|
||||
// Find the target panel
|
||||
var panel = `#panel-${panel_name}`;
|
||||
var select = `#select-${panel_name}`;
|
||||
let panel = `#panel-${panel_name}`;
|
||||
let select = `#select-${panel_name}`;
|
||||
|
||||
// Check that the selected panel (and select) exist
|
||||
if ($(panel).exists() && $(panel).length && $(select).length) {
|
||||
@ -37,7 +38,7 @@ function activatePanel(label, panel_name, options={}) {
|
||||
panel_name = null;
|
||||
|
||||
$('.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)) {
|
||||
panel_name = name;
|
||||
@ -64,7 +65,7 @@ function activatePanel(label, panel_name, options={}) {
|
||||
$('.list-group-item').removeClass('active');
|
||||
|
||||
// Find the associated selector
|
||||
var selector = `#select-${panel_name}`;
|
||||
const selector = `#select-${panel_name}`;
|
||||
|
||||
$(selector).addClass('active');
|
||||
}
|
||||
@ -75,7 +76,7 @@ function onPanelLoad(panel, callback) {
|
||||
// Used to implement lazy-loading, rather than firing
|
||||
// multiple AJAX queries when the page is first loaded.
|
||||
|
||||
var panelId = `#panel-${panel}`;
|
||||
const panelId = `#panel-${panel}`;
|
||||
|
||||
$(panelId).on('fadeInStarted', function() {
|
||||
|
||||
@ -96,10 +97,10 @@ function enableSidebar(label, options={}) {
|
||||
|
||||
// Enable callbacks for sidebar buttons
|
||||
$('.sidebar-selector').click(function() {
|
||||
var el = $(this);
|
||||
const el = $(this);
|
||||
|
||||
// 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);
|
||||
});
|
||||
@ -111,16 +112,16 @@ function enableSidebar(label, options={}) {
|
||||
* - 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) {
|
||||
activatePanel(label, selected_panel);
|
||||
} else {
|
||||
// Find the "first" available panel (according to the sidebar)
|
||||
var selector = $('.sidebar-selector').first();
|
||||
const selector = $('.sidebar-selector').first();
|
||||
|
||||
if (selector.exists()) {
|
||||
var panel_name = selector.attr('id').replace('select-', '');
|
||||
const panel_name = selector.attr('id').replace('select-', '');
|
||||
activatePanel(label, panel_name);
|
||||
}
|
||||
}
|
||||
@ -133,7 +134,7 @@ function enableSidebar(label, options={}) {
|
||||
// Add callback to "collapse" and "expand" the sidebar
|
||||
|
||||
// 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!
|
||||
setSidebarState(label, state == 'expanded' ? 'collapsed' : 'expanded');
|
||||
@ -141,7 +142,7 @@ function enableSidebar(label, options={}) {
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
@ -161,10 +162,8 @@ function enableSidebar(label, options={}) {
|
||||
function generateTreeStructure(data, options) {
|
||||
const nodes = {};
|
||||
const roots = [];
|
||||
let node = null;
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
node = data[i];
|
||||
for (let node of data) {
|
||||
nodes[node.pk] = node;
|
||||
node.selectable = false;
|
||||
|
||||
@ -178,9 +177,7 @@ function generateTreeStructure(data, options) {
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
node = data[i];
|
||||
|
||||
for (let node of data) {
|
||||
if (node.parent != null) {
|
||||
if (nodes[node.parent].nodes) {
|
||||
nodes[node.parent].nodes.push(node);
|
||||
@ -208,14 +205,14 @@ function generateTreeStructure(data, options) {
|
||||
*/
|
||||
function enableBreadcrumbTree(options) {
|
||||
|
||||
var label = options.label;
|
||||
const label = options.label;
|
||||
|
||||
if (!label) {
|
||||
console.error('enableBreadcrumbTree called without supplying label');
|
||||
return;
|
||||
}
|
||||
|
||||
var filters = options.filters || {};
|
||||
const filters = options.filters || {};
|
||||
|
||||
inventreeGet(
|
||||
options.url,
|
||||
@ -283,7 +280,7 @@ function setSidebarState(label, state) {
|
||||
*/
|
||||
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'>
|
||||
<i class='bi bi-bootstrap'></i>
|
||||
${options.content_before || ''}
|
||||
@ -302,7 +299,7 @@ function addSidebarItem(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">
|
||||
<h6>
|
||||
<i class="bi bi-bootstrap"></i>
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
// 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"
|
||||
>
|
||||
<IconCopy size={10} />
|
||||
{label && <div> </div>}
|
||||
{label && label}
|
||||
{label && (
|
||||
<>
|
||||
<div> </div>
|
||||
{label}
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</MantineCopyButton>
|
||||
|
@ -112,7 +112,8 @@ export function GroupTable() {
|
||||
}),
|
||||
RowDeleteAction({
|
||||
onClick: () => {
|
||||
setSelectedGroup(record.pk), deleteGroup.open();
|
||||
setSelectedGroup(record.pk);
|
||||
deleteGroup.open();
|
||||
}
|
||||
})
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user