Skip to content

Commit

Permalink
Build allocation table updates (#7106)
Browse files Browse the repository at this point in the history
* Update build line allocation table

- Allow display of "tracked" items in main allocation table

* Add resolveItem function for finding nested items

* Update BuildLineTable

* Allow BuildLineList to be ordered by 'trackable' field

* Bump API version
  • Loading branch information
SchrodingersGat committed Apr 23, 2024
1 parent 8f2ef39 commit 3e52e5f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/backend/InvenTree/InvenTree/api_version.py
@@ -1,11 +1,14 @@
"""InvenTree API version information."""

# InvenTree API version
INVENTREE_API_VERSION = 191
INVENTREE_API_VERSION = 192
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""

INVENTREE_API_TEXT = """
v192 - 2024-04-23 : https://github.com/inventree/InvenTree/pull/7106
- Adds 'trackable' ordering option to BuildLineLabel API endpoint
v191 - 2024-04-22 : https://github.com/inventree/InvenTree/pull/7079
- Adds API endpoints for Contenttype model
Expand Down
2 changes: 2 additions & 0 deletions src/backend/InvenTree/build/api.py
Expand Up @@ -349,6 +349,7 @@ class BuildLineList(BuildLineEndpoint, ListCreateAPI):
'optional',
'unit_quantity',
'available_stock',
'trackable',
]

ordering_field_aliases = {
Expand All @@ -357,6 +358,7 @@ class BuildLineList(BuildLineEndpoint, ListCreateAPI):
'unit_quantity': 'bom_item__quantity',
'consumable': 'bom_item__consumable',
'optional': 'bom_item__optional',
'trackable': 'bom_item__sub_part__trackable',
}

search_fields = [
Expand Down
10 changes: 6 additions & 4 deletions src/backend/InvenTree/templates/js/translated/build.js
Expand Up @@ -2436,11 +2436,9 @@ function loadBuildLineTable(table, build_id, options={}) {
params.build = build_id;

if (output) {
params.tracked = true;
params.output = output;
name += `-${output}`;
} else {
// Default to untracked parts for the build
params.tracked = false;
}

let filters = loadTableFilters('buildlines', params);
Expand Down Expand Up @@ -2649,7 +2647,11 @@ function loadBuildLineTable(table, build_id, options={}) {

if (row.part_detail.trackable && !options.output) {
// Tracked parts must be allocated to a specific build output
return `<em>{% trans "Tracked item" %}</em>`;
return `
<div>
<em>{% trans "Tracked item" %}</em>
<span title='{% trans "Allocate tracked items against individual build outputs" %}' class='fas fa-info-circle icon-blue' />
</div>`;
}

if (row.allocated < row.quantity) {
Expand Down
13 changes: 13 additions & 0 deletions src/frontend/src/functions/conversion.tsx
Expand Up @@ -19,3 +19,16 @@ export function isTrue(value: any): boolean {

return ['true', 'yes', '1', 'on', 't', 'y'].includes(s);
}

/*
* Resolve a nested item in an object.
* Returns the resolved item, if it exists.
*
* e.g. resolveItem(data, "sub.key.accessor")
*
* Allows for retrieval of nested items in an object.
*/
export function resolveItem(obj: any, path: string): any {
let properties = path.split('.');
return properties.reduce((prev, curr) => prev?.[curr], obj);
}
3 changes: 1 addition & 2 deletions src/frontend/src/pages/build/BuildDetail.tsx
Expand Up @@ -203,8 +203,7 @@ export default function BuildDetail() {
content: build?.pk ? (
<BuildLineTable
params={{
build: id,
tracked: false
build: id
}}
/>
) : (
Expand Down
13 changes: 10 additions & 3 deletions src/frontend/src/tables/ColumnRenderers.tsx
Expand Up @@ -3,6 +3,7 @@
*/
import { t } from '@lingui/macro';
import { Anchor } from '@mantine/core';
import { access } from 'fs';

import { YesNoButton } from '../components/buttons/YesNoButton';
import { Thumbnail } from '../components/images/Thumbnail';
Expand All @@ -11,6 +12,7 @@ import { TableStatusRenderer } from '../components/render/StatusRenderer';
import { RenderOwner } from '../components/render/User';
import { formatCurrency, renderDate } from '../defaults/formatters';
import { ModelType } from '../enums/ModelType';
import { resolveItem } from '../functions/conversion';
import { cancelEvent } from '../functions/events';
import { TableColumn } from './Column';
import { ProjectCodeHoverCard } from './TableHoverCard';
Expand All @@ -29,19 +31,24 @@ export function BooleanColumn({
accessor,
title,
sortable,
switchable
switchable,
ordering
}: {
accessor: string;
title?: string;
ordering?: string;
sortable?: boolean;
switchable?: boolean;
}): TableColumn {
return {
accessor: accessor,
title: title,
ordering: ordering,
sortable: sortable ?? true,
switchable: switchable ?? true,
render: (record: any) => <YesNoButton value={record[accessor]} />
render: (record: any) => (
<YesNoButton value={resolveItem(record, accessor)} />
)
};
}

Expand Down Expand Up @@ -71,7 +78,7 @@ export function LinkColumn({
accessor: accessor,
sortable: false,
render: (record: any) => {
let url = record[accessor];
let url = resolveItem(record, accessor);

if (!url) {
return '-';
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/src/tables/InvenTreeTable.tsx
Expand Up @@ -28,6 +28,7 @@ import { ActionButton } from '../components/buttons/ActionButton';
import { ButtonMenu } from '../components/buttons/ButtonMenu';
import { ApiFormFieldSet } from '../components/forms/fields/ApiFormField';
import { ModelType } from '../enums/ModelType';
import { resolveItem } from '../functions/conversion';
import { extractAvailableFields, mapFields } from '../functions/forms';
import { getDetailUrl } from '../functions/urls';
import { TableState } from '../hooks/UseTable';
Expand Down Expand Up @@ -519,7 +520,8 @@ export function InvenTreeTable<T = any>({
// If a custom row click handler is provided, use that
props.onRowClick(record, index, event);
} else if (tableProps.modelType) {
const pk = record?.[tableProps.modelField ?? 'pk'];
const accessor = tableProps.modelField ?? 'pk';
const pk = resolveItem(record, accessor);

if (pk) {
// If a model type is provided, navigate to the detail view for that model
Expand Down
36 changes: 25 additions & 11 deletions src/frontend/src/tables/build/BuildLineTable.tsx
Expand Up @@ -6,13 +6,11 @@ import {
IconTool
} from '@tabler/icons-react';
import { useCallback, useMemo } from 'react';
import { useNavigate } from 'react-router-dom';

import { PartHoverCard } from '../../components/images/Thumbnail';
import { ProgressBar } from '../../components/items/ProgressBar';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { ModelType } from '../../enums/ModelType';
import { getDetailUrl } from '../../functions/urls';
import { useTable } from '../../hooks/UseTable';
import { apiUrl } from '../../states/ApiState';
import { useUserState } from '../../states/UserState';
Expand All @@ -25,7 +23,6 @@ import { TableHoverCard } from '../TableHoverCard';
export default function BuildLineTable({ params = {} }: { params?: any }) {
const table = useTable('buildline');
const user = useUserState();
const navigate = useNavigate();

const tableFilters: TableFilter[] = useMemo(() => {
return [
Expand All @@ -47,6 +44,11 @@ export default function BuildLineTable({ params = {} }: { params?: any }) {
name: 'optional',
label: t`Optional`,
description: t`Show optional lines`
},
{
name: 'tracked',
label: t`Tracked`,
description: t`Show tracked lines`
}
];
}, []);
Expand Down Expand Up @@ -122,18 +124,28 @@ export default function BuildLineTable({ params = {} }: { params?: any }) {
return [
{
accessor: 'bom_item',
ordering: 'part',
sortable: true,
switchable: false,
render: (record: any) => <PartHoverCard part={record.part_detail} />
},
{
accessor: 'bom_item_detail.reference'
accessor: 'bom_item_detail.reference',
ordering: 'reference',
sortable: true,
title: t`Reference`
},
BooleanColumn({
accessor: 'bom_item_detail.consumable'
accessor: 'bom_item_detail.consumable',
ordering: 'consumable'
}),
BooleanColumn({
accessor: 'bom_item_detail.optional',
ordering: 'optional'
}),
BooleanColumn({
accessor: 'bom_item_detail.optional'
accessor: 'part_detail.trackable',
ordering: 'trackable'
}),
{
accessor: 'bom_item_detail.quantity',
Expand Down Expand Up @@ -198,6 +210,11 @@ export default function BuildLineTable({ params = {} }: { params?: any }) {
return [];
}

// Tracked items must be allocated to a particular output
if (record?.part_detail?.trackable) {
return [];
}

return [
{
icon: <IconArrowRight />,
Expand Down Expand Up @@ -234,11 +251,8 @@ export default function BuildLineTable({ params = {} }: { params?: any }) {
},
tableFilters: tableFilters,
rowActions: rowActions,
onRowClick: (row: any) => {
if (row?.part_detail?.pk) {
navigate(getDetailUrl(ModelType.part, row.part_detail.pk));
}
}
modelType: ModelType.part,
modelField: 'part_detail.pk'
}}
/>
);
Expand Down

0 comments on commit 3e52e5f

Please sign in to comment.