diff --git a/.gitignore b/.gitignore index 1b4cb6d..1275837 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,7 @@ secrets.* *~ .DS_Store Thumbs.db + +_tmp_*.py +output/ +storage/ \ No newline at end of file diff --git a/_tmp_fix_agr02.py b/_tmp_fix_agr02.py deleted file mode 100644 index 2ee609a..0000000 --- a/_tmp_fix_agr02.py +++ /dev/null @@ -1,75 +0,0 @@ -from pathlib import Path - -p = Path("app/templates/agreements/detail.html") -t = p.read_text(encoding="utf-8") - -old_badge = ( - "{% if agreement.status == 'approved' %}" - '\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e' - "{% else %}" - '\u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a' -) -new_badge = ( - "{% if agreement.status == 'approved' %}" - '\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e' - '' - "{% elif agreement.status == 'cancelled' %}" - '\u041e\u0422\u041c\u0415\u041d\u0415\u041d\u041e' - "{% else %}" - '\u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a' -) - -if old_badge in t: - t = t.replace(old_badge, new_badge) - print("badge replaced") -else: - print("badge NOT found") - -# The file uses HTML entities for Russian text - find and replace using entity form -# Look for the actual bytes in file -old_ent = "{% if agreement.status == 'approved' %}" -idx = t.find(old_ent) -if idx >= 0: - # Find the closing {% endif %} after this - end = t.find("{% endif %}", idx) - end += len("{% endif %}") - old_block = t[idx:end] - print("OLD BLOCK:", repr(old_block[:200])) - new_block = ( - "{% if agreement.status == 'approved' %}" - '\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e' - '' - "{% elif agreement.status == 'cancelled' %}" - '\u041e\u0422\u041c\u0415\u041d\u0415\u041d\u041e' - "{% else %}" - '\u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a' - '' - "{% endif %}" - ) - t = t.replace(old_block, new_block) - print("badge block replaced") - -old_modal = "\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0414\u0421" -cancel_modal = ( - '" + old_modal -) - -if old_modal in t: - t = t.replace(old_modal, cancel_modal) - print("modal replaced") -else: - print("modal NOT found") - -p.write_text(t, encoding="utf-8") -print("done") diff --git a/_tmp_verify_026b6.py b/_tmp_verify_026b6.py deleted file mode 100644 index d8744c9..0000000 --- a/_tmp_verify_026b6.py +++ /dev/null @@ -1,145 +0,0 @@ -"""Browser smoke for DOC-B6 (temporary).""" -import pathlib -from datetime import date -from decimal import Decimal - -from playwright.sync_api import sync_playwright - -from app.main import app -from app.database.database import SessionLocal -from app.models.boq import BoqDocument, WorkItem -from app.models.daily_report import DailyReport, DailyReportItem -from app.models.project import Project -from app.services.ks2_service import cancel_ks2, issue_ks2, save_draft as save_ks2_draft -from app.services.ks3_service import cancel_ks3, issue_ks3, save_draft as save_ks3_draft - -BASE = "http://127.0.0.1:8026" -results = [] - - -def ok(name, cond, detail=""): - results.append((name, bool(cond), detail)) - print(("PASS" if cond else "FAIL"), name, detail) - - -db = SessionLocal() -p = Project(name="B6 smoke", status="active") -db.add(p) -db.flush() -doc = BoqDocument(project_id=p.id, name="BOQ") -db.add(doc) -db.flush() -wi = WorkItem(project_id=p.id, boq_document_id=doc.id, name="W", unit="шт", - quantity=Decimal("100"), unit_price=Decimal("10"), amount=Decimal("1000")) -db.add(wi) -db.flush() -dr = DailyReport(project_id=p.id, report_date=date(2026, 2, 1)) -db.add(dr) -db.flush() -db.add(DailyReportItem(daily_report_id=dr.id, work_item_id=wi.id, completed_quantity=Decimal("50"))) -db.commit() -pid, wi_id = p.id, wi.id - -# Draft KS-2 -draft2 = save_ks2_draft(db, pid, "K2-SM", date(2026, 3, 1), None, - [(wi_id, Decimal("10"))], - reporting_period_from=date(2026, 2, 1), - reporting_period_to=date(2026, 2, 28)) -db.commit() -draft2_id = draft2.id - -# Issued KS-2 -ks2 = issue_ks2(db, pid, draft2_id) -ks2_id = ks2.id - -# Issued KS-3 -draft3 = save_ks3_draft(db, pid, "K3-SM", date(2026, 4, 1), None, [ks2_id], - reporting_period_from=date(2026, 2, 1), - reporting_period_to=date(2026, 2, 28)) -db.commit() -ks3 = issue_ks3(db, pid, draft3.id) -ks3_id = ks3.id - -# Cancelled KS-2 copy -draft2b = save_ks2_draft(db, pid, "K2-SM-C", date(2026, 3, 2), None, - [(wi_id, Decimal("5"))], - reporting_period_from=date(2026, 2, 1), - reporting_period_to=date(2026, 2, 28)) -db.commit() -ks2c = issue_ks2(db, pid, draft2b.id) -cancel_ks2(db, pid, ks2c.id) -ks2c_id = ks2c.id - -# Separate draft that stays draft -draft_only = save_ks2_draft(db, pid, "K2-SM-D", date(2026, 3, 3), None, - [(wi_id, Decimal("3"))], - reporting_period_from=date(2026, 2, 1), - reporting_period_to=date(2026, 2, 28)) -db.commit() -draft_only_id = draft_only.id - -db.close() -print("SEEDED", pid, "draft2", draft2_id, "ks2", ks2_id, "ks3", ks3_id, "ks2c", ks2c_id) - -with sync_playwright() as pw: - b = pw.chromium.launch(headless=True) - ctx = b.new_context(accept_downloads=True, viewport={"width": 1280, "height": 900}) - page = ctx.new_page() - - # Draft KS-2: no official button - page.goto(f"{BASE}/projects/{pid}/ks2/{draft_only_id}") - page.wait_for_load_state("networkidle") - ok("draft-ks2-no-btn", "Официальная форма" not in page.content()) - - # Issued KS-2: button present, download works - page.goto(f"{BASE}/projects/{pid}/ks2/{ks2_id}") - page.wait_for_load_state("networkidle") - html = page.content() - ok("issued-ks2-btn", "Официальная форма" in html) - ok("issued-ks2-export-still-there", "Excel" in html and "Word" in html) - with page.expect_download() as dl: - page.locator("a", has_text="Официальная форма").click() - d = dl.value - fname = d.suggested_filename - ok("ks2-download-filename", "КС-2" in fname and fname.endswith(".xlsx"), fname) - pathlib.Path("output").mkdir(exist_ok=True) - d.save_as("output/smoke_b6_ks2.xlsx") - ok("ks2-download-size", pathlib.Path("output/smoke_b6_ks2.xlsx").stat().st_size > 100) - - # Cancelled KS-2: button + СТОРНИРОВАН badge - page.goto(f"{BASE}/projects/{pid}/ks2/{ks2c_id}") - page.wait_for_load_state("networkidle") - html = page.content() - ok("cancelled-ks2-btn", "Официальная форма" in html) - ok("cancelled-ks2-storno", "СТОРНИРОВАН" in html) - with page.expect_download() as dl: - page.locator("a", has_text="Официальная форма").click() - d = dl.value - ok("cancelled-ks2-download", d.suggested_filename.endswith(".xlsx"), d.suggested_filename) - - # Issued KS-3: button + download - page.goto(f"{BASE}/projects/{pid}/ks3/{ks3_id}") - page.wait_for_load_state("networkidle") - html = page.content() - ok("issued-ks3-btn", "Официальная форма" in html) - ok("issued-ks3-word-label", "Word" in html) - with page.expect_download() as dl: - page.locator("a", has_text="Официальная форма").click() - d = dl.value - ok("ks3-download-filename", "КС-3" in d.suggested_filename and d.suggested_filename.endswith(".docx"), d.suggested_filename) - d.save_as("output/smoke_b6_ks3.docx") - ok("ks3-download-size", pathlib.Path("output/smoke_b6_ks3.docx").stat().st_size > 100) - - # Existing export still works - page.goto(f"{BASE}/projects/{pid}/ks2/{ks2_id}") - page.wait_for_load_state("networkidle") - with page.expect_download() as dl: - page.locator("a", has_text="Excel").first.click() - ok("legacy-export-works", dl.value.suggested_filename.endswith(".xlsx")) - - b.close() - -print("\nSUMMARY", sum(1 for r in results if r[1]), "/", len(results)) -for n, p, d in results: - if not p: - print("FAIL", n, d) diff --git a/_tmp_verify_029.py b/_tmp_verify_029.py deleted file mode 100644 index a48ec06..0000000 --- a/_tmp_verify_029.py +++ /dev/null @@ -1,144 +0,0 @@ -"""Browser smoke for task 029 (temporary).""" -from datetime import date -from decimal import Decimal - -from playwright.sync_api import sync_playwright - -from app.main import app -from app.database.database import SessionLocal -from app.models.project import Project -from app.models.agreement import Agreement, AgreementItem -from app.models.boq import BoqDocument, System, WorkItem - -BASE = "http://127.0.0.1:8029" -PID = 2 -results = [] - - -def ok(name, cond, detail=""): - results.append((name, bool(cond), detail)) - print(("PASS" if cond else "FAIL"), name, detail) - - -db = SessionLocal() -p = db.query(Project).filter_by(id=PID).first() -doc = db.query(BoqDocument).filter_by(project_id=PID).first() -system = db.query(System).filter_by(project_id=PID).first() -wi = db.query(WorkItem).filter( - WorkItem.project_id == PID, - WorkItem.system_id.isnot(None), - WorkItem.quantity > 0, -).first() -assert p and doc and system and wi -sys_id, wi_id, doc_id = system.id, wi.id, doc.id -print("ctx", PID, doc_id, sys_id, wi_id) -db.close() - - -def make_draft(number): - import time - number = f"{number}-{int(time.time() * 1000) % 100000}" - db = SessionLocal() - a = Agreement( - project_id=PID, number=number, date=date(2026, 1, 1), - title=f"Smoke {number}", status="draft", boq_document_id=doc_id, - ) - db.add(a) - db.commit() - aid = a.id - db.close() - return aid - - -with sync_playwright() as pw: - b = pw.chromium.launch(headless=True) - page = b.new_page(viewport={"width": 1280, "height": 900}) - page.on("dialog", lambda d: d.accept()) - - # 2-5. Empty draft: button exists, delete works - aid = make_draft("SM-EMPTY") - page.goto(f"{BASE}/projects/{PID}/agreements/{aid}") - page.wait_for_load_state("networkidle") - ok("empty-draft-btn", page.locator("button[data-bs-target='#deleteAgreementModal']").count() == 1) - ok("empty-draft-modal", "deleteAgreementModal" in page.content()) - page.locator("button[data-bs-target='#deleteAgreementModal']").click() - page.wait_for_timeout(300) - page.locator("#deleteAgreementModal button.btn-danger").click() - page.wait_for_load_state("networkidle") - ok("empty-deleted", "agreements" in page.url and "deleted=1" in page.url, page.url) - ok("empty-flash", "Черновик ДС удалён" in page.content()) - db = SessionLocal() - ok("empty-gone", db.get(Agreement, aid) is None) - db.close() - - # 6-8. Draft with existing item: base WorkItem preserved - aid = make_draft("SM-EXIST") - page.goto(f"{BASE}/projects/{PID}/agreements/{aid}") - page.wait_for_load_state("networkidle") - page.fill("#existing-position-search", "") - page.wait_for_timeout(200) - # pick first autocomplete option - page.locator(".autocomplete-position").first.click() - page.locator("form[action$='/items/existing'] input[name=quantity_delta]").fill("3") - page.locator("button", has_text="Добавить позицию").click() - page.wait_for_load_state("networkidle") - ok("existing-added", "Увеличение" in page.content() or "3" in page.content()) - page.locator("button[data-bs-target='#deleteAgreementModal']").click() - page.wait_for_timeout(300) - page.locator("#deleteAgreementModal button.btn-danger").click() - page.wait_for_load_state("networkidle") - db = SessionLocal() - ok("existing-agr-gone", db.get(Agreement, aid) is None) - ok("base-wi-kept", db.get(WorkItem, wi_id) is not None) - db.close() - - # 9-11. Draft with new_position: orphan WorkItem removed - aid = make_draft("SM-NEW") - page.goto(f"{BASE}/projects/{PID}/agreements/{aid}") - page.wait_for_load_state("networkidle") - page.locator("form[action$='/items/new'] input[name=name]").fill("Сирота 029") - page.locator("form[action$='/items/new'] input[name=quantity_delta]").fill("2") - page.locator("form[action$='/items/new'] input[name=unit_price]").fill("5") - page.select_option("form[action$='/items/new'] select[name=system_id]", str(sys_id)) - page.wait_for_timeout(100) - page.select_option("form[action$='/items/new'] select[name=section_id]", str(wi.section_id or 0) if False else page.locator("form[action$='/items/new'] select[name=section_id] option").nth(1).get_attribute("value")) - page.locator("button", has_text="Добавить новую позицию").click() - page.wait_for_load_state("networkidle") - ok("new-added", "Сирота 029" in page.content() or "Новая" in page.content()) - db = SessionLocal() - orphan = db.query(WorkItem).filter_by(name="Сирота 029").first() - orphan_id = orphan.id if orphan else None - db.close() - ok("orphan-created", orphan_id is not None) - page.locator("button[data-bs-target='#deleteAgreementModal']").click() - page.wait_for_timeout(300) - page.locator("#deleteAgreementModal button.btn-danger").click() - page.wait_for_load_state("networkidle") - db = SessionLocal() - ok("new-agr-gone", db.get(Agreement, aid) is None) - ok("orphan-wi-gone", orphan_id is None or db.get(WorkItem, orphan_id) is None) - db.close() - - # 12-13. Approved cannot be deleted - db = SessionLocal() - a = Agreement(project_id=PID, number="SM-APPR", date=date(2026, 1, 1), - title="Approved smoke", status="approved", boq_document_id=doc_id) - db.add(a) - db.commit() - appr_id = a.id - db.close() - page.goto(f"{BASE}/projects/{PID}/agreements/{appr_id}") - page.wait_for_load_state("networkidle") - ok("approved-no-btn", page.locator("button[data-bs-target='#deleteAgreementModal']").count() == 0) - ok("approved-no-modal", "deleteAgreementModal" not in page.content()) - # direct POST blocked - resp = page.request.post(f"{BASE}/projects/{PID}/agreements/{appr_id}/delete") - ok("approved-post-blocked", resp.status == 409, str(resp.status)) - page.screenshot(path="output/playwright/029-approved-no-delete.png") - - b.close() - -print("\nSUMMARY", sum(1 for r in results if r[1]), "/", len(results)) -for n, p, d in results: - if not p: - print("FAIL", n, d) diff --git a/output/playwright/029-approved-no-delete.png b/output/playwright/029-approved-no-delete.png deleted file mode 100644 index 840fe0f..0000000 Binary files a/output/playwright/029-approved-no-delete.png and /dev/null differ diff --git a/output/smoke_b6_ks3.docx b/output/smoke_b6_ks3.docx deleted file mode 100644 index 8ea0e43..0000000 Binary files a/output/smoke_b6_ks3.docx and /dev/null differ diff --git a/storage/projects/3/documents/KS3/3/ks3_v1_2026-09-30_105535_326329.docx b/storage/projects/3/documents/KS3/3/ks3_v1_2026-09-30_105535_326329.docx deleted file mode 100644 index cad94f9..0000000 Binary files a/storage/projects/3/documents/KS3/3/ks3_v1_2026-09-30_105535_326329.docx and /dev/null differ diff --git a/storage/projects/4/documents/KS3/4/ks3_v1_2026-09-30_105629_787056.docx b/storage/projects/4/documents/KS3/4/ks3_v1_2026-09-30_105629_787056.docx deleted file mode 100644 index 8ea0e43..0000000 Binary files a/storage/projects/4/documents/KS3/4/ks3_v1_2026-09-30_105629_787056.docx and /dev/null differ