bfdafdsa
This commit is contained in:
1 parent
58618429db
commit
0f68b09a00
1 file changed
+26
-14
+26
-14
@@ -256,10 +256,15 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None):
|
|||||||
variation_id = None
|
variation_id = None
|
||||||
variation_version = None
|
variation_version = None
|
||||||
present_at_location_ids = []
|
present_at_location_ids = []
|
||||||
|
present_at_all_locations = False
|
||||||
else:
|
else:
|
||||||
variation_id = variations[0]["id"]
|
variation_id = variations[0]["id"]
|
||||||
variation_version = variations[0].get("version")
|
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 = variations[0].get(
|
||||||
"present_at_location_ids", []
|
"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 item version: {current_version}")
|
||||||
print(f"[@DEBUG] Fresh variation version: {variation_version}")
|
print(f"[@DEBUG] Fresh variation version: {variation_version}")
|
||||||
print(f"[@DEBUG] Category ID from fresh_item: {category_id}")
|
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}")
|
print(f"[@DEBUG] Present at locations: {present_at_location_ids}")
|
||||||
|
|
||||||
# Ensure we have a category_id
|
# 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:
|
if variation_version is not None:
|
||||||
variation_obj["version"] = variation_version
|
variation_obj["version"] = variation_version
|
||||||
|
|
||||||
|
# Build item object matching variation's location settings
|
||||||
|
item_obj = {
|
||||||
|
"type": "ITEM",
|
||||||
|
"id": item_id,
|
||||||
|
"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,
|
||||||
|
"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 = {
|
upsert_body = {
|
||||||
"idempotency_key": str(uuid.uuid4()),
|
"idempotency_key": str(uuid.uuid4()),
|
||||||
"object": {
|
"object": 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
|
|
||||||
"item_data": {
|
|
||||||
"name": pw_name,
|
|
||||||
"description": f"{set_name} - {set_theme}",
|
|
||||||
"category_id": category_id, # Preserve category assignment
|
|
||||||
"variations": [variation_obj],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove None values
|
# Remove None values
|
||||||
|
|||||||
Reference in new issue
Block a user