From 19876a5640f042714ee5c60a461c0c257fa15c25 Mon Sep 17 00:00:00 2001 From: cproudlock Date: Fri, 24 Jul 2026 13:24:36 -0400 Subject: [PATCH] warranty: fix bulk Dell re-check duplicating non-dell warranties The bulk /sync/dell reuse check only matched an existing warranty when its provider was exactly 'dell'. Warranties added by hand or via import default to provider 'manual', so re-check-all did not recognize them and created a brand new Dell warranty for every asset - duplicating the whole set. Broaden the reuse match to treat a warranty as Dell by any signal (provider, matching service tag, or a 'Dell' vendor), and canonicalize the reused row to provider 'dell' so later re-checks match by provider and never duplicate. --- plugins/warranty/api/routes.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/warranty/api/routes.py b/plugins/warranty/api/routes.py index 890e322..fa51ae0 100644 --- a/plugins/warranty/api/routes.py +++ b/plugins/warranty/api/routes.py @@ -286,10 +286,22 @@ def sync_dell(): existing = None for link in WarrantyAsset.query.filter_by(assetid=assetid).all(): candidate = db.session.get(Warranty, link.warrantyid) - if candidate and candidate.provider == 'dell': + # Reuse a warranty that is Dell by ANY signal, not just + # provider: a manually-added or imported Dell warranty carries + # provider 'manual' (create default) but the same service tag or + # a "Dell" vendor. Matching only provider=='dell' made re-check + # duplicate every one of those instead of updating it. + if candidate and ( + candidate.provider == 'dell' + or (candidate.servicetag or '').strip().upper() == tag + or (candidate.vendor or '').strip().lower() == 'dell'): existing = candidate break if existing: + # Canonicalize to Dell so later re-checks match by provider and + # never fall through to a duplicate. + existing.provider = 'dell' + existing.vendor = existing.vendor or 'Dell' existing.servicelevel = found.get('servicelevel') existing.startdate = _parse_date(found.get('startdate')) existing.enddate = _parse_date(found.get('enddate'))