fix: send prices in rubles to VK Market API, not kopecks
VK Market API expects the price field in rubles (float), not kopecks. Removing the *100 conversion that was inflating all prices by 100x. Comparison with cached VK prices now also uses rubles consistently. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -38,14 +38,14 @@ def _is_weight(measure: str | None) -> bool:
|
|||||||
return (measure or "").strip().lower() in WEIGHT_MEASURES
|
return (measure or "").strip().lower() in WEIGHT_MEASURES
|
||||||
|
|
||||||
|
|
||||||
def _calc_price(price: Decimal | None, measure: str | None) -> int:
|
def _calc_price(price: Decimal | None, measure: str | None) -> float:
|
||||||
"""Return price in VK kopecks (integer). Weight items are multiplied."""
|
"""Return price in rubles for VK Market API. Weight items are multiplied."""
|
||||||
if price is None:
|
if price is None:
|
||||||
return 0
|
return 0.0
|
||||||
base = int(price)
|
base = float(price)
|
||||||
if _is_weight(measure):
|
if _is_weight(measure):
|
||||||
base *= settings.VK_WEIGHT_PRICE_MULTIPLIER
|
base *= settings.VK_WEIGHT_PRICE_MULTIPLIER
|
||||||
return base * 100 # kopecks
|
return base
|
||||||
|
|
||||||
|
|
||||||
def _build_description(name: str, measure: str | None, evo_description: str | None) -> str:
|
def _build_description(name: str, measure: str | None, evo_description: str | None) -> str:
|
||||||
@@ -169,7 +169,7 @@ def _sync_product(
|
|||||||
token: str,
|
token: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
name = _name_for_vk(product.name)
|
name = _name_for_vk(product.name)
|
||||||
price_kopecks = _calc_price(product.price, product.measure_name)
|
price_rubles = _calc_price(product.price, product.measure_name)
|
||||||
desc = _build_description(product.name, product.measure_name, None)
|
desc = _build_description(product.name, product.measure_name, None)
|
||||||
stock = settings.VK_STOCK_AMOUNT if product.allow_to_sell else 0
|
stock = settings.VK_STOCK_AMOUNT if product.allow_to_sell else 0
|
||||||
owner_id = f"-{vk_group_id}"
|
owner_id = f"-{vk_group_id}"
|
||||||
@@ -185,7 +185,7 @@ def _sync_product(
|
|||||||
).first()
|
).first()
|
||||||
album_changed = False
|
album_changed = False
|
||||||
if vk_p:
|
if vk_p:
|
||||||
vk_price_kopecks = int(vk_p.price * 100) if vk_p.price is not None else 0
|
vk_price = float(vk_p.price) if vk_p.price is not None else 0.0
|
||||||
vk_stock = settings.VK_STOCK_AMOUNT if vk_p.availability == 0 else 0
|
vk_stock = settings.VK_STOCK_AMOUNT if vk_p.availability == 0 else 0
|
||||||
vk_name = vk_p.name or ""
|
vk_name = vk_p.name or ""
|
||||||
vk_desc = (vk_p.description or "").strip()
|
vk_desc = (vk_p.description or "").strip()
|
||||||
@@ -193,7 +193,7 @@ def _sync_product(
|
|||||||
album_changed = str(vk_p.album_id) != str(album_id) if album_id else False
|
album_changed = str(vk_p.album_id) != str(album_id) if album_id else False
|
||||||
changed = (
|
changed = (
|
||||||
name != vk_name
|
name != vk_name
|
||||||
or price_kopecks != vk_price_kopecks
|
or price_rubles != vk_price
|
||||||
or curr_desc != vk_desc
|
or curr_desc != vk_desc
|
||||||
or stock != vk_stock
|
or stock != vk_stock
|
||||||
or album_changed
|
or album_changed
|
||||||
@@ -210,7 +210,7 @@ def _sync_product(
|
|||||||
"name": name,
|
"name": name,
|
||||||
"description": desc.strip(),
|
"description": desc.strip(),
|
||||||
"category_id": settings.VK_CATEGORY_ID,
|
"category_id": settings.VK_CATEGORY_ID,
|
||||||
"price": price_kopecks,
|
"price": price_rubles,
|
||||||
"stock_amount": stock,
|
"stock_amount": stock,
|
||||||
}, token, user_id=user_id)
|
}, token, user_id=user_id)
|
||||||
if "error" in resp:
|
if "error" in resp:
|
||||||
@@ -252,7 +252,7 @@ def _sync_product(
|
|||||||
"name": name,
|
"name": name,
|
||||||
"description": desc,
|
"description": desc,
|
||||||
"category_id": settings.VK_CATEGORY_ID,
|
"category_id": settings.VK_CATEGORY_ID,
|
||||||
"price": price_kopecks,
|
"price": price_rubles,
|
||||||
"main_photo_id": photo_id,
|
"main_photo_id": photo_id,
|
||||||
"stock_amount": stock,
|
"stock_amount": stock,
|
||||||
}, token, user_id=user_id)
|
}, token, user_id=user_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user