feat: add piece_count and piece_size fields to BomItem for cut-to-length parts - #12422
feat: add piece_count and piece_size fields to BomItem for cut-to-length parts#12422amanjain57-gif wants to merge 3 commits into
Conversation
…gth parts Manufacturing BOMs frequently require multiple pieces of a specific size cut from continuous stock (cables, tubing, structural profiles). Currently the only way to express "10 pieces of 250mm cable" is to enter the total length (2.5m) as quantity, which loses the piece-count information that purchasing and production need. This adds two optional fields to BomItem: - piece_count: number of discrete pieces required (default: 1) - piece_size: size/length of each piece (e.g. "250 mm") When piece_size is specified, the total quantity is auto-calculated as piece_count × piece_size, maintaining full backward compatibility (existing items effectively have piece_count=1 and empty piece_size). Changes: - Backend: new model fields, migration, updated recalculate_quantity() logic, hash_fields for BOM validation - API: serializer exposes piece_count and piece_size - Frontend: BOM form includes the new fields, BOM table shows them as optional columns Addresses inventree#10274
✅ Deploy Preview for inventree-web-pui-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@amanjain57-gif an interesting idea here, thanks for submitting. I think that you can achieve this with a single additional field, not two. If you remove the "piece_size" field and just use quantity, then the additional "piece_count" field can be used to reflect multiple pieces. e.g. a BOM with multiple lengths of wire
Thus the total requirement is 2m of wire, but we can see it is in 10x pieces of 200mm |
SchrodingersGat
left a comment
There was a problem hiding this comment.
Reduce to a single additional field as discussed
Remove the piece_size field entirely. The existing quantity field already represents the per-piece size/length, so piece_count multiplied by quantity gives the total material requirement. Example: quantity=200mm, piece_count=10 → total 2m of wire in 10 pieces. Changes: - Remove piece_size model field, serializer field, and frontend column/form - Update migration to only add piece_count - Update get_required_quantity() to multiply by piece_count - Restore original recalculate_quantity() without piece_size logic
|
Thanks for the feedback! Simplified to a single |

Summary
Addresses #10274
Manufacturing BOMs frequently require multiple pieces of a specific size cut from continuous stock (cables, tubing,
structural profiles). Currently the only way to express "10 pieces of 250mm cable" is to enter the total length (2.5m)
as quantity, which loses the piece-count information that purchasing and production need.
Changes
Adds two optional fields to BomItem:
When
piece_sizeis specified, the total quantity is auto-calculated aspiece_count × piece_size, maintaining fullbackward compatibility (existing items effectively have piece_count=1 and empty piece_size).
Backend
recalculate_quantity()to compute total from piece_count × piece_size when piece_size is setAPI
piece_countandpiece_sizefieldsFrontend
Example
A BOM line for "10 pieces of 250mm aluminum profile" (part units: m):
This preserves the per-piece information for production while correctly computing total material requirement for
purchasing.