Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @router.get("/addons")
- def attach_addons(
- category_id: Annotated[List[str], Query(description="Category of Products to which addons must be attached.")],
- addon_inventory_ids: Annotated[List[str], Query(description="AddOns InventoryID")],
- store_id: int,
- db: Session = Depends(deps.get_db),
- ):
- for addon_inventory_id in addon_inventory_ids:
- addon_inventory = crud.inventory.get(db=db, id=addon_inventory_id)
- if addon_inventory:
- inventories = crud.inventory.get_by_categories(db=db, store_id=store_id, category_ids=category_id)
- # inventories = crud.inventory.get_by_filtering(db=db, store_id=store_id)
- for inventory in inventories:
- inventoryaddons = crud.inventoryaddons.get_addon(db=db, product_inventory_id=inventory.id, addon_inventory_id=addon_inventory_id)
- if not inventoryaddons:
- crud.inventoryaddons.create(db=db, obj_in=schemas.InventoryAddOnsCreate(inventory_id=inventory.id, addon_id=addon_inventory_id, price=addon_inventory.price), commit=False)
- else:
- logging.info("Already exist")
- db.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement