Changeset - 8c86d58fda4b
[Not reviewed]
default
0 3 0
Dennis Fink - 3 years ago 2022-03-03 17:55:27
dennis.fink@c3l.lu
Remove uneeded type annotations
3 files changed with 26 insertions and 32 deletions:
0 comments (0 inline, 0 general)
poetry.lock
Show inline comments
 
@@ -185,52 +185,60 @@ category = "dev"
 
optional = false
 
python-versions = ">=3.7"
 

	
 
[[package]]
 
name = "typing-extensions"
 
version = "4.0.1"
 
description = "Backported and Experimental Type Hints for Python 3.6+"
 
category = "dev"
 
optional = false
 
python-versions = ">=3.6"
 

	
 
[[package]]
 
name = "urllib3"
 
version = "1.26.8"
 
description = "HTTP library with thread-safe connection pooling, file post, and more."
 
category = "main"
 
optional = false
 
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
 

	
 
[package.extras]
 
brotli = ["brotlipy (>=0.6.0)"]
 
secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"]
 
socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
 

	
 
[[package]]
 
name = "vermin"
 
version = "1.3.3"
 
description = "Concurrently detect the minimum Python versions needed to run code"
 
category = "dev"
 
optional = false
 
python-versions = ">=2.7"
 

	
 
[metadata]
 
lock-version = "1.1"
 
python-versions = "^3.10"
 
content-hash = "14f945aef88b635fa5d4cc1f329572834551d8fb4fe0c7cbbbcfa419bbec84a7"
 
content-hash = "e73abda5748e52a1074f136fa035a8e427d57dd92ba4983c81141974a97dc25e"
 

	
 
[metadata.files]
 
