Supplier Mixin
SupplierMixin¶
The SupplierMixin class enables plugins to integrate with external suppliers, enabling seamless creation of parts, supplier parts, and manufacturer parts with just a few clicks from the supplier. The import process is split into multiple phases:
- Search supplier
- Select InvenTree category
- Match Part Parameters
- Create initial Stock
Import Methods¶
A plugin can connect to multiple suppliers. The get_suppliers method should return a list of available supplier connections (e.g. using different credentials).
When a user initiates a search through the UI, the get_search_results function is called with the search term, supplier slug returned previously, and the search results are returned. These contain a part_id which is then passed to get_import_data along with the supplier_slug, if a user decides to import that specific part. This function should return a bunch of data that is needed for the import process. This data may be cached in the future for the same part_id. Then depending if the user only wants to import the supplier and manufacturer part or the whole part, the import_part, import_manufacturer_part and import_supplier_part methods are called automatically. If the user has imported the complete part, the get_parameters method is used to get a list of parameters which then can be match to inventree part parameter templates with some provided guidance. Additionally the get_pricing_data method is used to extract price breaks which are automatically considered when creating initial stock through the UI in the part import wizard.
For that to work, a few methods need to be overridden:
Mixin which provides integration to specific suppliers.
Source code in src/backend/InvenTree/plugin/base/supplier/mixins.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
get_search_results(supplier_slug, term)
¶
Return a list of search results for the given search term.
Source code in src/backend/InvenTree/plugin/base/supplier/mixins.py
55 56 57 58 59 | |
get_import_data(supplier_slug, part_id)
¶
Return the import data for the given part ID.
Source code in src/backend/InvenTree/plugin/base/supplier/mixins.py
61 62 63 | |
get_pricing_data(data)
¶
Return a dictionary of pricing data for the given part data.
Source code in src/backend/InvenTree/plugin/base/supplier/mixins.py
65 66 67 | |
get_parameters(data)
¶
Return a list of parameters for the given part data.
Source code in src/backend/InvenTree/plugin/base/supplier/mixins.py
69 70 71 | |
import_part(data, *, category, creation_user)
¶
Import a part using the provided data.
This may include
- Creating a new part
- Add an image to the part
- if this part has several variants, (create) a template part and assign it to the part
- create related parts
- add attachments to the part
Source code in src/backend/InvenTree/plugin/base/supplier/mixins.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
import_manufacturer_part(data, *, part)
¶
Import a manufacturer part using the provided data.
This may include
- Creating a new manufacturer
- Creating a new manufacturer part
- Assigning the part to the manufacturer part
- Setting the default supplier for the part
- Adding parameters to the manufacturer part
- Adding attachments to the manufacturer part
Source code in src/backend/InvenTree/plugin/base/supplier/mixins.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
import_supplier_part(data, *, part, manufacturer_part)
¶
Import a supplier part using the provided data.
This may include
- Creating a new supplier part
- Creating supplier price breaks
Source code in src/backend/InvenTree/plugin/base/supplier/mixins.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
Sample Plugin¶
A simple example is provided in the InvenTree code base. Note that this uses some static data, but this can be extended in a real world plugin to e.g. call the supplier's API:
Example plugin to integrate with a dummy supplier.
Source code in src/backend/InvenTree/plugin/samples/supplier/supplier_sample.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |