Skip to content
Merged
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
49 changes: 43 additions & 6 deletions src/frontend/src/components/wizards/OrderPartsWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ function PartRequirementsInfo({
* - part: The part instance
* - supplier_part: The selected supplier part instance
* - purchase_order: The selected purchase order instance
* - quantity: The quantity of the part to order
* - quantity: The quantity of the part to order (taking supplier pack size into account)
* - quantity_raw: The raw quantity entered by the user (before adjusting for supplier pack size)
* - errors: Error messages for each attribute
*/
interface PartOrderRecord {
part: any;
supplier_part: any;
purchase_order: any;
quantity: number;
quantity_raw?: number;
errors: any;
}

Expand Down Expand Up @@ -277,6 +279,7 @@ function SelectPartsStep({
{
accessor: 'part',
title: t`Part`,
minWidth: 200,
render: (record: PartOrderRecord) => (
<Tooltip label={record.part?.description}>
<Paper p='xs'>
Expand Down Expand Up @@ -375,7 +378,7 @@ function SelectPartsStep({
{
accessor: 'quantity',
title: t`Quantity`,
width: 150,
width: 175,
render: (record: PartOrderRecord) => (
<Group gap='xs' wrap='nowrap'>
<StandaloneField
Expand Down Expand Up @@ -425,7 +428,12 @@ function SelectPartsStep({
)
}
];
}, [onRemovePart]);
}, [
onSelectSupplierPart,
onSelectPurchaseOrder,
onSelectQuantity,
onRemovePart
]);

if (records.length === 0) {
return (
Expand Down Expand Up @@ -483,6 +491,10 @@ export default function OrderPartsWizard({
records.forEach((record: PartOrderRecord, index: number) => {
if (record.part.pk === partId) {
records[index].quantity = quantity;

if (records[index].quantity_raw === undefined) {
records[index].quantity_raw = quantity;
}
}
});

Expand All @@ -499,6 +511,21 @@ export default function OrderPartsWizard({
records.forEach((record: PartOrderRecord, index: number) => {
if (record.part.pk === partId) {
records[index].supplier_part = supplierPart;

if (!records[index].quantity_raw && !!records[index].quantity) {
records[index].quantity_raw = records[index].quantity;
}

if (
supplierPart?.pack_quantity_native &&
records[index].quantity_raw
) {
// Adjust the quantity based on the supplier pack size
records[index].quantity = Math.max(
0,
records[index].quantity_raw / supplierPart.pack_quantity_native
);
}
}
});

Expand Down Expand Up @@ -536,7 +563,13 @@ export default function OrderPartsWizard({
/>
);
},
[selectedParts]
[
selectedParts,
removePart,
selectQuantity,
selectSupplierPart,
selectPurchaseOrder
]
);

const canStepForward = useCallback(
Expand Down Expand Up @@ -614,13 +647,17 @@ export default function OrderPartsWizard({
const on_order = part.ordering ?? 0;
const in_production = part.building ?? 0;

const to_order = required - on_hand - on_order - in_production;
const to_order = Math.max(
0,
required - on_hand - on_order - in_production
);

records.push({
part: part,
supplier_part: undefined,
purchase_order: undefined,
quantity: Math.max(to_order, 0),
quantity: to_order,
quantity_raw: undefined,
errors: {}
});
}
Expand Down
Loading