fix: use Item.brand for eBay pricing match
This commit is contained in:
@@ -326,32 +326,25 @@ def _upsert_system_pricing(manufacturer, model, pricing):
|
||||
|
||||
|
||||
def _update_item_market_data(manufacturer, model, pricing):
|
||||
clean_mfr = clean_manufacturer(manufacturer)
|
||||
model_lower = model.lower()
|
||||
|
||||
# Match by brand (exact) + item_name (contains model)
|
||||
items = frappe.get_all(
|
||||
"Item",
|
||||
filters={
|
||||
"item_group": ["in", ["Laptop", "Desktop", "Tablet", "Phone", "Workstation"]],
|
||||
"disabled": 0,
|
||||
"brand": clean_mfr,
|
||||
},
|
||||
fields=["name", "item_name", "brand"],
|
||||
fields=["name", "item_name"],
|
||||
)
|
||||
clean_mfr = clean_manufacturer(manufacturer).lower()
|
||||
model_lower = model.lower()
|
||||
matched = None
|
||||
for item in items:
|
||||
item_name_lower = (item.item_name or "").lower()
|
||||
brand_lower = (item.brand or "").lower()
|
||||
if model_lower in item_name_lower:
|
||||
if clean_mfr in brand_lower or brand_lower in clean_mfr or clean_mfr in item_name_lower:
|
||||
matched = item.name
|
||||
break
|
||||
elif matched is None:
|
||||
matched = item.name
|
||||
if not matched:
|
||||
for item in items:
|
||||
item_name_lower = (item.item_name or "").lower()
|
||||
if model_lower in item_name_lower:
|
||||
matched = item.name
|
||||
break
|
||||
matched = item.name
|
||||
break
|
||||
if not matched:
|
||||
return
|
||||
item_doc = frappe.get_doc("Item", matched)
|
||||
@@ -387,13 +380,15 @@ def _log_api_call(manufacturer, model, search_query, source, results_count, stat
|
||||
def run_batch(batch_size=10, source="auto", force=False):
|
||||
batch_size = int(batch_size) if batch_size != "all" else 999999
|
||||
force = bool(force)
|
||||
# Get unique models from Items that have serials
|
||||
models = frappe.db.sql(
|
||||
"""
|
||||
SELECT DISTINCT manufacturer, model
|
||||
FROM `tabSerial No`
|
||||
WHERE manufacturer IS NOT NULL AND manufacturer != ''
|
||||
AND model IS NOT NULL AND model != ''
|
||||
ORDER BY creation DESC
|
||||
SELECT DISTINCT i.brand as manufacturer, i.item_name as model
|
||||
FROM `tabItem` i
|
||||
INNER JOIN `tabSerial No` sn ON sn.item_code = i.name
|
||||
WHERE i.brand IS NOT NULL AND i.brand != ''
|
||||
AND i.disabled = 0
|
||||
ORDER BY i.modified DESC
|
||||
LIMIT %s
|
||||
""",
|
||||
(batch_size,),
|
||||
|
||||
Reference in New Issue
Block a user