From d86f964fb18cfae5e476f1096b578482dbe392cf Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Feb 2024 07:28:13 +0100 Subject: [PATCH] Add BOM creation to the sofa example (#6477) * Add BOM creation to ther sofa example * Fixed typo * Update examples.md Cleanup wording a bit --------- Co-authored-by: Oliver --- docs/docs/api/python/examples.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/docs/api/python/examples.md b/docs/docs/api/python/examples.md index 7901abb2a0..52e3de2ea4 100644 --- a/docs/docs/api/python/examples.md +++ b/docs/docs/api/python/examples.md @@ -234,3 +234,23 @@ part = Part(api, pk=47) part.uploadAttachment('data.txt', comment='A data file') ``` + +### Adding a Bill of Materials + +Imagine your sofa is made from three parts: one seat, one back and two arm rests. To enable this +the assembly flag of the sofa part has to be set. You need to have all three parts in you InvenTree +database. + +A BOM (Bill of Materials) contains BOM items. These are separate records in the database that refer to the master assembly (the *part*) +and the component which is being used (the *sub_part*). + +BOM Items can be created using the Python API interface as follows: + +```python +BomItem.create(api, data={'part':sofa_id, 'sub_part':back_id, 'quantity':1, 'reference':'p1'}) +BomItem.create(api, data={'part':sofa_id, 'sub_part':seat_id, 'quantity':1, 'reference':'p2'}) +BomItem.create(api, data={'part':sofa_id, 'sub_part':armrest_id, 'quantity':2, 'reference':'p3, p4'}) +``` + +Now you have three BOM items that make the BOM for the sofa. The `id` values are the primary keys of the +specified parts. The reference can be any string that names the instances.