black = [
 
    {file = "black-22.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:1297c63b9e1b96a3d0da2d85d11cd9bf8664251fd69ddac068b98dc4f34f73b6"},
 
    {file = "black-22.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2ff96450d3ad9ea499fc4c60e425a1439c2120cbbc1ab959ff20f7c76ec7e866"},
 
    {file = "black-22.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0e21e1f1efa65a50e3960edd068b6ae6d64ad6235bd8bfea116a03b21836af71"},
 
    {file = "black-22.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e2f69158a7d120fd641d1fa9a921d898e20d52e44a74a6fbbcc570a62a6bc8ab"},
 
    {file = "black-22.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:228b5ae2c8e3d6227e4bde5920d2fc66cc3400fde7bcc74f480cb07ef0b570d5"},
 
    {file = "black-22.1.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:b1a5ed73ab4c482208d20434f700d514f66ffe2840f63a6252ecc43a9bc77e8a"},
 
    {file = "black-22.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:35944b7100af4a985abfcaa860b06af15590deb1f392f06c8683b4381e8eeaf0"},
 
    {file = "black-22.1.0-cp36-cp36m-win_amd64.whl", hash = "sha256:7835fee5238fc0a0baf6c9268fb816b5f5cd9b8793423a75e8cd663c48d073ba"},
 
    {file = "black-22.1.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:dae63f2dbf82882fa3b2a3c49c32bffe144970a573cd68d247af6560fc493ae1"},
 
    {file = "black-22.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5fa1db02410b1924b6749c245ab38d30621564e658297484952f3d8a39fce7e8"},
 
    {file = "black-22.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:c8226f50b8c34a14608b848dc23a46e5d08397d009446353dad45e04af0c8e28"},
 
    {file = "black-22.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:2d6f331c02f0f40aa51a22e479c8209d37fcd520c77721c034517d44eecf5912"},
 
    {file = "black-22.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:742ce9af3086e5bd07e58c8feb09dbb2b047b7f566eb5f5bc63fd455814979f3"},
 
    {file = "black-22.1.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:fdb8754b453fb15fad3f72cd9cad3e16776f0964d67cf30ebcbf10327a3777a3"},
 
    {file = "black-22.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f5660feab44c2e3cb24b2419b998846cbb01c23c7fe645fee45087efa3da2d61"},
 
    {file = "black-22.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:6f2f01381f91c1efb1451998bd65a129b3ed6f64f79663a55fe0e9b74a5f81fd"},
 
    {file = "black-22.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:efbadd9b52c060a8fc3b9658744091cb33c31f830b3f074422ed27bad2b18e8f"},
 
    {file = "black-22.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:8871fcb4b447206904932b54b567923e5be802b9b19b744fdff092bd2f3118d0"},
 
    {file = "black-22.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ccad888050f5393f0d6029deea2a33e5ae371fd182a697313bdbd835d3edaf9c"},
 
    {file = "black-22.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:07e5c049442d7ca1a2fc273c79d1aecbbf1bc858f62e8184abe1ad175c4f7cc2"},
 
    {file = "black-22.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:373922fc66676133ddc3e754e4509196a8c392fec3f5ca4486673e685a421321"},
 
@@ -302,24 +310,27 @@ platformdirs = [
 
pygments = [
 
    {file = "Pygments-2.11.2-py3-none-any.whl", hash = "sha256:44238f1b60a76d78fc8ca0528ee429702aae011c265fe6a8dd8b63049ae41c65"},
 
    {file = "Pygments-2.11.2.tar.gz", hash = "sha256:4e426f72023d88d03b2fa258de560726ce890ff3b630f88c21cbb8b2503b8c6a"},
 
]
 
requests = [
 
    {file = "requests-2.27.1-py2.py3-none-any.whl", hash = "sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"},
 
    {file = "requests-2.27.1.tar.gz", hash = "sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61"},
 
]
 
rich = [
 
    {file = "rich-11.2.0-py3-none-any.whl", hash = "sha256:d5f49ad91fb343efcae45a2b2df04a9755e863e50413623ab8c9e74f05aee52b"},
 
    {file = "rich-11.2.0.tar.gz", hash = "sha256:1a6266a5738115017bb64a66c59c717e7aa047b3ae49a011ede4abdeffc6536e"},
 
]
 
tomli = [
 
    {file = "tomli-2.0.0-py3-none-any.whl", hash = "sha256:b5bde28da1fed24b9bd1d4d2b8cba62300bfb4ec9a6187a957e8ddb9434c5224"},
 
    {file = "tomli-2.0.0.tar.gz", hash = "sha256:c292c34f58502a1eb2bbb9f5bbc9a5ebc37bee10ffb8c2d6bbdfa8eb13cc14e1"},
 
]
 
typing-extensions = [
 
    {file = "typing_extensions-4.0.1-py3-none-any.whl", hash = "sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b"},
 
    {file = "typing_extensions-4.0.1.tar.gz", hash = "sha256:4ca091dea149f945ec56afb48dae714f21e8692ef22a395223bcd328961b6a0e"},
 
]
 
urllib3 = [
 
    {file = "urllib3-1.26.8-py2.py3-none-any.whl", hash = "sha256:000ca7f471a233c2251c6c7023ee85305721bfdf18621ebff4fd17a8653427ed"},
 
    {file = "urllib3-1.26.8.tar.gz", hash = "sha256:0e7c33d9a63e7ddfcb86780aac87befc2fbddf46c58dbb487e0855f7ceec283c"},
 
]
 
vermin = [
 
    {file = "vermin-1.3.3-py2.py3-none-any.whl", hash = "sha256:c5bd8bf2026d87563332293a0479606954bd973d8cf72ab370e1164a019c0524"},
 
]
pyproject.toml
Show inline comments
 
[tool.poetry]
 
name = "stockcli"
 
version = "0.0.1"
 
description = ""
 
authors = ["Dennis Fink <dennis.fink@c3l.lu>"]
 

	
 
[tool.poetry.dependencies]
 
python = "^3.10"
 
requests = "^2.27.1"
 
click = "^8.0.3"
 
rich = "^11.2.0"
 

	
 
[tool.poetry.dev-dependencies]
 
mypy = "^0.931"
 
black = "^22.1.0"
 
isort = "^5.10.1"
 
vermin = "^1.3.3"
 

	
 
[build-system]
 
requires = ["poetry-core>=1.0.0"]
 
build-backend = "poetry.core.masonry.api"
stockcli/stock.py
Show inline comments
 
import logging
 
from operator import itemgetter
 
from typing import Any
 
from typing import Any, Dict, List
 

	
 
from rich.panel import Panel
 
from rich.table import Table
 

	
 
from . import utils
 
from .console import DEFAULT_PADDING, console, int_prompt, prompt
 
from .style import GreenBoldText
 

	
 

	
 
def get_info_by_barcode(barcode: str) -> None:
 

	
 
    product = utils.get_request(
 
        f"stock/products/by-barcode/{barcode}"
 
    )  # type: dict[str, Any]
 
    product = utils.get_request(f"stock/products/by-barcode/{barcode}")
 

	
 
    inner_product = product["product"]
 
    product_id = inner_product["id"]
 

	
 
    product_group = utils.get_request(
 
        f"objects/product_groups/{inner_product['product_group_id']}"
 
    )  # type: dict[str, Any]
 
    )
 

	
 
    grid = Table.grid(padding=DEFAULT_PADDING)
 
    grid.add_column(justify="left", no_wrap=True)
 
    grid.add_column(justify="right", style="cyan", no_wrap=True)
 
    grid.add_column(justify="left", no_wrap=True)
 

	
 
    grid.add_row(GreenBoldText("Product ID:"), product_id)
 
    grid.add_row(GreenBoldText("Product Name:"), inner_product["name"])
 
    grid.add_row(GreenBoldText("Product Group:"), product_group["name"])
 

	
 
    for i, barcode_data in enumerate(product["product_barcodes"], start=1):
 
        grid.add_row(
 
            GreenBoldText(f"Barcode N°{i}:"),
 
            barcode_data["barcode"],
 
            barcode_data["note"],
 
        )
 

	
 
    purchase_quantity_unit = product["default_quantity_unit_purchase"]
 
    stock_quantity_unit = product["quantity_unit_stock"]
 

	
 
    purchase_to_stock_conversion = utils.get_request(
 
        f"objects/quantity_unit_conversions?query[]=from_qu_id={purchase_quantity_unit['id']}&query[]=to_qu_id={stock_quantity_unit['id']}"
 
    )  # type: list[dict[str, Any]]
 
    )
 

	
 
    if len(purchase_to_stock_conversion) != 0:
 
        conversion = f"{purchase_to_stock_conversion[0]['factor']} {stock_quantity_unit['name_plural']}"
 
    else:
 
        conversion = ""
 

	
 
    grid.add_row(
 
        GreenBoldText("Purchase Quantity Unit:"),
 
        purchase_quantity_unit["name"],
 
        conversion,
 
    )
 
    grid.add_row(
 
        GreenBoldText("Stock Quantity Unit:"),
 
        stock_quantity_unit["name"],
 
    )
 

	
 
    stock_amount = int(product["stock_amount"])
 
    grid.add_row(GreenBoldText("Overall Stock Amount:"), str(stock_amount))
 

	
 
    if stock_amount > 0:
 
        grid.add_row(GreenBoldText("Locations:"))
 
        locations = utils.get_request(
 
            f"stock/products/{product_id}/locations"
 
        )  # type: list[dict[str, Any]]
 
        locations = utils.get_request(f"stock/products/{product_id}/locations")
 

	
 
        for location in sorted(locations, key=itemgetter("location_name")):
 
            grid.add_row(
 
                f"[green bold]-[/green bold] [magenta]{location['location_name']}[/magenta]",
 
                location["amount"],
 
            )
 

	
 
    console.print(Panel(grid, title="[green bold]Product Info[/green bold]"))
 

	
 
    return
 

	
 

	
 
