bfdafdsa
This commit is contained in:
1 parent
58618429db
commit
0f68b09a00
1 file changed
+21
-9
+21
-9
@@ -256,10 +256,15 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None):
|
||||
variation_id = None
|
||||
variation_version = None
|
||||
present_at_location_ids = []
|
||||
present_at_all_locations = False
|
||||
else:
|
||||
variation_id = variations[0]["id"]
|
||||
variation_version = variations[0].get("version")
|
||||
# Extract location IDs from variation
|
||||
# Check if variation is at all locations
|
||||
present_at_all_locations = variations[0].get(
|
||||
"present_at_all_locations", False
|
||||
)
|
||||
# Extract location IDs from variation (only if not at all locations)
|
||||
present_at_location_ids = variations[0].get(
|
||||
"present_at_location_ids", []
|
||||
)
|
||||
@@ -271,6 +276,7 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None):
|
||||
print(f"[@DEBUG] Fresh item version: {current_version}")
|
||||
print(f"[@DEBUG] Fresh variation version: {variation_version}")
|
||||
print(f"[@DEBUG] Category ID from fresh_item: {category_id}")
|
||||
print(f"[@DEBUG] Present at all locations: {present_at_all_locations}")
|
||||
print(f"[@DEBUG] Present at locations: {present_at_location_ids}")
|
||||
|
||||
# Ensure we have a category_id
|
||||
@@ -300,21 +306,27 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None):
|
||||
if variation_version is not None:
|
||||
variation_obj["version"] = variation_version
|
||||
|
||||
upsert_body = {
|
||||
"idempotency_key": str(uuid.uuid4()),
|
||||
"object": {
|
||||
# Build item object matching variation's location settings
|
||||
item_obj = {
|
||||
"type": "ITEM",
|
||||
"id": item_id,
|
||||
"version": current_version, # Include version for conflict prevention
|
||||
"present_at_all_locations": False, # Required when using specific locations
|
||||
"present_at_location_ids": present_at_location_ids, # Preserve location assignment
|
||||
"version": current_version,
|
||||
"present_at_all_locations": present_at_all_locations,
|
||||
"item_data": {
|
||||
"name": pw_name,
|
||||
"description": f"{set_name} - {set_theme}",
|
||||
"category_id": category_id, # Preserve category assignment
|
||||
"category_id": category_id,
|
||||
"variations": [variation_obj],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# Only include present_at_location_ids if not at all locations
|
||||
if not present_at_all_locations and present_at_location_ids:
|
||||
item_obj["present_at_location_ids"] = present_at_location_ids
|
||||
|
||||
upsert_body = {
|
||||
"idempotency_key": str(uuid.uuid4()),
|
||||
"object": item_obj,
|
||||
}
|
||||
|
||||
# Remove None values
|
||||
|
||||
Reference in new issue
Block a user