Stok arama düzeltmesi - tüm XML taranacak
Browse files- MADONE SL 6 GEN 8 ürünü XML'de 464. sırada
- Erken durma limiti 10'a çıkarıldı
- v2 API kullanılıyor (doğru API)
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
app.py
CHANGED
|
@@ -85,10 +85,8 @@ def get_warehouse_stock(product_name):
|
|
| 85 |
print(f"DEBUG - Normalized (gen kept): {search_name}")
|
| 86 |
print(f"DEBUG - Search words: {search_words}")
|
| 87 |
|
| 88 |
-
# Search using new B2B API structure
|
| 89 |
candidates = []
|
| 90 |
-
product_count = 0
|
| 91 |
-
max_products = 100 # Increase limit for new API
|
| 92 |
|
| 93 |
# Separate size/color words from product words for context-aware search
|
| 94 |
size_color_words = ['s', 'm', 'l', 'xl', 'xs', 'xxl', 'ml', 'small', 'medium', 'large',
|
|
@@ -105,58 +103,65 @@ def get_warehouse_stock(product_name):
|
|
| 105 |
print(f"DEBUG - Product words: {product_words}")
|
| 106 |
print(f"DEBUG - Variant words: {variant_words}")
|
| 107 |
|
|
|
|
| 108 |
for product in root.findall('Product'):
|
| 109 |
-
if product_count >= max_products:
|
| 110 |
-
break
|
| 111 |
-
product_count += 1
|
| 112 |
-
|
| 113 |
product_name_elem = product.find('ProductName')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
variant_elem = product.find('ProductVariant')
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
variant_text = normalize_turkish(variant_elem.text.strip())
|
| 123 |
-
|
| 124 |
-
# Context-aware matching
|
| 125 |
-
name_match = False
|
| 126 |
-
variant_match = False
|
| 127 |
-
|
| 128 |
-
# Check product name match
|
| 129 |
-
if product_words:
|
| 130 |
-
name_match = all(word in normalized_name for word in product_words)
|
| 131 |
-
else:
|
| 132 |
-
name_match = any(word in normalized_name for word in search_words if len(word) > 2)
|
| 133 |
-
|
| 134 |
-
# Check variant match - be more strict with size matching
|
| 135 |
-
if variant_words and variant_text:
|
| 136 |
-
# For single letter sizes (S, M, L, etc), require exact match
|
| 137 |
-
if len(variant_words) == 1 and len(variant_words[0]) <= 2:
|
| 138 |
-
# Check if size appears as a separate token in variant
|
| 139 |
-
# Split by both dash and space to handle "s-beyaz gri" format
|
| 140 |
-
variant_tokens = variant_text.replace('-', ' ').split()
|
| 141 |
-
variant_match = any(variant_words[0] == token.strip().lower() for token in variant_tokens)
|
| 142 |
-
|
| 143 |
-
# Also check if it starts with the size (e.g., "s-beyaz")
|
| 144 |
-
if not variant_match:
|
| 145 |
-
variant_match = variant_text.startswith(variant_words[0] + '-') or variant_text.startswith(variant_words[0] + ' ')
|
| 146 |
-
else:
|
| 147 |
-
variant_match = all(word in variant_text for word in variant_words)
|
| 148 |
-
elif variant_words and not variant_text:
|
| 149 |
-
# If user specified a variant but product has no variant, skip
|
| 150 |
-
variant_match = False
|
| 151 |
else:
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
# Collect stock info from new structure
|
| 162 |
warehouse_stock_map = {}
|
|
|
|
| 85 |
print(f"DEBUG - Normalized (gen kept): {search_name}")
|
| 86 |
print(f"DEBUG - Search words: {search_words}")
|
| 87 |
|
| 88 |
+
# Search using new B2B API structure - OPTIMIZED
|
| 89 |
candidates = []
|
|
|
|
|
|
|
| 90 |
|
| 91 |
# Separate size/color words from product words for context-aware search
|
| 92 |
size_color_words = ['s', 'm', 'l', 'xl', 'xs', 'xxl', 'ml', 'small', 'medium', 'large',
|
|
|
|
| 103 |
print(f"DEBUG - Product words: {product_words}")
|
| 104 |
print(f"DEBUG - Variant words: {variant_words}")
|
| 105 |
|
| 106 |
+
# OPTIMIZED FAST SEARCH - Stop early when found
|
| 107 |
for product in root.findall('Product'):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
product_name_elem = product.find('ProductName')
|
| 109 |
+
|
| 110 |
+
# Quick skip if no name
|
| 111 |
+
if product_name_elem is None or not product_name_elem.text:
|
| 112 |
+
continue
|
| 113 |
+
|
| 114 |
+
xml_product_name = product_name_elem.text.strip()
|
| 115 |
+
|
| 116 |
+
# FAST PRE-CHECK: If key words not in uppercase name, skip
|
| 117 |
+
if product_words:
|
| 118 |
+
upper_name = xml_product_name.upper()
|
| 119 |
+
# Quick check - all product words must be in name
|
| 120 |
+
skip = False
|
| 121 |
+
for word in product_words:
|
| 122 |
+
if word.upper() not in upper_name:
|
| 123 |
+
skip = True
|
| 124 |
+
break
|
| 125 |
+
if skip:
|
| 126 |
+
continue
|
| 127 |
+
|
| 128 |
+
# Now do detailed normalization only for potential matches
|
| 129 |
+
normalized_name = normalize_turkish(xml_product_name)
|
| 130 |
+
|
| 131 |
+
# Final name match check
|
| 132 |
+
if product_words:
|
| 133 |
+
name_match = all(word in normalized_name for word in product_words)
|
| 134 |
+
else:
|
| 135 |
+
name_match = any(word in normalized_name for word in search_words if len(word) > 2)
|
| 136 |
+
|
| 137 |
+
if not name_match:
|
| 138 |
+
continue
|
| 139 |
+
|
| 140 |
+
# Name matches! Now check variant if needed
|
| 141 |
variant_elem = product.find('ProductVariant')
|
| 142 |
+
variant_text = ""
|
| 143 |
+
if variant_elem is not None and variant_elem.text:
|
| 144 |
+
variant_text = normalize_turkish(variant_elem.text.strip())
|
| 145 |
|
| 146 |
+
# Check variant match
|
| 147 |
+
variant_match = False
|
| 148 |
+
if variant_words and variant_text:
|
| 149 |
+
# For size codes like S, M, L - must start with it
|
| 150 |
+
if len(variant_words) == 1 and len(variant_words[0]) <= 2:
|
| 151 |
+
variant_match = variant_text.startswith(variant_words[0] + '-') or variant_text.startswith(variant_words[0] + ' ')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
else:
|
| 153 |
+
variant_match = all(word in variant_text for word in variant_words)
|
| 154 |
+
elif variant_words and not variant_text:
|
| 155 |
+
variant_match = False
|
| 156 |
+
else:
|
| 157 |
+
variant_match = True
|
| 158 |
+
|
| 159 |
+
# Found a match!
|
| 160 |
+
if name_match and variant_match:
|
| 161 |
+
candidates.append((product, xml_product_name, variant_text))
|
| 162 |
+
# Continue searching for all matching variants
|
| 163 |
+
if len(candidates) >= 10: # Reasonable limit
|
| 164 |
+
break
|
| 165 |
|
| 166 |
# Collect stock info from new structure
|
| 167 |
warehouse_stock_map = {}
|