2
0
mirror of https://github.com/inventree/inventree-docs.git synced 2025-04-28 05:36:46 +00:00

Merge pull request #239 from SergeoLacruz/master

Added description for parameter upload
This commit is contained in:
Oliver 2022-01-28 08:31:00 +11:00 committed by GitHub
commit 0c0ac0d135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,11 +88,9 @@ stock_item.uploadTestResult("Firmware", True, value="0x12345678", attachment="de
```python
from inventree.part import Part, PartCategory
from inventree.stock import StockItem
from inventree.base import Parameter
from inventree.base import ParameterTemplate
## Create a new PartCategory object,
## underneath the existing category with pk 7
## underneath the existing category with pk 7. Leave the parent empty fpr a top level category
furniture = PartCategory.create(api, {
'name': 'Furniture',
'description': 'Chairs, tables, etc',
@ -109,20 +107,27 @@ couch = Part.create(api, {
'virtual': False,
## Note - You do not have to fill out *all* fields
})
```
#### Adding parameters to the sofa
Each part can have multiple parameters like resistance, voltage or capacitance. For the sofa length and weight make sense. Each parameter has a parameter template that combines the parameter name with a unit. So we first have to create the parameter templates and afterwards add the parameter values to the sofa.
```python
from inventree.base import Parameter
from inventree.base import ParameterTemplate
## Before we can add parameters to the couch, we neeed to create the parameter templates
## These parameter templates need to be defined only once and can be used for all other parts.
LengthTemplate = ParameterTemplate.create(api, { 'name' : 'Length', 'units' : 'Meters' })
WeightTemplate = ParameterTemplate.create(api, { 'name' : 'Weight', 'units' : 'kg' })
## Now we create the parameters
ParameterLength = Parameter.create(api, { 'part': couch.pk, 'template': LengthTemplate.pk, 'data' : 2 })
ParameterWeight = Parameter.create(api, { 'part': couch.pk, 'template': WeightTemplate.pk, 'data' : 60 })
```
These parameter templates need to be defined only once and can be used for all other parts. Lets finally add a picture.
## Add a picture to the part
```python
couch.upload_image('my_nice_couch.jpg')
```
#### Adding a location to the sofa
If we have several sofas on stock we need to know there we have stored them. So lets add stock locations to the part. Stock locations can be organized in a hierarchical manner e.g. boxes in shelves in aisles in rooms. So each location can have a parent. Lets assume we have 10 sofas in box 12 and 3 sofas in box 13 located in shelve 43 aisle 3. First we have to create the locations, afterwards we can put the sofas inside.
@ -198,3 +203,14 @@ SupplierPart.create(api,{
```
Supplier and manufacturer are added with just one command. The SKU is the code under which the couch is listed in the store.
#### Add a datasheet or other documents
We have the possibility to add documents to the part. We can use pdf for documents but also other files like 3D drawings or pictures. To do so we add the following commands:
```python
from inventree.part import PartAttachment
PartAttachment.upload_attachment(api, pk, **{'comment':'Datasheet', 'attachment':'manual.pdf'} )
PartAttachment.upload_attachment(api, pk, **{'comment':'Drawing', 'attachment':'sofa.dxf'} )
```
Here pk is the primary key of the part where the attachment will be added, comment is a name of the attachment that can be freely chosen and attachment is a file that must exist.