[bug] Can build fix (#13090)

* Fix 'can_build' calculation

- Take 'piece_count' into consideration
- Update queryset annotations
- Update quantity calculation call sites

* Updated docs
This commit is contained in:
Oliver authored and GitHub committed 2026-10-24 17:28:07 +11:00
1 parent 66e3278ea7
commit 43956b9324
19 files changed
+368 -25

No files matched your search

+10 -1
View File
@@ -85,6 +85,11 @@ function quantityChain(record: any): number[] {
return record.quantity_chain ?? [Number(record.quantity)];
}
// Quantity of a BomItem required for a single parent assembly (quantity x piece_count)
function unitQuantity(record: any): number {
return Number(record.quantity) * Number(record.piece_count ?? 1);
}
// Quantity of a BomItem required for a single unit of the top-level assembly
function totalQuantity(record: any): number {
return quantityChain(record).reduce((total, qty) => total * qty, 1);
@@ -821,7 +826,11 @@ export function BomTable({
// Multiply quantities through each level of the BOM
transformChild: (child: any, parent: any) => ({
...child,
quantity_chain: [Number(child.quantity), ...quantityChain(parent)]
quantity_chain: [
Number(child.quantity),
unitQuantity(parent),
...quantityChain(parent).slice(1)
]
})
};
}, [isEditing, showSubassemblies]);
@@ -69,6 +69,14 @@ function isLineConsumable(record: any): boolean {
);
}
/**
* Return the quantity of a BOM item required for a single assembly,
* accounting for the piece count (total material = quantity x piece_count).
*/
export function bomUnitQuantity(bom_item: any): number {
return Number(bom_item?.quantity ?? 0) * Number(bom_item?.piece_count ?? 1);
}
function allocationPartDiffers(allocation: any, bomPartId: number): boolean {
const allocatedPartId = allocation.part_detail?.pk;
@@ -465,7 +473,9 @@ export default function BuildLineTable({
render: (record: any) => {
return (
<Group justify='space-between' wrap='nowrap'>
<Text>{record.bom_item_detail?.quantity}</Text>
<Text>
{formatDecimal(bomUnitQuantity(record.bom_item_detail))}
</Text>
{record?.part_detail?.units && (
<Text size='xs'>[{record.part_detail.units}]</Text>
)}
@@ -581,7 +591,7 @@ export default function BuildLineTable({
if (output?.pk) {
// If an output is specified, we show the allocated quantity for that output
required = record.bom_item_detail?.quantity;
required = bomUnitQuantity(record.bom_item_detail);
}
if (allocated <= 0 && required <= 0) {
@@ -73,7 +73,7 @@ import {
import useStatusCodes from '../../hooks/UseStatusCodes';
import { useStockAdjustActions } from '../../hooks/UseStockAdjustActions';
import { useUserState } from '../../states/UserState';
import BuildLineTable from './BuildLineTable';
import BuildLineTable, { bomUnitQuantity } from './BuildLineTable';
type TestResultOverview = {
name: string;
@@ -309,10 +309,9 @@ export default function BuildOutputTable({
allocated += allocation.quantity;
});
if (
item.bom_item_detail?.quantity &&
allocated >= item.bom_item_detail.quantity
) {
const required = bomUnitQuantity(item.bom_item_detail);
if (required && allocated >= required) {
fullyAllocatedCount += 1;
}
});