Exemplo n.º 1
0
def find_part_location(part_number):
    """
    find part location in database
    :param part_number: part number to find
    :return: location of the part
    """
    try:
        api = InvenTreeAPI(SERVER_ADDRESS, token=My_TOKEN, verbose=True)
        parts = Part.list(api, search=part_number)
        # print(len(parts))

        if len(parts) == 1:
            my_part = parts[0].pk
        elif len(parts) > 1:
            for part in parts:
                my_part = part.pk  # get internal part number
                part_count = part._data['in_stock']  # total qty in stock

        part = Part(api, my_part)
        stock_items = part.getStockItems()
        if stock_items:
            if stock_items[0]._data['location']:
                stock_location = stock_items[0]._data['location']
                location = inventree.stock.StockLocation(api,
                                                         pk=stock_location)
                my_location = location._data['name']
            else:
                my_location = 'No Location'
        # print(my_location)
        return my_location
    except:
        print(api)
        print('Can not connect to the database')
def test_server(address, **kwargs):
    """
    Perform basic server checks.
    """

    if kwargs.get('debug', False):
        # Print all debug messages
        logging.basicConfig(level=logging.INFO)

    api = InvenTreeAPI(address, **kwargs)

    assert api.server_details is not None
    assert api.token is not None

    print("Server Details:", api.server_details)
    print("Token:", api.token)

    print("All checks passed OK...")
Exemplo n.º 3
0
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 = "******"
INVENTREE_PASSWORD = "******"

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):
Exemplo n.º 4
0
 def get_inventree_api_timeout():
     return InvenTreeAPI(server, username=username, password=password)
Exemplo n.º 5
0
import partkeepr
from inventree.api import InvenTreeAPI
from inventree.part import PartCategory,Part
from inventree.stock import StockItem, StockLocation

SERVER_ADDRESS = 'http://127.0.0.1:8000'
MY_USERNAME = '******'
MY_PASSWORD = '******'

api = InvenTreeAPI(SERVER_ADDRESS, username=MY_USERNAME, password=MY_PASSWORD)

#delete all the exisiting parts

itparts = Part.list(api)
for p in itparts:
    print("delete p ",p.name)
    p._data['active'] = False
    p.save()
    p.delete()

#delete all of the exisitng categories

cat = PartCategory.list(api)


for c in cat:
    print("delete c ",c.name)
    c.delete()


from inventree.part import Part, PartCategory
from inventree.base import Parameter, ParameterTemplate
from pathlib import Path

from .Digikey import DigiPart
from .ImageManager import ImageManager

config = configparser.ConfigParser()
config_path = Path(__file__).resolve().parent / "config.ini"
config.read(config_path)

API_URL = config['INVENTREE_API']['URL']
USERNAME = config['INVENTREE_API']['USER']
PASSWORD = config['INVENTREE_API']['PASSWORD']

API = InvenTreeAPI(API_URL, username=USERNAME, password=PASSWORD)


def add_digikey_part(dkpart: DigiPart):
    dk = get_digikey_supplier()
    inv_part = create_inventree_part(dkpart)
    if inv_part == -1:
        return
    base_pk = int(inv_part.pk)
    mfg = find_manufacturer(dkpart)

    ManufacturerPart.create(API, {
        'part': base_pk,
        'supplier': dk.pk,
        'MPN': dkpart.mfg_part_num,
        'manufacturer': mfg.pk