feat(inout): 수퍼관리자 발주 삭제(발주 목록)
- 발주 목록 줄 끝 휴지통 — 수퍼관리자에게만 보이고 서버도 수퍼관리자만 허용(ERP 관리자도 403) - 확인 창 후 품목·입고 기록·입고증 사진·발주 메일 기록까지 완전히 삭제(CASCADE), 서버 로그에 남김 - 지운 뒤 보던 목록(거르기 그대로)으로 — 다른 사이트 주소는 무시 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -302,5 +302,23 @@ class InoutDbTests(unittest.TestCase):
|
||||
self.assertEqual(self.st.catalog_count(), before)
|
||||
|
||||
|
||||
def test_delete_order_cascades(self):
|
||||
"""수퍼관리자 발주 삭제 — 품목·입고 기록·입고증 사진·메일 기록까지 함께 지워진다."""
|
||||
o = self.order([("MT-D", 10), ("MT-E", 5)])
|
||||
ids = self.line_ids(o["id"])
|
||||
rid = self.st.add_receipt(o["id"], {ids["MT-D"]: "4"}, receipt_date="2026-10-20", memo="", confirm_over=False, by="w@x")
|
||||
if isinstance(rid, dict):
|
||||
rid = rid.get("receipt_id") or rid.get("id")
|
||||
r = self.st.delete_order(o["id"])
|
||||
self.assertEqual((r["order_no"], r["receipts"]), (o["order_no"], 1))
|
||||
self.assertIsNone(self.st.get_order(o["id"]))
|
||||
with self.st._pool.connection() as conn:
|
||||
left = conn.execute("SELECT (SELECT count(*) FROM inout_order_lines WHERE order_id=%s) + "
|
||||
"(SELECT count(*) FROM inout_receipts WHERE order_id=%s) AS n", (o["id"], o["id"])).fetchone()["n"]
|
||||
self.assertEqual(left, 0)
|
||||
with self.assertRaises(LookupError):
|
||||
self.st.delete_order(o["id"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -400,5 +400,47 @@ run(body)
|
||||
self.assertIn("OK", res.stdout)
|
||||
|
||||
|
||||
@unittest.skipUnless(DB_ENABLED, "INOUT_TEST_DB_URL(localhost) not set")
|
||||
def test_super_admin_deletes_order(self):
|
||||
"""발주 목록 🗑 — 수퍼관리자만(ERP 관리자·발주 담당은 403·버튼 없음), 지운 뒤 보던 목록으로."""
|
||||
res = _run('''
|
||||
import re, uuid
|
||||
from app.modules.inout.db import InoutDBStore
|
||||
st = InoutDBStore(__import__("os").environ["INOUT_TEST_DB_URL"])
|
||||
main.app.state.inout_store = st
|
||||
main.app.state.inout_items = Items()
|
||||
tag = uuid.uuid4().hex[:6]
|
||||
admin = U("admin-%s@t.local" % tag, role="admin")
|
||||
boss = dict(U("boss-%s@t.local" % tag, role="admin"), is_super_admin=True)
|
||||
users.extend([admin, boss])
|
||||
|
||||
def body(c):
|
||||
who["u"] = admin
|
||||
H = {"X-Inout-Options": "1"}
|
||||
c.post("/inout/settings/factories", data={"name": "공장D-" + tag, "is_active": "1"}, headers=H)
|
||||
fid = next(f["id"] for f in st.list_factories() if f["name"] == "공장D-" + tag)
|
||||
r = c.post("/inout/orders/new", data={"factory_id": fid, "order_date": "2026-10-16", "item_code": ["MT-A"],
|
||||
"item_name": [""], "qty": ["7"], "line_memo": [""]}, follow_redirects=False)
|
||||
oid = int(re.search(r"/inout/orders/(\\d+)", r.headers["location"]).group(1))
|
||||
no = st.get_order(oid)["order_no"]
|
||||
# ERP 관리자(수퍼 아님) — 버튼 없음, 직접 보내도 403
|
||||
assert 'action="/inout/orders/%d/delete"' % oid not in c.get("/inout/?status=all").text
|
||||
assert c.post("/inout/orders/%d/delete" % oid).status_code == 403
|
||||
assert st.get_order(oid) is not None
|
||||
# 수퍼관리자 — 목록에 🗑, 지우면 보던 목록(거르기 그대로)으로
|
||||
who["u"] = boss
|
||||
lst = c.get("/inout/?status=all&q=" + no).text
|
||||
assert 'action="/inout/orders/%d/delete"' % oid in lst and "완전히 삭제할까요?" in lst
|
||||
r = c.post("/inout/orders/%d/delete" % oid, data={"back": "/inout/?status=all&q=" + no}, follow_redirects=False)
|
||||
assert r.status_code == 303 and r.headers["location"].startswith("/inout/?status=all&q=" + no + "&msg="), r.headers["location"]
|
||||
assert st.get_order(oid) is None
|
||||
assert c.post("/inout/orders/%d/delete" % oid, data={"back": "https://evil.example/"}, follow_redirects=False).headers["location"].startswith("/inout/?msg=")
|
||||
print("OK")
|
||||
run(body)
|
||||
''', {"INOUT_TEST_DB_URL": DSN})
|
||||
self.assertEqual(res.returncode, 0, res.stdout + res.stderr)
|
||||
self.assertIn("OK", res.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user