Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various small code quality cleanups #7626

Merged
merged 15 commits into from
Jul 11, 2024
6 changes: 3 additions & 3 deletions src/backend/InvenTree/InvenTree/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import InvenTree.ready
from InvenTree.version import inventreeVersion

# Logger configuration
logger = logging.getLogger('inventree')


def setup_tracing(
endpoint: str,
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/backend/InvenTree/InvenTree/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')

Expand Down
6 changes: 6 additions & 0 deletions src/backend/InvenTree/common/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

if not file_manager: # pragma: no cover
return

# Setup FileManager
file_manager.setup()
# Get columns
Expand Down Expand Up @@ -87,6 +90,9 @@ def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

if not file_manager: # pragma: no cover
return

# Setup FileManager
file_manager.setup()

Expand Down
10 changes: 6 additions & 4 deletions src/backend/InvenTree/stock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,6 @@ def clean(self):
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
Expand Down Expand Up @@ -1109,7 +1107,11 @@ def allocateToCustomer(

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
Expand Down Expand Up @@ -1773,7 +1775,7 @@ def merge_stock_items(self, other_items, raise_error=False, **kwargs):
price = convert_money(price, base_currency)
total_price += price * qty
quantity += qty
except:
except Exception:
# Skip this entry, cannot convert to base currency
continue

Expand Down
41 changes: 19 additions & 22 deletions src/backend/InvenTree/templates/js/dynamic/nav.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* globals
inventreeGet,
*/

/* exported
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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');
}
Expand All @@ -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() {

Expand All @@ -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);
});
Expand All @@ -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);
}
}
Expand All @@ -133,15 +134,15 @@ 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');
});
}

// 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);

Expand All @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 || ''}
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

// Keep track of the current user permissions
var user_roles = null;
let user_roles = null;


/*
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/src/components/buttons/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ export function CopyButton({
size="compact-md"
>
<IconCopy size={10} />
{label && <div>&nbsp;</div>}
{label && label}
{label && (
<>
<div>&nbsp;</div>
{label}
</>
)}
</Button>
)}
</MantineCopyButton>
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/tables/settings/GroupTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export function GroupTable() {
}),
RowDeleteAction({
onClick: () => {
setSelectedGroup(record.pk), deleteGroup.open();
setSelectedGroup(record.pk);
deleteGroup.open();
}
})
];
Expand Down
Loading