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
 
@@ -161,100 +161,108 @@ urllib3 = ">=1.21.1,<1.27"
 
socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"]
 
use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"]
 

	
 
[[package]]
 
name = "rich"
 
version = "11.2.0"
 
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
 
category = "main"
 
optional = false
 
python-versions = ">=3.6.2,<4.0.0"
 

	
 
[package.dependencies]
 
colorama = ">=0.4.0,<0.5.0"
 
commonmark = ">=0.9.0,<0.10.0"
 
pygments = ">=2.6.0,<3.0.0"
 

	
 
[package.extras]
 
jupyter = ["ipywidgets (>=7.5.1,<8.0.0)"]
 

	
 
[[package]]
 
name = "tomli"
 
version = "2.0.0"
 
description = "A lil' TOML parser"
 
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"},
 
    {file = "black-22.1.0-py3-none-any.whl", hash = "sha256:3524739d76b6b3ed1132422bf9d82123cd1705086723bc3e235ca39fd21c667d"},
 
    {file = "black-22.1.0.tar.gz", hash = "sha256:a7c0192d35635f6fc1174be575cb7915e92e5dd629ee79fdaf0dcfa41a80afb5"},
 
]
 
certifi = [
 
    {file = "certifi-2021.10.8-py2.py3-none-any.whl", hash = "sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"},
 
    {file = "certifi-2021.10.8.tar.gz", hash = "sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"},
 
]
 
charset-normalizer = [
 
    {file = "charset-normalizer-2.0.11.tar.gz", hash = "sha256:98398a9d69ee80548c762ba991a4728bfc3836768ed226b3945908d1a688371c"},
 
    {file = "charset_normalizer-2.0.11-py3-none-any.whl", hash = "sha256:2842d8f5e82a1f6aa437380934d5e1cd4fcf2003b06fed6940769c164a480a45"},
 
]
 
click = [
 
    {file = "click-8.0.3-py3-none-any.whl", hash = "sha256:353f466495adaeb40b6b5f592f9f91cb22372351c84caeb068132442a4518ef3"},
 
    {file = "click-8.0.3.tar.gz", hash = "sha256:410e932b050f5eed773c4cda94de75971c89cdb3155a72a0831139a79e5ecb5b"},
 
]
 
colorama = [
 
    {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"},
 
    {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"},
 
]
 
commonmark = [
 
    {file = "commonmark-0.9.1-py2.py3-none-any.whl", hash = "sha256:da2f38c92590f83de410ba1a3cbceafbc74fee9def35f9251ba9a971d6d66fd9"},
 
    {file = "commonmark-0.9.1.tar.gz", hash = "sha256:452f9dc859be7f06631ddcb328b6919c67984aca654e5fefb3914d54691aed60"},
 
]
 
idna = [
 
@@ -278,48 +286,51 @@ mypy = [
 
    {file = "mypy-0.931-cp37-cp37m-win_amd64.whl", hash = "sha256:d8f1ff62f7a879c9fe5917b3f9eb93a79b78aad47b533911b853a757223f72e7"},
 
    {file = "mypy-0.931-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:f9fe20d0872b26c4bba1c1be02c5340de1019530302cf2dcc85c7f9fc3252ae0"},
 
    {file = "mypy-0.931-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:1b06268df7eb53a8feea99cbfff77a6e2b205e70bf31743e786678ef87ee8069"},
 
    {file = "mypy-0.931-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:8c11003aaeaf7cc2d0f1bc101c1cc9454ec4cc9cb825aef3cafff8a5fdf4c799"},
 
    {file = "mypy-0.931-cp38-cp38-win_amd64.whl", hash = "sha256:d9d2b84b2007cea426e327d2483238f040c49405a6bf4074f605f0156c91a47a"},
 
    {file = "mypy-0.931-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:ff3bf387c14c805ab1388185dd22d6b210824e164d4bb324b195ff34e322d166"},
 
    {file = "mypy-0.931-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:5b56154f8c09427bae082b32275a21f500b24d93c88d69a5e82f3978018a0266"},
 
    {file = "mypy-0.931-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:8ca7f8c4b1584d63c9a0f827c37ba7a47226c19a23a753d52e5b5eddb201afcd"},
 
    {file = "mypy-0.931-cp39-cp39-win_amd64.whl", hash = "sha256:74f7eccbfd436abe9c352ad9fb65872cc0f1f0a868e9d9c44db0893440f0c697"},
 
    {file = "mypy-0.931-py3-none-any.whl", hash = "sha256:1171f2e0859cfff2d366da2c7092b06130f232c636a3f7301e3feb8b41f6377d"},
 
    {file = "mypy-0.931.tar.gz", hash = "sha256:0038b21890867793581e4cb0d810829f5fd4441aa75796b53033af3aa30430ce"},
 
]
 
mypy-extensions = [
 
    {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"},
 
    {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},
 
]
 
pathspec = [
 
    {file = "pathspec-0.9.0-py2.py3-none-any.whl", hash = "sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a"},
 
    {file = "pathspec-0.9.0.tar.gz", hash = "sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"},
 
]
 
platformdirs = [
 
    {file = "platformdirs-2.4.1-py3-none-any.whl", hash = "sha256:1d7385c7db91728b83efd0ca99a5afb296cab9d0ed8313a45ed8ba17967ecfca"},
 
    {file = "platformdirs-2.4.1.tar.gz", hash = "sha256:440633ddfebcc36264232365d7840a970e75e1018d15b4327d11f91909045fda"},
 
]
 
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(
 
            grid,
 
            title="[green bold]Product Info[/green bold]",
 
            subtitle="[blue]Transfer stock[/blue]",
 
        )
 
    )
 

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

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

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

	
 
    choices = []
 
    for location in sorted(all_locations, key=itemgetter("id")):
 
        location_id = location["id"]
 
        if int(location_id) != from_id:
 
            choices.append(location_id)
 
            grid.add_row(location_id, location["name"])
 

	
 
    choices.append("0")
 
    console.print(
 
        Panel(
 
            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)