mirror of
https://github.com/inventree/demo-dataset.git
synced 2025-04-27 04:56:50 +00:00
Remove old scripts (#85)
This commit is contained in:
parent
b545c12e5a
commit
6c1149ff0b
@ -1,67 +0,0 @@
|
||||
from inventree.api import InvenTreeAPI
|
||||
|
||||
from inventree.part import Part, PartCategory
|
||||
from inventree.stock import StockItem, StockLocation
|
||||
from inventree.company import SupplierPart
|
||||
|
||||
import random
|
||||
import sys
|
||||
|
||||
INVENTREE_URL = "http://localhost:8000"
|
||||
INVENTREE_USERNAME = "admin"
|
||||
INVENTREE_PASSWORD = "inventree"
|
||||
|
||||
api = InvenTreeAPI(INVENTREE_URL, username=INVENTREE_USERNAME, password=INVENTREE_PASSWORD)
|
||||
|
||||
capacitors = Part.list(api, category=6)
|
||||
|
||||
storage = StockLocation(api, pk=8)
|
||||
|
||||
count = 0
|
||||
|
||||
for cap in capacitors:
|
||||
|
||||
if random.random() > 0.65:
|
||||
continue
|
||||
|
||||
# Get the first matching supplierpart
|
||||
sp_list = SupplierPart.list(api, part=cap.pk)
|
||||
|
||||
for sp in sp_list:
|
||||
if random.random() > 0.6:
|
||||
continue
|
||||
|
||||
status = 10
|
||||
|
||||
q = random.random()
|
||||
|
||||
quantity = 1000
|
||||
|
||||
if q < 0.1:
|
||||
quantity = 500
|
||||
|
||||
elif q > 0.85:
|
||||
quantity = 4000
|
||||
|
||||
if random.random() < 0.2:
|
||||
quantity += int(random.random() * 2000)
|
||||
|
||||
if random.random() > 0.95:
|
||||
status = 55 # Damaged
|
||||
elif random.random() > 0.95:
|
||||
status = 50 # Attention
|
||||
|
||||
StockItem.create(api, data={
|
||||
'location': storage.pk,
|
||||
'part': cap.pk,
|
||||
'quantity': quantity,
|
||||
'supplier_part': sp.pk,
|
||||
'packaging': 'reel',
|
||||
'status': status,
|
||||
})
|
||||
|
||||
count += 1
|
||||
|
||||
print(f"Created {count} new stock items")
|
||||
|
||||
|
@ -1,43 +0,0 @@
|
||||
from inventree.api import InvenTreeAPI
|
||||
|
||||
from inventree.part import Part, PartCategory
|
||||
from inventree.stock import StockItem, StockLocation
|
||||
from inventree.company import SupplierPart
|
||||
|
||||
import random
|
||||
import sys
|
||||
|
||||
INVENTREE_URL = "http://localhost:8000"
|
||||
INVENTREE_USERNAME = "admin"
|
||||
INVENTREE_PASSWORD = "inventree"
|
||||
|
||||
api = InvenTreeAPI(INVENTREE_URL, username=INVENTREE_USERNAME, password=INVENTREE_PASSWORD)
|
||||
|
||||
category = 6
|
||||
|
||||
packages = [
|
||||
'0402',
|
||||
'0603',
|
||||
'0805',
|
||||
]
|
||||
|
||||
values = [
|
||||
# '100pF',
|
||||
'100nF',
|
||||
'1uF',
|
||||
'10uF',
|
||||
]
|
||||
|
||||
for package in packages:
|
||||
for value in values:
|
||||
name = f"C_{value}_{package}"
|
||||
description = f"{value} in {package} SMD package"
|
||||
keywords = "cap smd ceramic"
|
||||
|
||||
Part.create(api, data={
|
||||
'name': name,
|
||||
'category': category,
|
||||
'description': description,
|
||||
'keywords': keywords,
|
||||
'purchaseable': True,
|
||||
})
|
@ -1,64 +0,0 @@
|
||||
from inventree.api import InvenTreeAPI
|
||||
|
||||
from inventree.part import Part, PartCategory
|
||||
from inventree.stock import StockItem, StockLocation
|
||||
from inventree.company import SupplierPart
|
||||
|
||||
import random
|
||||
import sys
|
||||
|
||||
INVENTREE_URL = "http://localhost:8000"
|
||||
INVENTREE_USERNAME = "admin"
|
||||
INVENTREE_PASSWORD = "inventree"
|
||||
|
||||
api = InvenTreeAPI(INVENTREE_URL, username=INVENTREE_USERNAME, password=INVENTREE_PASSWORD)
|
||||
|
||||
resistors = Part.list(api, category=5)
|
||||
|
||||
storage = StockLocation(api, pk=8)
|
||||
|
||||
count = 0
|
||||
|
||||
for resistor in resistors:
|
||||
|
||||
if random.random() > 0.65:
|
||||
continue
|
||||
|
||||
q = random.random()
|
||||
|
||||
quantity = 1000
|
||||
|
||||
if q < 0.1:
|
||||
quantity = 2000
|
||||
|
||||
elif q > 0.85:
|
||||
quantity = 4000
|
||||
|
||||
# Get the first matching supplierpart
|
||||
sp_list = SupplierPart.list(api, part=resistor.pk)
|
||||
|
||||
for sp in sp_list:
|
||||
if random.random() > 0.6:
|
||||
continue
|
||||
|
||||
status = 10
|
||||
|
||||
if random.random() > 0.95:
|
||||
status = 55 # Damaged
|
||||
elif random.random() > 0.95:
|
||||
status = 50 # Attention
|
||||
|
||||
StockItem.create(api, data={
|
||||
'location': storage.pk,
|
||||
'part': resistor.pk,
|
||||
'quantity': quantity,
|
||||
'supplier_part': sp.pk,
|
||||
'packaging': 'reel',
|
||||
'status': status,
|
||||
})
|
||||
|
||||
count += 1
|
||||
|
||||
print(f"Created {count} new stock items")
|
||||
|
||||
|
@ -1,97 +0,0 @@
|
||||
|
||||
from random import randint
|
||||
|
||||
from inventree.api import InvenTreeAPI
|
||||
|
||||
from inventree.part import Part, Parameter, ParameterTemplate
|
||||
from inventree.stock import StockItem
|
||||
|
||||
api = InvenTreeAPI("http://localhost:8000", username="admin", password="inventree")
|
||||
|
||||
# Pin headers category
|
||||
cat_id = 21
|
||||
|
||||
# Storage location
|
||||
loc_id = 10
|
||||
|
||||
rows = [1, 2]
|
||||
pitch = [1.27, 2.0, 2.54]
|
||||
ways = range(2, 11)
|
||||
|
||||
# Parameter templates
|
||||
templates = {}
|
||||
|
||||
for tmp in ParameterTemplate.list(api):
|
||||
templates[tmp.name] = tmp.pk
|
||||
|
||||
for r in rows:
|
||||
for p in pitch:
|
||||
for w in ways:
|
||||
|
||||
n = r * w
|
||||
|
||||
name = f"PinHeader_{r}x{w:02d}x{p}mm"
|
||||
description = f"Male pin header connector, {r} rows, {n} positions, {p}mm pitch, vertical"
|
||||
keywords = "pin header connector"
|
||||
|
||||
# Check if this part already exists
|
||||
results = Part.list(api, search=name)
|
||||
|
||||
if len(results) > 0:
|
||||
part = results[0]
|
||||
else:
|
||||
part = Part.create(
|
||||
api,
|
||||
{
|
||||
'name': name,
|
||||
'description': description,
|
||||
'keywords': keywords,
|
||||
'category': cat_id,
|
||||
'purchaseable': True,
|
||||
'component': True,
|
||||
}
|
||||
)
|
||||
|
||||
# Create stock item for this item
|
||||
items = StockItem.list(api, part=part.pk)
|
||||
|
||||
if len(items) == 0:
|
||||
q = randint(0, 25)
|
||||
|
||||
if q > 0:
|
||||
StockItem.create(
|
||||
api,
|
||||
{
|
||||
'part': part.pk,
|
||||
'quantity': q,
|
||||
'location': loc_id,
|
||||
}
|
||||
)
|
||||
|
||||
# Generate parameters for each item
|
||||
Parameter.create(
|
||||
api,
|
||||
{
|
||||
'part': part.pk,
|
||||
'template': templates['Pitch'],
|
||||
'data': p
|
||||
}
|
||||
)
|
||||
|
||||
Parameter.create(
|
||||
api,
|
||||
{
|
||||
'part': part.pk,
|
||||
'template': templates['Positions'],
|
||||
'data': n
|
||||
}
|
||||
)
|
||||
|
||||
Parameter.create(
|
||||
api,
|
||||
{
|
||||
'part': part.pk,
|
||||
'template': templates['Rows'],
|
||||
'data': r
|
||||
}
|
||||
)
|
@ -1,131 +0,0 @@
|
||||
from inventree.api import InvenTreeAPI
|
||||
from inventree.part import Part, PartCategory
|
||||
from inventree.base import Parameter
|
||||
from inventree.company import Company, ManufacturerPart, SupplierPart, ManufacturerPartParameter
|
||||
|
||||
import os
|
||||
import sys
|
||||
import digikey
|
||||
from digikey.v3.productinformation import KeywordSearchRequest
|
||||
|
||||
os.environ['DIGIKEY_CLIENT_ID'] = 'DjV4w1v0ebNTiL7Nqvslw0GkNYuYdrLG'
|
||||
os.environ['DIGIKEY_CLIENT_SECRET'] = 'dK0dTRimeq3aiPH1'
|
||||
os.environ['DIGIKEY_CLIENT_SANDBOX'] = 'False'
|
||||
os.environ['DIGIKEY_STORAGE_PATH'] = 'C:\\Users\\Oliver\\Desktop\\digikey\\'
|
||||
|
||||
INVENTREE_URL = "http://localhost:8000"
|
||||
INVENTREE_USERNAME = "admin"
|
||||
INVENTREE_PASSWORD = "inventree"
|
||||
|
||||
inventree = InvenTreeAPI(INVENTREE_URL, username=INVENTREE_USERNAME, password=INVENTREE_PASSWORD)
|
||||
|
||||
resistors = Part.list(inventree, category=5)
|
||||
|
||||
def getParameter(result, name):
|
||||
|
||||
for param in result.parameters:
|
||||
if param.parameter.lower() == name.lower():
|
||||
return param
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def getValue(result, name):
|
||||
|
||||
param = getParameter(result, name)
|
||||
|
||||
if param:
|
||||
return param.value
|
||||
else:
|
||||
return None
|
||||
|
||||
manufacturers = {}
|
||||
|
||||
DIGIKEY_PK = 1
|
||||
|
||||
for res in resistors:
|
||||
|
||||
search_term = res.name.replace('_', ' ').replace('R ' , 'Resistor ')
|
||||
|
||||
print(res.name, res.description)
|
||||
|
||||
request = KeywordSearchRequest(search_term, record_count=25)
|
||||
|
||||
result = digikey.keyword_search(body=request)
|
||||
|
||||
# Set of manufacturer part numbers
|
||||
MPN = set()
|
||||
|
||||
for product in result.products:
|
||||
|
||||
mpn = product.manufacturer_part_number
|
||||
|
||||
print(f"> {mpn}")
|
||||
|
||||
if mpn in MPN or len(MPN) >= 5:
|
||||
continue
|
||||
|
||||
MPN.add(mpn)
|
||||
|
||||
sku = product.digi_key_part_number
|
||||
|
||||
man_name = product.manufacturer.value
|
||||
|
||||
if man_name in manufacturers.keys():
|
||||
manufacturer = manufacturers[man_name]
|
||||
else:
|
||||
|
||||
# Search InvenTree for manufacturer name
|
||||
query = Company.list(inventree, search=man_name)
|
||||
|
||||
if len(query) == 0:
|
||||
|
||||
print(f"Creating new manufacturer: '{man_name}'")
|
||||
|
||||
manufacturer = Company.create(inventree, data={
|
||||
'is_supplier': False,
|
||||
'is_manufacturer': True,
|
||||
'name': man_name,
|
||||
})
|
||||
|
||||
else:
|
||||
manufacturer = query[0]
|
||||
|
||||
manufacturers[man_name] = manufacturer
|
||||
|
||||
m_parts = ManufacturerPart.list(inventree, MPN=mpn)
|
||||
|
||||
print("Existing Manufacturer Parts:")
|
||||
|
||||
for mp in m_parts:
|
||||
print(f" - {mp.MPN}, {mp.manufacturer}")
|
||||
|
||||
if len(m_parts) == 0:
|
||||
print(f"Creating new part: {man_name} -> {mpn}")
|
||||
manufacturer_part = ManufacturerPart.create(inventree, data={
|
||||
'part': res.pk,
|
||||
'manufacturer': manufacturer.pk,
|
||||
'MPN': mpn,
|
||||
})
|
||||
else:
|
||||
manufacturer_part = m_parts[0]
|
||||
|
||||
# Check if a "supplier part" exists
|
||||
s_parts = SupplierPart.list(
|
||||
inventree,
|
||||
manufacturer_part=manufacturer_part.pk,
|
||||
supplier=DIGIKEY_PK
|
||||
)
|
||||
|
||||
if s_parts is None or len(s_parts) == 0:
|
||||
print(f"Creating new supplier part")
|
||||
|
||||
SupplierPart.create(inventree, data={
|
||||
'part': res.pk,
|
||||
'supplier': DIGIKEY_PK,
|
||||
'manufacturer_part': manufacturer_part.pk,
|
||||
'SKU': sku,
|
||||
'link': product.product_url,
|
||||
'description': product.product_description,
|
||||
})
|
||||
|
@ -1,46 +0,0 @@
|
||||
"""
|
||||
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()
|
@ -1,127 +0,0 @@
|
||||
"""
|
||||
This script adds new supplier data and supplier pricing for the demo dataset.
|
||||
|
||||
The supplier part numbers here are not real, neither is the pricing.
|
||||
None of this data should be used for anything in the realm of sensible decision making.
|
||||
"""
|
||||
|
||||
import random
|
||||
import string
|
||||
|
||||
from progress.bar import Bar
|
||||
|
||||
from inventree.api import InvenTreeAPI
|
||||
|
||||
from inventree.company import Company, SupplierPart, SupplierPriceBreak
|
||||
from inventree.part import Part
|
||||
|
||||
api = InvenTreeAPI("http://localhost:8000", username="admin", password="inventree")
|
||||
|
||||
# ID for the "passives" category
|
||||
passives_category_id = 4
|
||||
|
||||
# List of electronics suppliers we wish to create supplier parts for
|
||||
supplier_ids = [
|
||||
1, # DigiKey
|
||||
2, # Mouser
|
||||
3, # Arrow
|
||||
39, # LCSC
|
||||
40, # Newark
|
||||
41, # Future Electronics
|
||||
]
|
||||
|
||||
# Special currency (default = USD)
|
||||
currencies = {
|
||||
2: 'AUD', # Mouser
|
||||
39: 'CNY', # LCSC
|
||||
41: 'CAD', # Future
|
||||
}
|
||||
|
||||
parts = Part.list(api, category=passives_category_id, cascade=True)
|
||||
|
||||
bar = Bar('Creating Supplier Part Data', max=len(parts))
|
||||
|
||||
for part in parts:
|
||||
|
||||
bar.next()
|
||||
|
||||
# Create at least one supplier part for each supplier
|
||||
for supplier_id in supplier_ids:
|
||||
supplier_parts = SupplierPart.list(
|
||||
api,
|
||||
part=part.pk,
|
||||
supplier=supplier_id,
|
||||
)
|
||||
|
||||
# Supplier part already exists for this supplier
|
||||
if len(supplier_parts) > 0:
|
||||
continue
|
||||
|
||||
supplier = Company(api, pk=supplier_id)
|
||||
|
||||
# Create a new supplier part for this supplier
|
||||
SKU = supplier.name.upper()[0:3]
|
||||
|
||||
SKU += "-" + "".join(random.choice(string.digits) for _ in range(5))
|
||||
SKU += "-"
|
||||
SKU += "".join(random.choice(string.ascii_uppercase) for _ in range(3))
|
||||
|
||||
# Create a new supplier part based on randomly generated SKU
|
||||
SupplierPart.create(
|
||||
api,
|
||||
{
|
||||
"part": part.pk,
|
||||
"supplier": supplier.pk,
|
||||
"SKU": SKU,
|
||||
}
|
||||
)
|
||||
|
||||
# Now, ensure that each SupplierPart has some associated price break information
|
||||
supplier_parts = SupplierPart.list(api, part=part.pk)
|
||||
|
||||
for sp in supplier_parts:
|
||||
price_breaks = SupplierPriceBreak.list(api, part=sp.pk)
|
||||
|
||||
# Skip for any supplier pars which already have price-break information
|
||||
if len(price_breaks) > 0:
|
||||
continue
|
||||
|
||||
currency = currencies.get(sp.supplier, 'USD')
|
||||
|
||||
# Start with the highest price break for 1000x
|
||||
pb_1000 = 0.0025 + random.random() * 0.025
|
||||
pb_100 = pb_1000 * (10 + random.random() * 1.25)
|
||||
pb_1 = pb_100 * (10 + random.random() * 2.5)
|
||||
|
||||
SupplierPriceBreak.create(
|
||||
api,
|
||||
{
|
||||
"part": sp.pk,
|
||||
"quantity": 1,
|
||||
"price": round(pb_1, 4),
|
||||
"price_currency": currency
|
||||
}
|
||||
)
|
||||
|
||||
SupplierPriceBreak.create(
|
||||
api,
|
||||
{
|
||||
"part": sp.pk,
|
||||
"quantity": 100,
|
||||
"price": round(pb_100, 4),
|
||||
"price_currency": currency
|
||||
}
|
||||
)
|
||||
|
||||
SupplierPriceBreak.create(
|
||||
api,
|
||||
{
|
||||
"part": sp.pk,
|
||||
"quantity": 1000,
|
||||
"price": round(pb_1000, 4),
|
||||
"price_currency": currency
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
bar.finish()
|
@ -1,74 +0,0 @@
|
||||
"""
|
||||
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()
|
Loading…
x
Reference in New Issue
Block a user