fix: delete VK product immediately when allow_to_sell becomes false
Previously only the create path checked allow_to_sell. The update path kept syncing disabled products indefinitely. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -164,6 +164,25 @@ def _sync_product(
|
|||||||
now = _now()
|
now = _now()
|
||||||
|
|
||||||
if product.vk_product_id:
|
if product.vk_product_id:
|
||||||
|
# Delete from VK if product is no longer for sale
|
||||||
|
if not product.allow_to_sell:
|
||||||
|
resp = _vk_post("market.delete", {
|
||||||
|
"owner_id": owner_id,
|
||||||
|
"item_id": product.vk_product_id,
|
||||||
|
}, token, user_id=user_id)
|
||||||
|
if "error" not in resp:
|
||||||
|
from web.models.connections import VkCachedProduct
|
||||||
|
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()
|
||||||
|
if vk_p:
|
||||||
|
db.delete(vk_p)
|
||||||
|
product.vk_product_id = None
|
||||||
|
logger.info("user=%s deleted VK product '%s' (disabled)", user_id, name)
|
||||||
|
else:
|
||||||
|
logger.warning("market.delete error for disabled product %s: %s", product.evotor_id, resp["error"])
|
||||||
|
return
|
||||||
|
|
||||||
# Check if update needed
|
# Check if update needed
|
||||||
changed = False
|
changed = False
|
||||||
# Re-read current VK state from cache
|
# Re-read current VK state from cache
|
||||||
|
|||||||
Reference in New Issue
Block a user