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 <oliver.henry.walters@gmail.com>
This commit is contained in:
Michael 2024-02-14 07:28:13 +01:00 committed by GitHub
parent 3637b28da7
commit d86f964fb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.