Ordne Anlagen und Belege im Übergabepaket pro Hauptschriftstück zu.
Deploy Development / deploy (push) Successful in 28s
Test Suite / pytest-backend (push) Failing after 1m38s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 9s

Statt gemeinsamem anlagen-arbeitsstand und Datumsordnern auf Kapitel-Ebene liegen zugeordnete Dateien unter Dokumentname/Anlagen bzw. Belege, damit mehrere Schreiben im gleichen Kapitel vollständig und eindeutig exportiert werden.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-18 14:32:05 +02:00
1 parent 5b23e4aab0
commit 2b23992a1a
3 files changed
+152 -7

No files matched your search

+21 -5
View File
@@ -608,18 +608,34 @@ def _emit_loose(node, prefix, add, entries, loaded, notice_for, generated: str,
_emit_related(node, prefix, add, entries, loaded, notice_for, chosen, generated)
def _host_bundle(prefix: list[str], host: ExportNode) -> list[str]:
"""Correspondence files stay under the host title, not a shared chapter folder."""
return prefix + [_segment(host.title)]
def _related_bucket(node: ExportNode) -> str:
if node.kind == "attachment":
return "Anlagen"
if node.kind == "evidence":
return "Belege"
if node.kind == "dispatch_item":
relation = node.relation or ""
if "Anlage → Versand" in relation:
return "Anlagen"
return "Belege"
return "Belege"
def _emit_related(node, prefix, add, entries, loaded, notice_for, chosen, generated: str) -> None:
bundle = _host_bundle(prefix, node)
for child in node.children:
if child.kind == "attachment" and child.id in chosen and child.id in loaded:
_emit_one(child, prefix + ["anlagen-arbeitsstand"], add, entries, loaded, notice_for, generated)
_emit_one(child, bundle + ["Anlagen"], add, entries, loaded, notice_for, generated)
if child.kind != "dispatch":
continue
picked = [item for item in child.children if item.id in chosen and item.id in loaded]
if not picked:
continue
folder = prefix + [_segment(child.title)]
for item in picked:
_emit_one(item, folder, add, entries, loaded, notice_for, generated)
_emit_one(item, bundle + [_related_bucket(item)], add, entries, loaded, notice_for, generated)
def _emit_one(node, prefix, add, entries, loaded, notice_for, generated: str) -> None:
+2 -2
View File
@@ -384,7 +384,7 @@ def test_dispatch_keeps_the_secured_stand_and_distinct_mail_parts(client, db, mo
selected = [node["id"] for node in nodes if node["kind"] in {"dispatch_item", "evidence"}]
archive = _zip(ada, matter["id"], selected)
names = archive.namelist()
snapshot = next(name for name in names if name.endswith("/lage.pdf") and "/anlagen/" not in name)
snapshot = next(name for name in names if name.endswith("/Anlagen/lage.pdf"))
assert archive.read(snapshot) == PDF_B
eml_name = next(name for name in names if name.endswith("nachricht.eml"))
assert b"Fachlicher Zusatz" in archive.read(eml_name)
@@ -517,7 +517,7 @@ def test_dispatch_keeps_the_secured_stand_and_distinct_mail_parts(client, db, mo
assert gaps
assert all("Später geänderter Text" not in full.read(name).decode("utf-8") for name in gaps)
assert all(b"%PDF" not in full.read(name) for name in gaps)
secured = next(name for name in full.namelist() if name.endswith("/lage.pdf") and "/anlagen/" not in name)
secured = next(name for name in full.namelist() if name.endswith("/Anlagen/lage.pdf"))
assert full.read(secured) == PDF_B
+129
View File
@@ -777,3 +777,132 @@ def test_nested_chapter_export_keeps_path_and_complete_mail(client, db, monkeypa
assert overview.index("Anschreiben") < overview.index("Heizkostenbeleg")
assert "Hausmeisterbeleg" not in overview
assert "Ausgelassen" not in overview
def test_correspondence_attachments_stay_under_each_host_in_one_chapter(client, db):
ada = Actor(client, "ada-host-bundle@example.test", "Ada Host Bundle")
register(db, ada.email, ada.name)
ada.login()
matter = ada.request("POST", "/api/v1/matters", json={"title": "Gemeinsames Kapitel"}, status=201)
chapter = ada.request(
"POST",
f"/api/v1/matters/{matter['id']}/chapters",
json={"title": "Schriftwechsel"},
status=201,
)
first = ada.request(
"POST",
"/api/v1/notes",
json={
"title": "Erstes Schreiben",
"document": document("Text eins"),
"context": {"kind": "matter", "id": matter["id"]},
"chapter_id": chapter["id"],
},
status=201,
)
second = ada.request(
"POST",
"/api/v1/notes",
json={
"title": "Zweites Schreiben",
"document": document("Text zwei"),
"context": {"kind": "matter", "id": matter["id"]},
"chapter_id": chapter["id"],
},
status=201,
)
att_a1 = ada.request(
"POST",
"/api/v1/files",
data={"title": "Anlage A1", "context_kind": "matter", "context_id": matter["id"]},
files={"upload": ("a1.pdf", PDF_A, "application/pdf")},
status=201,
)
att_a2 = ada.request(
"POST",
"/api/v1/files",
data={"title": "Anlage A2", "context_kind": "matter", "context_id": matter["id"]},
files={"upload": ("a2.pdf", PDF_B, "application/pdf")},
status=201,
)
att_b1 = ada.request(
"POST",
"/api/v1/files",
data={"title": "Anlage B1", "context_kind": "matter", "context_id": matter["id"]},
files={"upload": ("b1.pdf", PDF_C, "application/pdf")},
status=201,
)
att_b2 = ada.request(
"POST",
"/api/v1/files",
data={"title": "Anlage B2", "context_kind": "matter", "context_id": matter["id"]},
files={"upload": ("a1.pdf", PDF_A, "application/pdf")},
status=201,
)
receipt = ada.request(
"POST",
"/api/v1/notes",
json={
"title": "Einlieferungsbeleg",
"document": document("Eingeliefert"),
"context": {"kind": "matter", "id": matter["id"]},
"dates": {"document_on": "2026-04-01"},
},
status=201,
)
detail = ada.request("GET", f"/api/v1/matters/{matter['id']}")
host_a = next(item for item in detail["bindings"] if item["element"]["title"] == "Erstes Schreiben")
host_b = next(item for item in detail["bindings"] if item["element"]["title"] == "Zweites Schreiben")
ada.request(
"POST",
f"/api/v1/elements/{first['id']}/attachments",
json={
"expected_version": host_a["element"]["version"],
"context": {"kind": "matter", "id": matter["id"]},
"attachment_element_ids": [att_a1["id"], att_a2["id"]],
"fold": "attachment",
},
status=201,
)
ada.request(
"POST",
f"/api/v1/elements/{second['id']}/attachments",
json={
"expected_version": host_b["element"]["version"],
"context": {"kind": "matter", "id": matter["id"]},
"attachment_element_ids": [att_b1["id"], att_b2["id"]],
"fold": "attachment",
},
status=201,
)
ada.request(
"POST",
f"/api/v1/elements/{first['id']}/dispatches",
json={
"expected_version": host_a["element"]["version"],
"context": {"kind": "matter", "id": matter["id"]},
"channel": "post",
"sent_on": "2026-04-02",
"counterpart": "Post",
"attachment_element_ids": [],
"evidence": [{"element_id": receipt["id"], "role": "submission", "fold": "keep"}],
},
status=201,
)
tree = ada.request("GET", f"/api/v1/matters/{matter['id']}/export-tree")["tree"]
selected = [
node["id"]
for node in _walk(tree)
if node["kind"] in {"binding", "attachment", "evidence"} and node["exportable"]
]
response = _post_zip(ada, matter["id"], {"context": {"kind": "matter", "id": matter["id"]}, "selected": selected})
assert response.status_code == 200, response.text
names = _archive(response.content).namelist()
assert not any("anlagen-arbeitsstand" in name.lower() for name in names)
first_paths = [name for name in names if "Erstes Schreiben/Erstes Schreiben/Anlagen/" in name.replace("\\", "/")]
second_paths = [name for name in names if "Zweites Schreiben/Zweites Schreiben/Anlagen/" in name.replace("\\", "/")]
assert sorted(name.rsplit("/", 1)[-1] for name in first_paths) == ["a1.pdf", "a2.pdf"]
assert sorted(name.rsplit("/", 1)[-1] for name in second_paths) == ["a1.pdf", "b1.pdf"]
assert any("Erstes Schreiben/Erstes Schreiben/Belege/" in name.replace("\\", "/") for name in names)
assert not any(name.replace("\\", "/").startswith("01 Schriftwechsel/2026-04") for name in names)