fix(asset): allow registering a monitor of an already-registered model
Registration was blocked whenever same-model candidates existed, so a second monitor of the same model (e.g. dual monitors) could not be added. Now only an existing asset with the same serial blocks a new one; the UI tells serial and model candidates apart and hides 'register' only for serial matches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -229,9 +229,14 @@ class AssetStore:
|
||||
compatible = [a for a in matches if compatible_monitor(a, device)]
|
||||
asset = linked or (compatible[0] if len(compatible) == 1 else None)
|
||||
candidates = matches if not asset else []
|
||||
# candidate_by — 후보가 같은 시리얼(같은 실물일 가능성)인지, 참고용 같은 모델·이름인지.
|
||||
# 같은 모델은 여러 대일 수 있으므로(듀얼 모니터 등) 새 등록을 막지 않는다(2026-10-07).
|
||||
candidate_by = "serial" if candidates else ""
|
||||
if not asset and not candidates:
|
||||
candidates = conn.execute("SELECT * FROM assets WHERE category='monitor' AND deleted_at IS NULL AND (lower(btrim(model))=%s OR lower(btrim(name))=%s) ORDER BY id LIMIT 20", (device["model"].casefold(), device["name"].casefold())).fetchall()
|
||||
candidate_by = "model" if candidates else ""
|
||||
result.append({**device, "asset": serialize(asset), "candidates": [serialize(r) for r in candidates],
|
||||
"candidate_by": candidate_by,
|
||||
"match": "linked" if linked else "serial" if asset else "unconfirmed"})
|
||||
return result
|
||||
|
||||
@@ -263,8 +268,10 @@ class AssetStore:
|
||||
monitor_id = target["id"]
|
||||
else:
|
||||
match = self._monitor_matches(conn, computer_id, row["parsed"])[index]
|
||||
if match["asset"] or (device["serial"] and match["candidates"]):
|
||||
raise AssetConflict("이미 등록된 모니터가 있습니다. 기존 자산을 확인하고 연결하세요.")
|
||||
# 같은 시리얼(같은 실물)만 막는다 — 같은 모델이지만 시리얼이 다른 모니터는 새 자산으로 등록된다.
|
||||
if match["asset"] or match["candidate_by"] == "serial":
|
||||
raise AssetConflict(f"같은 시리얼({device['serial']})의 모니터가 이미 등록되어 있습니다. 기존 자산에 연결하세요."
|
||||
if device["serial"] else "이 모니터는 이미 자산에 연결되어 있습니다.")
|
||||
# 보고서의 실제 시리얼을 유지해야 이후 보고서에서도 같은 장비를 찾습니다.
|
||||
data = payload.asset.model_copy(update={"serial": device["serial"] or payload.asset.serial})
|
||||
monitor_id = self._create(conn, data, actor)
|
||||
|
||||
@@ -67,4 +67,4 @@
|
||||
<dialog id="am-photo" class="am-dialog" aria-labelledby="am-photo-title"><div class="am-dialog-head"><h2 id="am-photo-title">자산 사진 등록</h2><button type="button" class="am-close" data-close="am-photo" aria-label="사진 등록 닫기">×</button></div><form id="am-photo-form" class="am-form"><p class="am-form-hint">JPG · PNG · WebP, 파일당 8 MB 이하 · 자산당 최대 10장. 촬영 위치 정보는 제거해 보관합니다.</p><label>사진 선택<input id="am-photo-file" type="file" accept="image/jpeg,image/png,image/webp" required></label><div class="am-form-error" role="alert" hidden></div><div class="am-dialog-footer"><button type="button" class="erp-btn erp-btn-outline" data-close="am-photo">취소</button><button type="submit" class="erp-btn erp-btn-primary">사진 저장</button></div></form></dialog>
|
||||
<dialog id="am-delete" class="am-dialog" aria-labelledby="am-delete-title"><div class="am-dialog-head"><h2 id="am-delete-title">자산 삭제</h2><button type="button" class="am-close" data-close="am-delete" aria-label="삭제 창 닫기">×</button></div><form id="am-delete-form" class="am-form"><p class="am-warning" id="am-delete-hint"></p><p class="am-form-hint">자산대장과 현황에서 제외됩니다. 사진·보고서·처리 이력은 보존됩니다.</p><label>삭제할 자산번호 확인<input id="am-delete-confirm" required autocomplete="off"></label><label>삭제 사유<textarea id="am-delete-note" required maxlength="2000" rows="3"></textarea></label><div class="am-form-error" role="alert" hidden></div><div class="am-dialog-footer"><button type="button" class="erp-btn erp-btn-outline" data-close="am-delete">취소</button><button type="submit" class="erp-btn am-danger">자산 삭제</button></div></form></dialog>
|
||||
{% endblock %}
|
||||
{% block scripts %}<script id="am-config" type="application/json">{{ {"categories":categories,"statuses":statuses}|tojson }}</script><script src="/static/asset.js?v=20261006c" defer></script>{% endblock %}
|
||||
{% block scripts %}<script id="am-config" type="application/json">{{ {"categories":categories,"statuses":statuses}|tojson }}</script><script src="/static/asset.js?v=20261007a" defer></script>{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user