Skip to content

Commit

Permalink
Configurable WMS translation table (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-Tomas authored May 14, 2024
1 parent fe5c18b commit a63517e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
4 changes: 4 additions & 0 deletions instock_connector/config/myinstock.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ instock-asrs-1:
instock_site_id: x.y.z-A
# Position of the ASRS in map space
pose: { "x": 0, "y": 0, "yaw": 0 }
# Map of WMS product IDs to InStock article IDs.
wms_translation_table:
article1wms: instock-art1
article2wms: instock-art2
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ class InstockConfigModel(BaseModel):
- instock_site_id (str): The ID of the InStock site.
- pose (dict, optional): The pose information which consists of "x", "y", and
"yaw" values. Defaults to {"x": 0, "y": 0, "yaw": 0}.
- wms_translation_table (dict, optional): A dictionary that maps WMS product IDs
to InStock article IDs.
"""
instock_api_url: HttpUrl = os.getenv("INSTOCK_API_URL", DEFAULT_INSTOCK_API_URL)
instock_api_token: str = os.getenv("INSTOCK_API_TOKEN")
instock_api_version: str = DEFAULT_INSTOCK_API_VERSION
instock_site_id: str
instock_org_id: str
pose: dict = default_instock_config["pose"]
wms_translation_table: dict = {}

# TODO(tomi): instock_base_url validator

Expand Down
10 changes: 10 additions & 0 deletions instock_connector/inorbit_instock_connector/src/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ def _handle_message_action(self, args: list, options: dict):
options["result_function"](2)
return

# Translate any items for which the WMS goods code differs from the
# article_id stored in InStock
translation = self.config.connector_config.wms_translation_table
if line["article_id"] in translation:
self._logger.info(
f'Replacing {line["article_id"]} with '
f'{translation[line["article_id"]]}'
)
line["article_id"] = translation[line["article_id"]]

if "order_id" in data and not isinstance(order_id, str):
self._logger.error('"order_id" must be a string if provided.')
options["result_function"](2)
Expand Down
21 changes: 0 additions & 21 deletions instock_connector/inorbit_instock_connector/src/instock/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@

TERMINAL_ORDER_STATUSES = ["done", "canceled"]

# TODO(adamantivm): Load translation table from a config file
INSTOCK_JELLO = "043000200261"
WMS_CHEESE = "R8S1B1-KraftParmesan"
INSTOCK_CHEESE = "R8S1B1"
WMS_PASTA = "R7S1B1-BarillaPasta"
INSTOCK_PASTA = "R7S1B1"

WMS_TO_INSTOCK_ID_MAP = {
WMS_CHEESE: INSTOCK_CHEESE,
WMS_PASTA: INSTOCK_PASTA
}


class InStockAPIBase(ABC):
def __init__(self, loglevel: LogLevels = logging.INFO):
Expand Down Expand Up @@ -224,15 +212,6 @@ def create_order(self, lines: list, order_id: str = None) -> dict | None:
}

for line in lines:
# Translate any items for which the WMS goods code differs from the
# article_id stored in InStock
if line["article_id"] in WMS_TO_INSTOCK_ID_MAP:
self.logger.info(
f'Replacing {line["article_id"]} with '
f'{WMS_TO_INSTOCK_ID_MAP[line["article_id"]]}'
)
line["article_id"] = WMS_TO_INSTOCK_ID_MAP[line["article_id"]]

data["lines"].append({
"line_id": f"inorbit-{uuid.uuid4()}",
"article_id": line["article_id"],
Expand Down

0 comments on commit a63517e

Please sign in to comment.