Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/frontend/src/components/render/Stock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
type InstanceRenderInterface,
RenderInlineModel
} from './Instance';
import { StatusRenderer, getStatusCodes } from './StatusRenderer';

/**
* Inline rendering of a single StockLocation instance
Expand Down Expand Up @@ -102,6 +103,17 @@
const showLocation: boolean = props.extra?.show_location !== false;
const location: any = props.instance?.location_detail;

const statusKey = instance?.status_custom_key ?? instance?.status;
const flaggedStatusNames = ['ATTENTION', 'DAMAGED'];

Check warning on line 107 in src/frontend/src/components/render/Stock.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

`flaggedStatusNames` should be a `Set`, and use `flaggedStatusNames.has()` to check existence or non-existence.

See more on https://sonarcloud.io/project/issues?id=inventree_InvenTree&issues=AZ8axlxRXV8YJoY6x1vL&open=AZ8axlxRXV8YJoY6x1vL&pullRequest=12286
const statusCodes = getStatusCodes(ModelType.stockitem);
const showStatus =
props.extra?.show_status === true &&
!!statusCodes &&
Object.values(statusCodes.values).some(
(entry) =>
entry.key == statusKey && flaggedStatusNames.includes(entry.name)
);

// Form the "secondary" text to display
const secondary: ReactNode = (
<Group gap='xs' style={{ paddingLeft: '5px' }}>
Expand All @@ -111,6 +123,9 @@
{instance.batch && (
<InlineSecondaryBadge title={t`Batch`} text={instance.batch} />
)}
{showStatus && (
<StatusRenderer status={statusKey} type={ModelType.stockitem} />
)}
</Group>
);

Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/forms/BuildForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@
field_type: 'related field',
api_url: apiUrl(ApiEndpoints.stock_item_list),
model: ModelType.stockitem,
modelRenderer: ({ instance }: { instance: any }) => (

Check warning on line 571 in src/frontend/src/forms/BuildForms.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this component definition out of the parent component and pass data as props.

See more on https://sonarcloud.io/project/issues?id=inventree_InvenTree&issues=AZ8axl3JXV8YJoY6x1vP&open=AZ8axl3JXV8YJoY6x1vP&pullRequest=12286

Check warning on line 571 in src/frontend/src/forms/BuildForms.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'instance' PropType is defined but prop is never used

See more on https://sonarcloud.io/project/issues?id=inventree_InvenTree&issues=AZ8axl3JXV8YJoY6x1vO&open=AZ8axl3JXV8YJoY6x1vO&pullRequest=12286
<RenderStockItem instance={instance} extra={{ show_status: true }} />
),
autoFill: !output || !!output?.serial,
autoFillFilters: {
serial: output?.serial
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/forms/SalesOrderForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { ModelType } from '@lib/enums/ModelType';
import RemoveRowButton from '../components/buttons/RemoveRowButton';
import { StandaloneField } from '../components/forms/StandaloneField';
import { RenderStockItem } from '../components/render/Stock';

import { ProgressBar } from '@lib/components/ProgressBar';
import { apiUrl } from '@lib/functions/Api';
Expand Down Expand Up @@ -319,6 +320,9 @@
field_type: 'related field',
api_url: apiUrl(ApiEndpoints.stock_item_list),
model: ModelType.stockitem,
modelRenderer: ({ instance }: { instance: any }) => (

Check warning on line 323 in src/frontend/src/forms/SalesOrderForms.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'instance' PropType is defined but prop is never used

See more on https://sonarcloud.io/project/issues?id=inventree_InvenTree&issues=AZ8axl2tXV8YJoY6x1vM&open=AZ8axl2tXV8YJoY6x1vM&pullRequest=12286

Check warning on line 323 in src/frontend/src/forms/SalesOrderForms.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this component definition out of the parent component and pass data as props.

See more on https://sonarcloud.io/project/issues?id=inventree_InvenTree&issues=AZ8axl2tXV8YJoY6x1vN&open=AZ8axl2tXV8YJoY6x1vN&pullRequest=12286
<RenderStockItem instance={instance} extra={{ show_status: true }} />
),
autoFill: true,
filters: {
available: true,
Expand Down