mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 13:06:45 +00:00
Part table extra options (#5821)
* Render stock information on hover in part table * Fix minimum_stock serializer field
This commit is contained in:
parent
a83bc32fc7
commit
43fac17796
@ -715,6 +715,8 @@ class PartSerializer(InvenTree.serializers.RemoteImageMixin, InvenTree.serialize
|
|||||||
unallocated_stock = serializers.FloatField(read_only=True)
|
unallocated_stock = serializers.FloatField(read_only=True)
|
||||||
variant_stock = serializers.FloatField(read_only=True)
|
variant_stock = serializers.FloatField(read_only=True)
|
||||||
|
|
||||||
|
minimum_stock = serializers.FloatField()
|
||||||
|
|
||||||
image = InvenTree.serializers.InvenTreeImageSerializerField(required=False, allow_null=True)
|
image = InvenTree.serializers.InvenTreeImageSerializerField(required=False, allow_null=True)
|
||||||
thumbnail = serializers.CharField(source='get_thumbnail_url', read_only=True)
|
thumbnail = serializers.CharField(source='get_thumbnail_url', read_only=True)
|
||||||
starred = serializers.SerializerMethodField()
|
starred = serializers.SerializerMethodField()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Group, Text } from '@mantine/core';
|
import { Group, Stack, Text } from '@mantine/core';
|
||||||
import { useMemo } from 'react';
|
import { ReactNode, useMemo } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { shortenString } from '../../../functions/tables';
|
import { shortenString } from '../../../functions/tables';
|
||||||
@ -10,6 +10,7 @@ import { Thumbnail } from '../../images/Thumbnail';
|
|||||||
import { TableColumn } from '../Column';
|
import { TableColumn } from '../Column';
|
||||||
import { TableFilter } from '../Filter';
|
import { TableFilter } from '../Filter';
|
||||||
import { InvenTreeTable, InvenTreeTableProps } from '../InvenTreeTable';
|
import { InvenTreeTable, InvenTreeTableProps } from '../InvenTreeTable';
|
||||||
|
import { TableHoverCard } from '../TableHoverCard';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a list of columns for the part table
|
* Construct a list of columns for the part table
|
||||||
@ -57,6 +58,7 @@ function partTableColumns(): TableColumn[] {
|
|||||||
accessor: 'category',
|
accessor: 'category',
|
||||||
title: t`Category`,
|
title: t`Category`,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
switchable: true,
|
||||||
render: function (record: any) {
|
render: function (record: any) {
|
||||||
// TODO: Link to the category detail page
|
// TODO: Link to the category detail page
|
||||||
return shortenString({
|
return shortenString({
|
||||||
@ -68,7 +70,76 @@ function partTableColumns(): TableColumn[] {
|
|||||||
accessor: 'total_in_stock',
|
accessor: 'total_in_stock',
|
||||||
title: t`Stock`,
|
title: t`Stock`,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
switchable: true
|
switchable: true,
|
||||||
|
render: (record) => {
|
||||||
|
let extra: ReactNode[] = [];
|
||||||
|
|
||||||
|
let stock = record?.total_in_stock ?? 0;
|
||||||
|
|
||||||
|
let text = String(stock);
|
||||||
|
|
||||||
|
let color: string | undefined = undefined;
|
||||||
|
|
||||||
|
if (record.minimum_stock > stock) {
|
||||||
|
extra.push(
|
||||||
|
<Text color="orange">
|
||||||
|
{t`Minimum stock` + `: ${record.minimum_stock}`}
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
|
||||||
|
color = 'orange';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (record.ordering > 0) {
|
||||||
|
extra.push(<Text>{t`On Order` + `: ${record.ordering}`}</Text>);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (record.building) {
|
||||||
|
extra.push(<Text>{t`Building` + `: ${record.building}`}</Text>);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (record.allocated_to_build_orders > 0) {
|
||||||
|
extra.push(
|
||||||
|
<Text>
|
||||||
|
{t`Build Order Allocations` +
|
||||||
|
`: ${record.allocated_to_build_orders}`}
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (record.allocated_to_sales_orders > 0) {
|
||||||
|
extra.push(
|
||||||
|
<Text>
|
||||||
|
{t`Sales Order Allocations` +
|
||||||
|
`: ${record.allocated_to_sales_orders}`}
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Add extra information on stock "deman"
|
||||||
|
|
||||||
|
if (stock == 0) {
|
||||||
|
color = 'red';
|
||||||
|
text = t`No stock`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableHoverCard
|
||||||
|
value={
|
||||||
|
<Group spacing="xs" position="left">
|
||||||
|
<Text color={color}>{text}</Text>
|
||||||
|
{record.units && (
|
||||||
|
<Text size="xs" color="color">
|
||||||
|
[{record.units}]
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
}
|
||||||
|
title={t`Stock Information`}
|
||||||
|
extra={extra.length > 0 && <Stack spacing="xs">{extra}</Stack>}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessor: 'price_range',
|
accessor: 'price_range',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user