feat(inventory): Qwen vehicle compatibility — store AI unmatched vehicles as text, Celery background sync, fix brand filter fallback, increase vehicle limits
This commit is contained in:
44
pos/tasks.py
44
pos/tasks.py
@@ -96,3 +96,47 @@ def generate_report_task(self, report_type, params, tenant_id):
|
||||
'status': 'completed',
|
||||
'url': f'/pos/static/reports/{report_type}_{tenant_id}.pdf',
|
||||
}
|
||||
|
||||
|
||||
@celery.task(bind=True, max_retries=2)
|
||||
def sync_vehicle_compatibility_task(self, tenant_id, item_id, part_number, name, brand, compat_source):
|
||||
"""Fetch AI/TecDoc vehicle compatibility in background after item creation."""
|
||||
from tenant_db import get_tenant_conn, get_master_conn
|
||||
from services.inventory_vehicle_compat import auto_match_vehicle_compatibility, save_qwen_fitment
|
||||
from services.qwen_fitment import get_vehicle_fitment
|
||||
|
||||
tenant_conn = None
|
||||
master_conn = None
|
||||
try:
|
||||
tenant_conn = get_tenant_conn(tenant_id)
|
||||
|
||||
if compat_source in ('tecdoc', 'both'):
|
||||
try:
|
||||
master_conn = get_master_conn()
|
||||
auto_match_vehicle_compatibility(
|
||||
master_conn, tenant_conn, item_id, part_number,
|
||||
brand=brand, name=name
|
||||
)
|
||||
master_conn.close()
|
||||
master_conn = None
|
||||
except Exception as am_err:
|
||||
print(f"[sync_vehicle_compat] TecDoc error for item {item_id}: {am_err}")
|
||||
|
||||
if compat_source in ('qwen', 'both'):
|
||||
try:
|
||||
fitment = get_vehicle_fitment(part_number, name, brand or '')
|
||||
save_qwen_fitment(tenant_conn, item_id, fitment)
|
||||
except Exception as qwen_err:
|
||||
print(f"[sync_vehicle_compat] QWEN error for item {item_id}: {qwen_err}")
|
||||
|
||||
tenant_conn.commit()
|
||||
return {'status': 'ok', 'item_id': item_id, 'tenant_id': tenant_id}
|
||||
except Exception as exc:
|
||||
if tenant_conn:
|
||||
tenant_conn.rollback()
|
||||
raise self.retry(exc=exc, countdown=10)
|
||||
finally:
|
||||
if tenant_conn:
|
||||
tenant_conn.close()
|
||||
if master_conn:
|
||||
master_conn.close()
|
||||
|
||||
Reference in New Issue
Block a user