def transfer_by_barcode(barcode: str) -> None:
 

	
 
    product = utils.get_request(
 
        f"stock/products/by-barcode/{barcode}"
 
    )  # type: dict[str, Any]
 
    product = utils.get_request(f"stock/products/by-barcode/{barcode}")
 

	
 
    inner_product = product["product"]
 
    product_id = inner_product["id"]
 

	
 
    locations = utils.get_request(
 
        f"stock/products/{product_id}/locations"
 
    )  # type: list[dict[str, Any]]
 
    all_locations = utils.get_request("objects/locations")  # type: list[dict[str, Any]]
 
    locations = utils.get_request(f"stock/products/{product_id}/locations")
 
    all_locations = utils.get_request("objects/locations")
 

	
 
    grid = Table.grid(padding=DEFAULT_PADDING)
 
    grid.add_column(justify="right", no_wrap=True)
 
    grid.add_column(justify="left", style="cyan", no_wrap=True)
 
    grid.add_column(justify="right", style="magenta", no_wrap=True)
 

	
 
    grid.add_row(GreenBoldText("Product ID:"), product_id)
 
    grid.add_row(GreenBoldText("Product Name:"), inner_product["name"])
 
    grid.add_row(GreenBoldText("Locations:"))
 

	
 
    choices = []
 

	
 
    for location in sorted(locations, key=itemgetter("location_id")):
 
        location_id = location["location_id"]
 
        choices.append(location_id)
 
        grid.add_row(
 
            f"[blue]{location_id}[/blue]",
 
            location["location_name"],
 
            location["amount"],
 
        )
 

	
 
    choices.append("0")
 
    console.print(
 
        Panel(
 
@@ -151,107 +143,97 @@ def transfer_by_barcode(barcode: str) ->
 
            grid,
 
            title="[green bold]Locations[/green bold]",
 
            subtitle="[blue]Transfer Stock[/blue]",
 
        )
 
    )
 

	
 
    to_id = int_prompt.ask(
 
        "To (Enter 0 to abort)",
 
        choices=choices,
 
        default=int(choices[0]),
 
    )
 

	
 
    if not to_id:
 
        logging.debug("User aborted task!")
 
        return
 

	
 
    amount = int_prompt.ask("Amount (Enter 0 to abort)")
 

	
 
    if not amount:
 
        logging.debug("User aborted task!")
 
        return
 

	
 
    data = {"amount": amount, "location_id_from": from_id, "location_id_to": to_id}
 

	
 
    response = utils.post_request(
 
        f"stock/products/by-barcode/{barcode}/transfer", data
 
    )  # type: dict[str, Any]
 
    response = utils.post_request(f"stock/products/by-barcode/{barcode}/transfer", data)
 
    console.print("Successfully transfered!")
 
    return
 

	
 

	
 
