Advertisement
bagsari

Untitled

Jan 17th, 2025
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. @router.get("/addons")
  2. def attach_addons(
  3.     category_id: Annotated[List[str], Query(description="Category of Products to which addons must be attached.")],
  4.     addon_inventory_ids: Annotated[List[str], Query(description="AddOns InventoryID")],
  5.     store_id: int,
  6.     db: Session = Depends(deps.get_db),
  7. ):
  8.     for addon_inventory_id in addon_inventory_ids:
  9.         addon_inventory = crud.inventory.get(db=db, id=addon_inventory_id)
  10.         if addon_inventory:
  11.             inventories = crud.inventory.get_by_categories(db=db, store_id=store_id, category_ids=category_id)
  12.             # inventories = crud.inventory.get_by_filtering(db=db, store_id=store_id)
  13.             for inventory in inventories:
  14.                 inventoryaddons = crud.inventoryaddons.get_addon(db=db, product_inventory_id=inventory.id, addon_inventory_id=addon_inventory_id)
  15.                 if not inventoryaddons:
  16.                     crud.inventoryaddons.create(db=db, obj_in=schemas.InventoryAddOnsCreate(inventory_id=inventory.id, addon_id=addon_inventory_id, price=addon_inventory.price), commit=False)
  17.                 else:
  18.                     logging.info("Already exist")
  19.     db.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement