Supplier part stock (#29)
* Add script for generating stock items with purchase price data * Generate preview images * Add more stock items with purchase price information * Script for updating supplier "availability" data * Add supplier availability data for some parts
16879
inventree_data.json
BIN
media/part_images/10x1.preview.webp
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
media/part_images/2x1.preview.webp
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
media/part_images/2x2.preview.webp
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
media/part_images/3x1.preview.webp
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
media/part_images/3x2.preview.webp
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
media/part_images/4x1.preview.webp
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
media/part_images/4x2.preview.webp
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
media/part_images/5x1.preview.webp
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
media/part_images/5x2.preview.webp
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
media/part_images/6x1.preview.webp
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
media/part_images/6x2.preview.webp
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
media/part_images/7x1.preview.webp
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
media/part_images/7x2.preview.webp
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
media/part_images/8x1.preview.webp
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
media/part_images/9x1.preview.webp
Normal file
After Width: | Height: | Size: 4.3 KiB |
46
scripts/supplier_part_availability.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
"""
|
||||||
|
This script adds supplier availability data to some SupplierPart objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
from random import randint
|
||||||
|
from matplotlib.style import available
|
||||||
|
|
||||||
|
from progress.bar import Bar
|
||||||
|
|
||||||
|
from inventree.api import InvenTreeAPI
|
||||||
|
|
||||||
|
from inventree.company import SupplierPart
|
||||||
|
from inventree.part import Part
|
||||||
|
from inventree.stock import StockItem
|
||||||
|
from scipy import rand
|
||||||
|
|
||||||
|
api = InvenTreeAPI("http://localhost:8000", username="admin", password="inventree")
|
||||||
|
|
||||||
|
# ID for the "passives" category
|
||||||
|
passives_category_id = 4
|
||||||
|
|
||||||
|
parts = Part.list(api, category=passives_category_id, cascade=True)
|
||||||
|
|
||||||
|
bar = Bar('Updating Supplier Availability', max=len(parts))
|
||||||
|
|
||||||
|
for part in parts:
|
||||||
|
|
||||||
|
supplier_parts = SupplierPart.list(api, part=part.pk)
|
||||||
|
|
||||||
|
for sp in supplier_parts:
|
||||||
|
|
||||||
|
# Do not update every SupplierPart instance
|
||||||
|
if randint(0, 10) > 3:
|
||||||
|
continue
|
||||||
|
|
||||||
|
available = randint(500, 50000)
|
||||||
|
|
||||||
|
sp.save(
|
||||||
|
data={
|
||||||
|
'available': available
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
bar.next()
|
||||||
|
|
||||||
|
bar.finish()
|
74
scripts/supplier_part_stock.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
"""
|
||||||
|
This script finds stock items which are not associated with a SupplierPart, and:
|
||||||
|
|
||||||
|
- Adds a SupplierPart Reference
|
||||||
|
- Adds a PurchasePrice reference
|
||||||
|
"""
|
||||||
|
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
from progress.bar import Bar
|
||||||
|
|
||||||
|
from inventree.api import InvenTreeAPI
|
||||||
|
|
||||||
|
from inventree.company import SupplierPart, SupplierPriceBreak
|
||||||
|
from inventree.part import Part
|
||||||
|
from inventree.stock import StockItem
|
||||||
|
|
||||||
|
api = InvenTreeAPI("http://localhost:8000", username="admin", password="inventree")
|
||||||
|
|
||||||
|
# ID for the "passives" category
|
||||||
|
passives_category_id = 4
|
||||||
|
|
||||||
|
location = 11
|
||||||
|
|
||||||
|
parts = Part.list(api, category=passives_category_id, cascade=True)
|
||||||
|
|
||||||
|
bar = Bar('Updating Stock Records', max=len(parts))
|
||||||
|
|
||||||
|
for part in parts:
|
||||||
|
|
||||||
|
supplier_parts = SupplierPart.list(api, part=part.pk)
|
||||||
|
|
||||||
|
for sp in supplier_parts:
|
||||||
|
|
||||||
|
# Find any supplier parts without stock
|
||||||
|
stock_items = StockItem.list(api, part=part.pk, supplier_part=sp.pk)
|
||||||
|
|
||||||
|
# Ignore if there are existing stock items
|
||||||
|
if len(stock_items) > 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
quantity = randint(0, 100)
|
||||||
|
|
||||||
|
if quantity <= 25:
|
||||||
|
continue
|
||||||
|
|
||||||
|
price_breaks = SupplierPriceBreak.list(api, part=sp.pk)
|
||||||
|
|
||||||
|
pp = None
|
||||||
|
ppc = None
|
||||||
|
|
||||||
|
|
||||||
|
for pb in price_breaks:
|
||||||
|
if pb.quantity == 1:
|
||||||
|
pp = pb.price
|
||||||
|
ppc = pb.price_currency
|
||||||
|
|
||||||
|
# Create a new StockItem
|
||||||
|
StockItem.create(
|
||||||
|
api,
|
||||||
|
{
|
||||||
|
'part': part.pk,
|
||||||
|
'supplier_part': sp.pk,
|
||||||
|
'quantity': quantity,
|
||||||
|
'location': location,
|
||||||
|
'packaging': 'cut tape',
|
||||||
|
'purchase_price': pp,
|
||||||
|
'purchase_price_currency': ppc,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
bar.next()
|
||||||
|
|
||||||
|
bar.finish()
|