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)]
|
compatible = [a for a in matches if compatible_monitor(a, device)]
|
||||||
asset = linked or (compatible[0] if len(compatible) == 1 else None)
|
asset = linked or (compatible[0] if len(compatible) == 1 else None)
|
||||||
candidates = matches if not asset else []
|
candidates = matches if not asset else []
|
||||||
|
# candidate_by — 후보가 같은 시리얼(같은 실물일 가능성)인지, 참고용 같은 모델·이름인지.
|
||||||
|
# 같은 모델은 여러 대일 수 있으므로(듀얼 모니터 등) 새 등록을 막지 않는다(2026-10-07).
|
||||||
|
candidate_by = "serial" if candidates else ""
|
||||||
if not asset and not candidates:
|
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()
|
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],
|
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"})
|
"match": "linked" if linked else "serial" if asset else "unconfirmed"})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -263,8 +268,10 @@ class AssetStore:
|
|||||||
monitor_id = target["id"]
|
monitor_id = target["id"]
|
||||||
else:
|
else:
|
||||||
match = self._monitor_matches(conn, computer_id, row["parsed"])[index]
|
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})
|
data = payload.asset.model_copy(update={"serial": device["serial"] or payload.asset.serial})
|
||||||
monitor_id = self._create(conn, data, actor)
|
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-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>
|
<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 %}
|
{% 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 %}
|
||||||
|
|||||||
+1
-1
@@ -387,7 +387,7 @@
|
|||||||
return `<section class="am-monitor-summary"><h3>모니터 / MONITOR <span class="am-badge">${monitors.length}개</span></h3><div class="am-monitor-grid">${monitors
|
return `<section class="am-monitor-summary"><h3>모니터 / MONITOR <span class="am-badge">${monitors.length}개</span></h3><div class="am-monitor-grid">${monitors
|
||||||
.map((m) => {
|
.map((m) => {
|
||||||
const a = m.asset;
|
const a = m.asset;
|
||||||
return `<article class="am-monitor-card"><strong>${esc(m.name)}</strong><small>${esc(m.model)}${m.serial ? " · 시리얼 " + esc(m.serial) : " · 시리얼 미기록"}</small>${a ? `<div class="am-linked-overview"><span class="am-badge">등록된 자산</span><h4>${esc(a.name)}</h4><p>${esc(a.tag)} · ${esc(a.location || "위치 미지정")}<br>${esc(userName(a.assignee_email))} · ${esc(statuses[a.status])}<br>구매 ${money(a.purchase_cost)} · 보증 ${esc(a.warranty_until || "미입력")}</p><button class="am-text-btn" data-monitor-open="${esc(a.id)}">자산 개요 보기 ↗</button></div>` : `<p class="am-muted">${m.candidates?.length ? "같은 시리얼 또는 모델의 자산이 있습니다. 실제 장비를 확인하세요." : "연결된 자산이 없습니다."}</p>${current ? (m.candidates || []).map((c) => `<div class="am-monitor-candidate"><span>${esc(c.tag)} · ${esc(c.name)}<small>${esc(c.serial || "시리얼 미기록")} · ${esc(c.location || "위치 미지정")}</small></span><button class="am-text-btn" data-monitor-link="${m.index}" data-target="${esc(c.id)}">이 자산 연결</button></div>`).join("") + `<button class="erp-btn erp-btn-outline" data-monitor-create="${m.index}">+ 모니터 자산으로 등록</button>` : '<p class="am-muted">모니터 등록·연결은 최신 보고서에서 진행하세요.</p>'}`}</article>`;
|
return `<article class="am-monitor-card"><strong>${esc(m.name)}</strong><small>${esc(m.model)}${m.serial ? " · 시리얼 " + esc(m.serial) : " · 시리얼 미기록"}</small>${a ? `<div class="am-linked-overview"><span class="am-badge">등록된 자산</span><h4>${esc(a.name)}</h4><p>${esc(a.tag)} · ${esc(a.location || "위치 미지정")}<br>${esc(userName(a.assignee_email))} · ${esc(statuses[a.status])}<br>구매 ${money(a.purchase_cost)} · 보증 ${esc(a.warranty_until || "미입력")}</p><button class="am-text-btn" data-monitor-open="${esc(a.id)}">자산 개요 보기 ↗</button></div>` : `<p class="am-muted">${m.candidate_by === "serial" ? "같은 시리얼의 모니터 자산이 이미 있습니다. 같은 장비이므로 아래 자산에 연결하세요." : m.candidates?.length ? "같은 모델의 다른 자산이 있습니다. 같은 장비면 연결하고, 다른 장비(예: 듀얼 모니터)면 새로 등록하세요." : "연결된 자산이 없습니다."}</p>${current ? (m.candidates || []).map((c) => `<div class="am-monitor-candidate"><span>${esc(c.tag)} · ${esc(c.name)}<small>${esc(c.serial || "시리얼 미기록")} · ${esc(c.location || "위치 미지정")}</small></span><button class="am-text-btn" data-monitor-link="${m.index}" data-target="${esc(c.id)}">이 자산 연결</button></div>`).join("") + (m.candidate_by === "serial" ? "" : `<button class="erp-btn erp-btn-outline" data-monitor-create="${m.index}">+ 모니터 자산으로 등록</button>`) : '<p class="am-muted">모니터 등록·연결은 최신 보고서에서 진행하세요.</p>'}`}</article>`;
|
||||||
})
|
})
|
||||||
.join("")}</div></section>`;
|
.join("")}</div></section>`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@
|
|||||||
시리얼이 없거나 중복·제조사/모델 불일치인 경우 자동 확정하지 않고 후보를 직접 연결한다.
|
시리얼이 없거나 중복·제조사/모델 불일치인 경우 자동 확정하지 않고 후보를 직접 연결한다.
|
||||||
- 미등록 모니터는 보고서의 이름/제조사/모델/시리얼과 컴퓨터의 위치/부서를 채운 등록 창을 연다.
|
- 미등록 모니터는 보고서의 이름/제조사/모델/시리얼과 컴퓨터의 위치/부서를 채운 등록 창을 연다.
|
||||||
생성과 컴퓨터 연결은 한 트랜잭션으로 저장한다. 동시 등록은 컴퓨터 행 잠금과 시리얼 잠금으로 보호한다.
|
생성과 컴퓨터 연결은 한 트랜잭션으로 저장한다. 동시 등록은 컴퓨터 행 잠금과 시리얼 잠금으로 보호한다.
|
||||||
|
- 새 등록을 막는 것은 **같은 시리얼의 모니터 자산이 이미 있을 때뿐**이다(같은 실물 — 기존 자산에 연결).
|
||||||
|
같은 모델·이름의 자산은 참고 후보로만 보여 주고(`candidate_by = "model"`), 시리얼이 다르거나 없으면 새 자산으로 등록된다
|
||||||
|
(듀얼 모니터처럼 같은 모델 여러 대 — 2026-10-07 수정, 예전엔 같은 모델 후보만 있어도 막혔다).
|
||||||
- 등록·연결은 최신 보고서에서만 가능하다. 이전 보고서도 모니터와 자산 개요를 조회할 수 있다.
|
- 등록·연결은 최신 보고서에서만 가능하다. 이전 보고서도 모니터와 자산 개요를 조회할 수 있다.
|
||||||
기존에 업로드한 보고서도 재업로드 없이 지원한다.
|
기존에 업로드한 보고서도 재업로드 없이 지원한다.
|
||||||
|
|
||||||
|
|||||||
@@ -104,6 +104,21 @@ class FeatureStoreTests(unittest.TestCase):
|
|||||||
match=self.store._monitor_matches(self.conn,"other-computer",unknown)[0]
|
match=self.store._monitor_matches(self.conn,"other-computer",unknown)[0]
|
||||||
self.assertIsNone(match["asset"]);self.assertEqual(len(match["candidates"]),2)
|
self.assertIsNone(match["asset"]);self.assertEqual(len(match["candidates"]),2)
|
||||||
|
|
||||||
|
def test_same_model_different_serial_can_be_registered(self):
|
||||||
|
# 같은 모델(듀얼 모니터 등)이 이미 있어도 시리얼이 다르면 새 자산으로 등록된다(2026-10-07)
|
||||||
|
other = self.store.create(AssetInput(name="Display", category="monitor", model="Display 24", serial="SN-OTHER"), "actor")
|
||||||
|
match = self.store._monitor_matches(self.conn, self.computer, self.parsed)[0]
|
||||||
|
self.assertIsNone(match["asset"]); self.assertEqual(match["candidate_by"], "model")
|
||||||
|
self.assertEqual([c["id"] for c in match["candidates"]], [other])
|
||||||
|
target = self.store.register_monitor(self.computer, 0, self.monitor_payload(asset=AssetInput(name="Second", category="monitor", model="Display 24")), "actor")
|
||||||
|
self.assertNotEqual(target, other); self.assertEqual(self.conn.assets[target]["serial"], "SN-1")
|
||||||
|
|
||||||
|
def test_same_serial_still_blocks_new_registration(self):
|
||||||
|
self.store.create(AssetInput(name="Other", category="monitor", serial="SN-1", model="Different Model", manufacturer="Another"), "actor")
|
||||||
|
self.assertEqual(self.store._monitor_matches(self.conn, self.computer, self.parsed)[0]["candidate_by"], "serial")
|
||||||
|
with self.assertRaises(AssetConflict):
|
||||||
|
self.store.register_monitor(self.computer, 0, self.monitor_payload(asset=AssetInput(name="Dup", category="monitor")), "actor")
|
||||||
|
|
||||||
def test_existing_unique_serial_matches_automatically(self):
|
def test_existing_unique_serial_matches_automatically(self):
|
||||||
target=self.store.create(AssetInput(name="Existing",category="monitor",serial="sn-1"),"actor")
|
target=self.store.create(AssetInput(name="Existing",category="monitor",serial="sn-1"),"actor")
|
||||||
match=self.store._monitor_matches(self.conn,self.computer,self.parsed)[0]
|
match=self.store._monitor_matches(self.conn,self.computer,self.parsed)[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user