fix: read parent_id field from Evotor API and move VK products between albums on group change
- catalog.py: include parent_id as fallback for group_evotor_id (Evotor API returns parent_id instead of group/parentUuid) - vk_sync.py: on product update, detect album change and call market.removeFromAlbum + market.addToAlbum to move product to the correct album Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -183,17 +183,20 @@ def _sync_product(
|
||||
vk_p = db.query(VkCachedProduct).filter_by(
|
||||
user_id=user_id, vk_group_id=vk_group_id, vk_product_id=product.vk_product_id,
|
||||
).first()
|
||||
album_changed = False
|
||||
if vk_p:
|
||||
vk_price_kopecks = int(vk_p.price * 100) if vk_p.price is not None else 0
|
||||
vk_stock = settings.VK_STOCK_AMOUNT if vk_p.availability == 0 else 0
|
||||
vk_name = vk_p.name or ""
|
||||
vk_desc = (vk_p.description or "").strip()
|
||||
curr_desc = desc.strip()
|
||||
album_changed = str(vk_p.album_id) != str(album_id) if album_id else False
|
||||
changed = (
|
||||
name != vk_name
|
||||
or price_kopecks != vk_price_kopecks
|
||||
or curr_desc != vk_desc
|
||||
or stock != vk_stock
|
||||
or album_changed
|
||||
)
|
||||
else:
|
||||
changed = True # cached VK product gone, push update
|
||||
@@ -213,6 +216,24 @@ def _sync_product(
|
||||
if "error" in resp:
|
||||
logger.warning("market.edit error product=%s: %s", product.evotor_id, resp["error"])
|
||||
return
|
||||
|
||||
if album_changed and album_id and vk_p:
|
||||
old_album_id = str(vk_p.album_id)
|
||||
_vk_post("market.removeFromAlbum", {
|
||||
"owner_id": owner_id,
|
||||
"item_ids": product.vk_product_id,
|
||||
"album_ids": old_album_id,
|
||||
}, token)
|
||||
resp_album = _vk_post("market.addToAlbum", {
|
||||
"owner_id": owner_id,
|
||||
"item_ids": product.vk_product_id,
|
||||
"album_ids": album_id,
|
||||
}, token)
|
||||
if "error" in resp_album:
|
||||
logger.warning("market.addToAlbum error product=%s: %s", product.evotor_id, resp_album["error"])
|
||||
else:
|
||||
logger.info("user=%s moved VK product '%s' album %s→%s", user_id, name, old_album_id, album_id)
|
||||
|
||||
product.synced_at = now
|
||||
logger.info("user=%s updated VK product '%s' id=%s", user_id, name, product.vk_product_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user