2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 13:06:45 +00:00

[PUI] part stock (#7179)

* [PUI] Update PartDetail page

- Cleanup details fields
- Add extra badge

* Update StockItem table

- Display items which are not "in stock" as red
This commit is contained in:
Oliver 2024-05-08 12:19:09 +10:00 committed by GitHub
parent 108bd28102
commit e24c4c56fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 18 deletions

View File

@ -188,18 +188,19 @@ export default function PartDetail() {
]; ];
let tr: DetailsField[] = [ let tr: DetailsField[] = [
{
type: 'string',
name: 'unallocated_stock',
unit: true,
label: t`Available Stock`
},
{ {
type: 'string', type: 'string',
name: 'total_in_stock', name: 'total_in_stock',
unit: true, unit: true,
label: t`In Stock` label: t`In Stock`
}, },
{
type: 'string',
name: 'unallocated_stock',
unit: true,
label: t`Available Stock`,
hidden: part.total_in_stock == part.unallocated_stock
},
{ {
type: 'string', type: 'string',
name: 'minimum_stock', name: 'minimum_stock',
@ -220,10 +221,7 @@ export default function PartDetail() {
total: part.required_for_build_orders, total: part.required_for_build_orders,
progress: part.allocated_to_build_orders, progress: part.allocated_to_build_orders,
label: t`Allocated to Build Orders`, label: t`Allocated to Build Orders`,
hidden: hidden: !part.component || part.required_for_build_orders <= 0
!part.assembly ||
(part.allocated_to_build_orders <= 0 &&
part.required_for_build_orders <= 0)
}, },
{ {
type: 'progressbar', type: 'progressbar',
@ -231,10 +229,7 @@ export default function PartDetail() {
total: part.required_for_sales_orders, total: part.required_for_sales_orders,
progress: part.allocated_to_sales_orders, progress: part.allocated_to_sales_orders,
label: t`Allocated to Sales Orders`, label: t`Allocated to Sales Orders`,
hidden: hidden: !part.salable || part.required_for_sales_orders <= 0
!part.salable ||
(part.allocated_to_sales_orders <= 0 &&
part.required_for_sales_orders <= 0)
}, },
{ {
type: 'string', type: 'string',
@ -306,7 +301,8 @@ export default function PartDetail() {
name: 'creation_user', name: 'creation_user',
label: t`Created By`, label: t`Created By`,
badge: 'user', badge: 'user',
icon: 'user' icon: 'user',
hidden: !part.creation_user
}, },
{ {
type: 'string', type: 'string',
@ -645,11 +641,17 @@ export default function PartDetail() {
return [ return [
<DetailsBadge <DetailsBadge
label={t`In Stock` + `: ${part.in_stock}`} label={t`In Stock` + `: ${part.total_in_stock}`}
color={part.in_stock >= part.minimum_stock ? 'green' : 'orange'} color={part.in_stock >= part.minimum_stock ? 'green' : 'orange'}
visible={part.in_stock > 0} visible={part.in_stock > 0}
key="in_stock" key="in_stock"
/>, />,
<DetailsBadge
label={t`Available` + `: ${part.unallocated_stock}`}
color="yellow"
key="available_stock"
visible={part.unallocated_stock != part.total_in_stock}
/>,
<DetailsBadge <DetailsBadge
label={t`No Stock`} label={t`No Stock`}
color="red" color="red"
@ -671,7 +673,7 @@ export default function PartDetail() {
<DetailsBadge <DetailsBadge
label={t`Inactive`} label={t`Inactive`}
color="red" color="red"
visible={!part.active} visible={part.active == false}
key="inactive" key="inactive"
/> />
]; ];

View File

@ -65,6 +65,18 @@ function stockItemTableColumns(): TableColumn[] {
let extra: ReactNode[] = []; let extra: ReactNode[] = [];
let color = undefined; let color = undefined;
// Determine if a stock item is "in stock"
// TODO: Refactor this out into a function
let in_stock =
!record?.belongs_to &&
!record?.consumed_by &&
!record?.customer &&
!record?.is_building &&
!record?.sales_order &&
!record?.expired &&
record?.quantity &&
record?.quantity > 0;
if (record.serial && quantity == 1) { if (record.serial && quantity == 1) {
text = `# ${record.serial}`; text = `# ${record.serial}`;
} }
@ -166,7 +178,6 @@ function stockItemTableColumns(): TableColumn[] {
} }
if (quantity <= 0) { if (quantity <= 0) {
color = 'red';
extra.push( extra.push(
<Text <Text
key="depleted" key="depleted"
@ -175,6 +186,10 @@ function stockItemTableColumns(): TableColumn[] {
); );
} }
if (!in_stock) {
color = 'red';
}
return ( return (
<TableHoverCard <TableHoverCard
value={ value={