File diff 2ea1af3149c2 → 8c86d58fda4b
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
 
@@ -12,16 +12,14 @@ 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)
 
@@ -44,7 +42,7 @@ def get_info_by_barcode(barcode: str) ->
 

	
 
    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']}"
 
@@ -66,9 +64,7 @@ def get_info_by_barcode(barcode: str) ->
 

	
 
    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(
 
@@ -83,17 +79,13 @@ def get_info_by_barcode(barcode: str) ->
 

	
 
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)
 
@@ -172,18 +164,14 @@ def transfer_by_barcode(barcode: str) ->
 

	
 
    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"]
 
@@ -209,18 +197,14 @@ def add_by_barcode(barcode: str) -> None
 

	
 
    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"]
 
@@ -250,8 +234,6 @@ def update_by_barcode(barcode: str) -> N
 
        "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