feat: allow deleting draft agreements while keeping approved read-only

This commit is contained in:
Арсентьев Александр
2026-09-28 21:55:29 +03:00
parent 2821208c65
commit 1b5bad0baf
9 changed files with 933 additions and 2 deletions
+2 -1
View File
@@ -1,7 +1,7 @@
<!doctype html><html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>ДС №{{ agreement.number }} — {{ project.name }}</title><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"><style>.numeric{font-variant-numeric:tabular-nums;white-space:nowrap}.item-name{min-width:16rem}</style></head><body class="bg-light"><main class="container-fluid container-xxl py-4">
<nav><ol class="breadcrumb"><li class="breadcrumb-item"><a href="/projects/">&#1055;&#1088;&#1086;&#1077;&#1082;&#1090;&#1099;</a></li><li class="breadcrumb-item"><a href="/projects/{{ project.id }}">{{ project.name }}</a></li><li class="breadcrumb-item"><a href="/projects/{{ project.id }}/agreements">&#1044;&#1057;</a></li><li class="breadcrumb-item active">&#8470;{{ agreement.number }}</li></ol></nav>
{% if error %}<div class="alert alert-danger" role="alert">{{ error }}</div>{% endif %}
<header class="d-flex flex-wrap justify-content-between align-items-start gap-3 mb-4"><div><h1 class="h2 mb-1">&#1044;&#1057; &#8470;{{ agreement.number }} — {{ agreement.title }}</h1><div class="text-muted">{{ agreement.date.strftime('%d.%m.%Y') }} · {{ scope_label }}</div></div><div class="d-flex gap-2"><a class="btn btn-outline-secondary" href="/projects/{{ project.id }}/agreements">&#1050; &#1089;&#1087;&#1080;&#1089;&#1082;&#1091;</a>{% if agreement.status == 'approved' %}<span class="badge text-bg-success align-self-center">&#1059;&#1090;&#1074;&#1077;&#1088;&#1078;&#1076;&#1077;&#1085;&#1086;</span>{% else %}<span class="badge text-bg-secondary align-self-center">&#1063;&#1077;&#1088;&#1085;&#1086;&#1074;&#1080;&#1082;</span>{% endif %}</div></header>
<header class="d-flex flex-wrap justify-content-between align-items-start gap-3 mb-4"><div><h1 class="h2 mb-1">&#1044;&#1057; &#8470;{{ agreement.number }} — {{ agreement.title }}</h1><div class="text-muted">{{ agreement.date.strftime('%d.%m.%Y') }} · {{ scope_label }}</div></div><div class="d-flex gap-2"><a class="btn btn-outline-secondary" href="/projects/{{ project.id }}/agreements">&#1050; &#1089;&#1087;&#1080;&#1089;&#1082;&#1091;</a>{% if agreement.status == 'approved' %}<span class="badge text-bg-success align-self-center">&#1059;&#1090;&#1074;&#1077;&#1088;&#1078;&#1076;&#1077;&#1085;&#1086;</span>{% else %}<span class="badge text-bg-secondary align-self-center">&#1063;&#1077;&#1088;&#1085;&#1086;&#1074;&#1080;&#1082;</span><button type="button" class="btn btn-outline-danger" data-bs-toggle="modal" data-bs-target="#deleteAgreementModal">Удалить ДС</button>{% endif %}</div></header>
{% if agreement.status == 'draft' %}
<section class="card border-0 shadow-sm mb-4"><div class="card-header bg-white"><h2 class="h5 mb-0">&#1056;&#1077;&#1082;&#1074;&#1080;&#1079;&#1080;&#1090;&#1099; &#1044;&#1057;</h2></div><form method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/update"><div class="card-body row g-3">
<div class="col-md-3"><label class="form-label">&#1053;&#1086;&#1084;&#1077;&#1088;</label><input class="form-control" name="number" value="{{ agreement.number }}" required></div><div class="col-md-3"><label class="form-label">&#1044;&#1072;&#1090;&#1072;</label><input class="form-control" type="date" name="agreement_date" value="{{ agreement.date.isoformat() }}" required></div><div class="col-md-6"><label class="form-label">&#1053;&#1072;&#1080;&#1084;&#1077;&#1085;&#1086;&#1074;&#1072;&#1085;&#1080;&#1077;</label><input class="form-control" name="title" value="{{ agreement.title }}" required></div><div class="col-12"><label class="form-label">&#1054;&#1087;&#1080;&#1089;&#1072;&#1085;&#1080;&#1077;</label><textarea class="form-control" name="description" rows="2">{{ agreement.description or '' }}</textarea></div>
@@ -15,6 +15,7 @@
<div class="col-xl-6"><section class="card border-0 shadow-sm h-100"><div class="card-header bg-white"><h2 class="h5 mb-0">&#1044;&#1086;&#1073;&#1072;&#1074;&#1080;&#1090;&#1100; &#1085;&#1086;&#1074;&#1091;&#1102; &#1087;&#1086;&#1079;&#1080;&#1094;&#1080;&#1102;</h2></div><form method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/items/new" data-new-item-form data-system-url="/projects/{{ project.id }}/agreements/{{ agreement.id }}/systems" data-section-url="/projects/{{ project.id }}/agreements/{{ agreement.id }}/sections"><div class="card-body row g-3"><div class="col-12"><label class="form-label">&#1042;&#1077;&#1076;&#1086;&#1084;&#1086;&#1089;&#1090;&#1100; (&#1085;&#1077;&#1086;&#1073;&#1103;&#1079;&#1072;&#1090;&#1077;&#1083;&#1100;&#1085;&#1086;)</label><select class="form-select" name="source_boq_document_id"><option value="">&#1041;&#1077;&#1079; &#1074;&#1077;&#1076;&#1086;&#1084;&#1086;&#1089;&#1090;&#1080;</option>{% for doc in boq_documents %}<option value="{{ doc.id }}" {% if agreement.boq_document_id == doc.id %}selected{% endif %}>{{ doc.display_name }}</option>{% endfor %}</select></div><div class="col-md-6"><label class="form-label">&#1053;&#1072;&#1080;&#1084;&#1077;&#1085;&#1086;&#1074;&#1072;&#1085;&#1080;&#1077;</label><input class="form-control" name="name" required></div><div class="col-md-6"><label class="form-label">&#1052;&#1086;&#1076;&#1077;&#1083;&#1100; / &#1072;&#1088;&#1090;&#1080;&#1082;&#1091;&#1083;</label><input class="form-control" name="model"></div><div class="col-md-6"><label class="form-label">&#1055;&#1088;&#1086;&#1080;&#1079;&#1074;&#1086;&#1076;&#1080;&#1090;&#1077;&#1083;&#1100;</label><input class="form-control" name="manufacturer"></div><div class="col-md-3"><label class="form-label">&#1045;&#1076;&#1080;&#1085;&#1080;&#1094;&#1072;</label><input class="form-control" name="unit"></div><div class="col-md-3"><label class="form-label">&#916; &#1082;&#1086;&#1083;-&#1074;&#1086;</label><input class="form-control" type="number" min="0.0001" step="0.0001" name="quantity_delta" required></div><div class="col-md-6"><label class="form-label">&#1062;&#1077;&#1085;&#1072; &#1079;&#1072; &#1077;&#1076;&#1080;&#1085;&#1080;&#1094;&#1091;</label><input class="form-control" type="number" min="0" step="0.000000000001" name="unit_price" required></div><div class="col-md-6"><label class="form-label">&#1057;&#1080;&#1089;&#1090;&#1077;&#1084;&#1072;</label><select class="form-select system-select" name="system_id" data-system-select><option value="">&#1041;&#1077;&#1079; &#1089;&#1080;&#1089;&#1090;&#1077;&#1084;&#1099;</option>{% for system in systems %}<option value="{{ system.id }}">{{ system.name }}</option>{% endfor %}<option value="__new__">+ &#1053;&#1086;&#1074;&#1072;&#1103; &#1089;&#1080;&#1089;&#1090;&#1077;&#1084;&#1072;...</option></select><div class="input-group mt-2 d-none" data-new-system-panel><input class="form-control" maxlength="255" placeholder="&#1053;&#1072;&#1079;&#1074;&#1072;&#1085;&#1080;&#1077; &#1089;&#1080;&#1089;&#1090;&#1077;&#1084;&#1099;"><button type="button" class="btn btn-outline-primary" data-create-system>&#1057;&#1086;&#1079;&#1076;&#1072;&#1090;&#1100;</button></div></div><div class="col-md-6"><label class="form-label">&#1056;&#1072;&#1079;&#1076;&#1077;&#1083;</label><select class="form-select section-select" name="section_id" data-section-select><option value="">&#1041;&#1077;&#1079; &#1088;&#1072;&#1079;&#1076;&#1077;&#1083;&#1072;</option>{% for section in sections %}<option value="{{ section.id }}" data-system="{{ section.system_id }}">{{ section.name }}</option>{% endfor %}<option value="__new__">+ &#1053;&#1086;&#1074;&#1099;&#1081; &#1088;&#1072;&#1079;&#1076;&#1077;&#1083;...</option></select><div class="input-group mt-2 d-none" data-new-section-panel><input class="form-control" maxlength="255" placeholder="&#1053;&#1072;&#1079;&#1074;&#1072;&#1085;&#1080;&#1077; &#1088;&#1072;&#1079;&#1076;&#1077;&#1083;&#1072;"><button type="button" class="btn btn-outline-primary" data-create-section>&#1057;&#1086;&#1079;&#1076;&#1072;&#1090;&#1100;</button></div></div><div class="col-12 text-danger small" data-association-error role="alert"></div></div><div class="card-footer bg-white"><button class="btn btn-outline-primary">&#1044;&#1086;&#1073;&#1072;&#1074;&#1080;&#1090;&#1100; &#1085;&#1086;&#1074;&#1091;&#1102; &#1087;&#1086;&#1079;&#1080;&#1094;&#1080;&#1102;</button></div></form></section></div></div>
<section class="d-flex justify-content-end mt-4"><button class="btn btn-success" data-bs-toggle="modal" data-bs-target="#approveModal" {% if not line_rows %}disabled{% endif %}>&#1059;&#1090;&#1074;&#1077;&#1088;&#1076;&#1080;&#1090;&#1100;</button></section>
<div class="modal fade" id="approveModal" tabindex="-1"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h2 class="modal-title fs-5">&#1055;&#1086;&#1076;&#1090;&#1074;&#1077;&#1088;&#1076;&#1080;&#1090;&#1077; &#1091;&#1090;&#1074;&#1077;&#1088;&#1078;&#1076;&#1077;&#1085;&#1080;&#1077;</h2><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body"><div><strong>&#1044;&#1057; &#8470;{{ agreement.number }}</strong></div><div>&#1054;&#1073;&#1083;&#1072;&#1089;&#1090;&#1100;: {{ scope_label }}</div><div>&#1050;&#1086;&#1083;&#1080;&#1095;&#1077;&#1089;&#1090;&#1074;&#1086; &#1087;&#1086;&#1079;&#1080;&#1094;&#1080;&#1081;: {{ line_rows|length }}</div><p class="text-warning mt-3 mb-0">&#1055;&#1086;&#1089;&#1083;&#1077; &#1091;&#1090;&#1074;&#1077;&#1088;&#1078;&#1076;&#1077;&#1085;&#1080;&#1103; &#1080;&#1079;&#1084;&#1077;&#1085;&#1077;&#1085;&#1080;&#1103; &#1085;&#1077;&#1083;&#1100;&#1079;&#1103; &#1088;&#1077;&#1076;&#1072;&#1082;&#1090;&#1080;&#1088;&#1086;&#1074;&#1072;&#1090;&#1100;.</p></div><div class="modal-footer"><button class="btn btn-outline-secondary" data-bs-dismiss="modal">&#1054;&#1090;&#1084;&#1077;&#1085;&#1072;</button><form method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/approve"><button class="btn btn-success">&#1059;&#1090;&#1074;&#1077;&#1088;&#1076;&#1080;&#1090;&#1100; &#1044;&#1057;</button></form></div></div></div></div>
<div class="modal fade" id="deleteAgreementModal" tabindex="-1"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h2 class="modal-title fs-5">Удалить черновик ДС</h2><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body"><p>Будет удалён весь документ <strong>ДС №{{ agreement.number }}</strong> и все его позиции ({{ line_rows|length }} шт.).</p><p class="text-danger mb-0">Действие необратимо.</p></div><div class="modal-footer"><button class="btn btn-outline-secondary" data-bs-dismiss="modal">Отмена</button><form method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/delete"><button class="btn btn-danger">Удалить ДС</button></form></div></div></div></div>
{% else %}<div class="alert alert-info">&#1044;&#1057; &#1091;&#1090;&#1074;&#1077;&#1088;&#1078;&#1076;&#1077;&#1085;&#1086;. &#1048;&#1079;&#1084;&#1077;&#1085;&#1077;&#1085;&#1080;&#1103; &#1085;&#1077;&#1076;&#1086;&#1089;&#1090;&#1091;&#1087;&#1085;&#1099;.</div>{% endif %}
</main><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script><script>
document.querySelectorAll('.system-select').forEach(systemSelect=>{const form=systemSelect.closest('form');const section=form.querySelector('.section-select');if(!section)return;const filter=()=>{const value=systemSelect.value;[...section.options].forEach(option=>{if(!option.dataset.system)return;option.hidden=!!value&&value!=='__new__'&&option.dataset.system!==value;});const selected=section.selectedOptions[0];if(selected&&selected.dataset.system&&selected.hidden)section.value='';};systemSelect.addEventListener('change',filter);filter();});