|
@@ -8,7 +8,6 @@ import yaml
|
|
|
from openpyxl import load_workbook
|
|
from openpyxl import load_workbook
|
|
|
from pydantic import ValidationError
|
|
from pydantic import ValidationError
|
|
|
|
|
|
|
|
-from app.git import git_add_commit
|
|
|
|
|
from app.parser import read_dir, read_file, parse_file
|
|
from app.parser import read_dir, read_file, parse_file
|
|
|
from app.schema import (
|
|
from app.schema import (
|
|
|
CartOrderInfo,
|
|
CartOrderInfo,
|
|
@@ -106,10 +105,6 @@ def update_product_inventory(
|
|
|
with open(p, "w") as f:
|
|
with open(p, "w") as f:
|
|
|
f.write(txt_doc)
|
|
f.write(txt_doc)
|
|
|
|
|
|
|
|
- # update git repo
|
|
|
|
|
- commit_msg = "Update product inventory"
|
|
|
|
|
- git_add_commit(settings.git_repo, filepath, commit_msg)
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
def create_variation_id(product: DocumentProduct):
|
|
def create_variation_id(product: DocumentProduct):
|
|
|
"""
|
|
"""
|
|
@@ -164,6 +159,16 @@ def write_product_id_db(product:DocumentProduct, settings, products_data = {}):
|
|
|
yaml.dump(products_data, f, default_flow_style = False)
|
|
yaml.dump(products_data, f, default_flow_style = False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def get_variation_id(product:DocumentProduct, size: str | None, style: str | None) -> str | None:
|
|
|
|
|
+ """Returns variation ID for product that has size or style"""
|
|
|
|
|
+ if size or style:
|
|
|
|
|
+ for variant in product.meta.inventory:
|
|
|
|
|
+ if variant.size == size and variant.style == style:
|
|
|
|
|
+ return variant.product_variation_id
|
|
|
|
|
+
|
|
|
|
|
+ return None
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def write_variation_id(product:DocumentProduct, settings):
|
|
def write_variation_id(product:DocumentProduct, settings):
|
|
|
""" Generate and write IDs for variation of the product into file"""
|
|
""" Generate and write IDs for variation of the product into file"""
|
|
|
|
|
|
|
@@ -189,16 +194,6 @@ def write_variation_id(product:DocumentProduct, settings):
|
|
|
# git_add_commit(settings.git_repo, filepath, commit_msg)
|
|
# git_add_commit(settings.git_repo, filepath, commit_msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def get_variation_id(product:DocumentProduct, size: str | None, style: str | None) -> str | None:
|
|
|
|
|
- """Returns variation ID for product that has size or style"""
|
|
|
|
|
- if size or style:
|
|
|
|
|
- for variant in product.meta.inventory:
|
|
|
|
|
- if variant.size == size and variant.style == style:
|
|
|
|
|
- return variant.product_variation_id
|
|
|
|
|
-
|
|
|
|
|
- return None
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
def get_products_by_category(settings):
|
|
def get_products_by_category(settings):
|
|
|
"""Helper function to product a list of products organized by their categories."""
|
|
"""Helper function to product a list of products organized by their categories."""
|
|
|
products = read_dir(
|
|
products = read_dir(
|
|
@@ -236,6 +231,7 @@ def get_product_by_product_id(
|
|
|
else:
|
|
else:
|
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def get_docs_by_category(category: str, settings):
|
|
def get_docs_by_category(category: str, settings):
|
|
|
"""Read a directory of directories and return a sublist with only the
|
|
"""Read a directory of directories and return a sublist with only the
|
|
|
documents matching the given category.
|
|
documents matching the given category.
|
|
@@ -380,8 +376,6 @@ def save_shipping_info(order: dict[str], git_repo: str, filepath: str) -> NoRetu
|
|
|
with open(p, "a") as f:
|
|
with open(p, "a") as f:
|
|
|
f.write(order["data"])
|
|
f.write(order["data"])
|
|
|
|
|
|
|
|
- git_add_commit(git_repo, filepath, order["commit_msg"])
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
def update_order_info(
|
|
def update_order_info(
|
|
|
order_id: str, order_status: str, git_repo: str, filepath: str
|
|
order_id: str, order_status: str, git_repo: str, filepath: str
|
|
@@ -468,10 +462,6 @@ def update_status_order(
|
|
|
client_reference_id, order_status, git_repo, local_db_filepath
|
|
client_reference_id, order_status, git_repo, local_db_filepath
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- if status_res:
|
|
|
|
|
- commit_msg = "Update order status"
|
|
|
|
|
- git_add_commit(git_repo, local_db_filepath, commit_msg)
|
|
|
|
|
-
|
|
|
|
|
return status_res
|
|
return status_res
|
|
|
|
|
|
|
|
|
|
|
|
@@ -652,7 +642,3 @@ def export_order_to_xlsx(
|
|
|
timestamp = arrow.get(order.date).format("YYYY-MM-DD-HHmmss")
|
|
timestamp = arrow.get(order.date).format("YYYY-MM-DD-HHmmss")
|
|
|
filepath = f"{git_repo}/orders/upload/{timestamp}--{order.order_id}.xlsx"
|
|
filepath = f"{git_repo}/orders/upload/{timestamp}--{order.order_id}.xlsx"
|
|
|
workbook.save(filename=filepath)
|
|
workbook.save(filename=filepath)
|
|
|
-
|
|
|
|
|
- # -- git add commit newly created file
|
|
|
|
|
- commit_msg = f"Export order {order.order_id} to .xlsx format"
|
|
|
|
|
- git_add_commit(git_repo, filepath, commit_msg)
|
|
|