2
0
mirror of https://github.com/inventree/demo-dataset.git synced 2025-04-27 21:16:50 +00:00

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
This commit is contained in:
Oliver 2022-07-15 17:43:10 +10:00 committed by GitHub
parent ac9b7ae603
commit 1344c1458a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 16351 additions and 648 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View 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()

View 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()