Changeset - 2ea1af3149c2
[Not reviewed]
default
0 3 0
Dennis Fink - 2 years ago 2022-03-03 17:40:15
dennis.fink@c3l.lu
Add more debug logging
3 files changed with 12 insertions and 0 deletions:
0 comments (0 inline, 0 general)
stockcli/cli.py
Show inline comments
 
import json
 
import logging
 
import logging.config
 
from operator import itemgetter
 

	
 
import click
 
import requests
 
from rich.panel import Panel
 
@@ -59,12 +60,13 @@ def stockcli(ctx: click.Context, configf
 
    while True:
 
        click.clear()
 
        console.print(Panel(menu, title="[green bold]Menu[/green bold]"))
 
        choice = prompt.ask(
 
            "Enter a number to select a task", choices=list(TASK_MAP.keys())
 
        )
 
        logging.debug(f"User selected task: {choice}")
 
        selected_task = TASK_MAP[choice][1]
 

	
 
        rerun = True
 
        while rerun:
 
            barcode = prompt.ask("Please scan the barcode")
 
            barcode = prepare_barcode(barcode)
stockcli/stock.py
Show inline comments
 
import logging
 
from operator import itemgetter
 
from typing import Any
 

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

	
 
@@ -127,12 +128,13 @@ def transfer_by_barcode(barcode: str) ->
 
        "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)
 

	
 
@@ -156,17 +158,19 @@ def transfer_by_barcode(barcode: str) ->
 
        "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
 
@@ -197,12 +201,13 @@ def add_by_barcode(barcode: str) -> None
 
        )
 
    )
 

	
 
    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
 
@@ -235,12 +240,13 @@ def update_by_barcode(barcode: str) -> N
 
            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,
 
    }
 

	
stockcli/utils.py
Show inline comments
 
@@ -18,14 +18,18 @@ def make_request(method: str, url_path: 
 
    requested_url = base_url + url_path
 

	
 
    method_function = attrgetter(method)
 

	
 
    try:
 
        if data is not None:
 
            logging.debug(
 
                f"Making {method.upper()} request: {requested_url} with {data}"
 
            )
 
            response = method_function(session)(requested_url, json=data)
 
        else:
 
            logging.debug(f"Making {method.upper()} request: {requested_url}")
 
            response = method_function(session)(requested_url)
 
        response.raise_for_status()
 
    except requests.Timeout:
 
        logging.error(f"The connection to {requested_url} timed out!")
 
        error_console.print("Connection timed out!")
 
        raise
0 comments (0 inline, 0 general)