def add_by_barcode(barcode: str) -> None:
 

	
 
    product = utils.get_request(
 
        f"stock/products/by-barcode/{barcode}"
 
    )  # type: dict[str, Any]
 
    product = utils.get_request(f"stock/products/by-barcode/{barcode}")
 

	
 
    inner_product = product["product"]
 
    product_id = inner_product["id"]
 

	
 
    grid = Table.grid(padding=DEFAULT_PADDING)
 
    grid.add_column(justify="right", no_wrap=True)
 
    grid.add_column(justify="left", style="cyan", no_wrap=True)
 
    grid.add_row(GreenBoldText("Product ID:"), product_id)
 
    grid.add_row(GreenBoldText("Product Name:"), inner_product["name"])
 
    console.print(
 
        Panel(
 
            grid,
 
            title="[green bold]Product Info[/green bold]",
 
            subtitle="[blue]Add Stock[/blue]",
 
        )
 
    )
 

	
 
    amount = int_prompt.ask("Amount (Enter 0 to abort)")
 

	
 
    if not amount:
 
        logging.debug("User aborted task!")
 
        return
 

	
 
    data = {"amount": amount, "transaction_type": "purchase"}
 

	
 
    response = utils.post_request(
 
        f"stock/products/by-barcode/{barcode}/add", data
 
    )  # type: dict[str, Any]
 
    response = utils.post_request(f"stock/products/by-barcode/{barcode}/add", data)
 
    console.print("Successfully added!")
 
    return
 

	
 

	
 
def update_by_barcode(barcode: str) -> None:
 

	
 
    product = utils.get_request(
 
        f"stock/products/by-barcode/{barcode}"
 
    )  # type: dict[str, Any]
 
    product = utils.get_request(f"stock/products/by-barcode/{barcode}")
 

	
 
    inner_product = product["product"]
 
    product_id = inner_product["id"]
 

	
 
    grid = Table.grid(padding=DEFAULT_PADDING)
 
    grid.add_column(justify="right", no_wrap=True)
 
    grid.add_column(justify="left", style="cyan", no_wrap=True)
 

	
 
    grid.add_row(GreenBoldText("Product ID:"), product_id)
 
    grid.add_row(GreenBoldText("Product Name:"), inner_product["name"])
 
    grid.add_row(GreenBoldText("Overall Stock Amount:"), product["stock_amount"])
 

	
 
    console.print(
 
        Panel(
 
            grid,
 
            title="[green bold]Product Info[/green bold]",
 
            subtitle="[blue]Update stock[/blue]",
 
        )
 
    )
 
    amount = int_prompt.ask("Amount (Enter 0 to abort)")
 

	
 
    if not amount:
 
        logging.debug("User aborted task!")
 
        return
 

	
 
    data = {
 
        "new_amount": amount,
 
    }
 

	
 
    response = utils.post_request(
 
        f"stock/products/{product_id}/inventory", data
 
    )  # type: dict[str, Any]
 
    response = utils.post_request(f"stock/products/{product_id}/inventory", data)
 
    console.print("Successfully updated!")
 
    return
0 comments (0 inline, 0 general)