Skip to content

Commit a7f831d

Browse files
committed
sync ebay
1 parent 0caa5a0 commit a7f831d

1 file changed

Lines changed: 35 additions & 20 deletions

File tree

api/services/ebay_publish_service.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
_TCG_LEAF_CATEGORY_IDS = frozenset({"183050", "183454", "261328"})
3737
# Descripteur « état de la carte » (cartes non gradées) — name + value IDs eBay.
3838
_CARD_CONDITION_DESCRIPTOR_NAME = "40001"
39+
# Aligné sur le sélecteur « État » du formulaire article (ArticleForm.vue) + anciennes valeurs en base.
3940
_APP_TO_CARD_CONDITION_VALUE_ID: dict[str, str] = {
4041
"Mint": "400010",
4142
"Near Mint": "400010",
@@ -46,6 +47,17 @@
4647
"Played": "400016",
4748
"Poor": "400017",
4849
}
50+
# État article Inventory (conditionId) pour catégories TCG — dérivé du champ ``article.condition``.
51+
_TCG_ITEM_CONDITION_ENUM: dict[str, str] = {
52+
"Mint": "USED_VERY_GOOD",
53+
"Near Mint": "USED_VERY_GOOD",
54+
"NM": "USED_VERY_GOOD",
55+
"Excellent": "USED_VERY_GOOD",
56+
"Good": "USED_GOOD",
57+
"Lightly Played": "USED_GOOD",
58+
"Played": "USED_ACCEPTABLE",
59+
"Poor": "USED_ACCEPTABLE",
60+
}
4961

5062
_MARKETPLACE_CURRENCY: dict[str, str] = {
5163
"EBAY_US": "USD",
@@ -65,17 +77,12 @@ def _ebay_condition(app_condition: str) -> str:
6577

6678
def _ebay_condition_for_category(category_id: str, app_condition: str) -> str:
6779
"""
68-
Pour les catégories cartes TCG avec descripteur « état de la carte », eBay attend l’état article
69-
**4000 = USED_VERY_GOOD** (carte non gradée), pas **3000 = USED_EXCELLENT** — sinon erreur 25059
70-
à la publication. Voir condition-id-values (trading cards) dans la doc eBay.
80+
Pour les catégories cartes TCG : état article + descripteur carte doivent suivre la doc eBay
81+
(pas ``USED_EXCELLENT`` / 3000 seul). Chaque libellé du formulaire article a son mapping explicite.
7182
"""
7283
if category_id.strip() in _TCG_LEAF_CATEGORY_IDS:
7384
c = (app_condition or "").strip()
74-
if c in ("Poor", "Played"):
75-
return "USED_ACCEPTABLE"
76-
if c in ("Good", "Lightly Played"):
77-
return "USED_GOOD"
78-
return "USED_VERY_GOOD"
85+
return _TCG_ITEM_CONDITION_ENUM.get(c, "USED_VERY_GOOD")
7986
return _ebay_condition(app_condition)
8087

8188

@@ -85,6 +92,25 @@ def _card_condition_descriptor_value_id(app_condition: str) -> str:
8592
return _APP_TO_CARD_CONDITION_VALUE_ID.get(key, "400010")
8693

8794

95+
def _product_aspects(
96+
article: Article,
97+
*,
98+
category_id: str,
99+
marketplace_id: str,
100+
) -> dict[str, list[str]]:
101+
aspects: dict[str, list[str]] = {"Brand": ["Pokémon"]}
102+
if article.pokemon_name:
103+
aspects["Character"] = [article.pokemon_name.strip()]
104+
if article.set_code:
105+
aspects["Set"] = [article.set_code.strip()]
106+
if article.card_number:
107+
aspects["Card Number"] = [article.card_number.strip()]
108+
# EBAY_FR : caractéristique « Jeu » obligatoire pour nombreuses catégories cartes (erreur 25002).
109+
if marketplace_id.strip().upper() == "EBAY_FR" and category_id.strip() in _TCG_LEAF_CATEGORY_IDS:
110+
aspects["Jeu"] = ["Pokémon"]
111+
return aspects
112+
113+
88114
def _listing_price_eur(article: Article) -> Decimal:
89115
if article.sell_price is not None:
90116
return article.sell_price
@@ -139,17 +165,6 @@ def _description_html(article: Article) -> str:
139165
return f"<p>{esc}</p>"
140166

141167

142-
def _product_aspects(article: Article) -> dict[str, list[str]]:
143-
aspects: dict[str, list[str]] = {"Brand": ["Pokémon"]}
144-
if article.pokemon_name:
145-
aspects["Character"] = [article.pokemon_name.strip()]
146-
if article.set_code:
147-
aspects["Set"] = [article.set_code.strip()]
148-
if article.card_number:
149-
aspects["Card Number"] = [article.card_number.strip()]
150-
return aspects
151-
152-
153168
async def publish_article_to_ebay(
154169
db: Session,
155170
article: Article,
@@ -195,7 +210,7 @@ async def publish_article_to_ebay(
195210
"product": {
196211
"title": title,
197212
"description": _description_html(article),
198-
"aspects": _product_aspects(article),
213+
"aspects": _product_aspects(article, category_id=category_id, marketplace_id=marketplace_id),
199214
"imageUrls": https_images[:24],
200215
},
201216
}

0 commit comments

Comments
 (0)