From 7be76da8ae5587c954d78a91e3a23cc84fc4c398 Mon Sep 17 00:00:00 2001 From: Well Date: Sat, 29 Jun 2024 23:23:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=83=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8=20=D0=BD=D0=B0=20=D0=B1=D1=8D=D0=BA=D1=8D?= =?UTF-8?q?=D0=BD=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- directory/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/directory/models.py b/directory/models.py index 413653ec2d..c3f4d3b16a 100644 --- a/directory/models.py +++ b/directory/models.py @@ -616,6 +616,11 @@ def get_tube_data(research_pk: int, need_fractions: bool = False) -> dict: research_tubes[fraction.relation_id]["fractions"] = [fraction_data] return research_tubes + @staticmethod + def check_duplicated_internal_code(internal_code): + result = Researches.objects.filter(internal_code=internal_code) + return result.exists() + @staticmethod def get_laboratory_researches(podrazdelenie_id: int): if podrazdelenie_id == -1: @@ -715,6 +720,10 @@ def update_lab_research_and_fractions(research_data, need_log_data: bool = False old_log_data = {} new_log_data = {} service_data = Researches.normalize_research_data(research_data) + internal_code_is_duplicated = Researches.check_duplicated_internal_code(service_data["internal_code"]) + if internal_code_is_duplicated: + return {"ok": False, "message": "Такой внутренний код уже есть"} + service = Researches.objects.filter(pk=service_data["pk"]).first() if need_log_data: old_log_data = service.as_json_lab_full() @@ -770,6 +779,9 @@ def create_lab_service(service_data): def create_lab_research_and_fractions(research_data, need_log_data: bool = False): log_data = {} service_data = Researches.normalize_research_data(research_data) + internal_code_is_duplicated = Researches.check_duplicated_internal_code(service_data["internal_code"]) + if internal_code_is_duplicated: + return {"ok": False, "message": "Такой внутренний код уже есть"} new_service = Researches.create_lab_service(service_data) if need_log_data: log_data = new_service.as_json_lab_full() From 2a3212c55942d150810660e83537a93829038ded Mon Sep 17 00:00:00 2001 From: Well Date: Sat, 29 Jun 2024 23:28:41 +0800 Subject: [PATCH 2/2] fix --- api/construct/views.py | 30 +++++++++++--------- directory/models.py | 6 ++-- l2-frontend/src/construct/ResearchDetail.vue | 8 +++--- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/api/construct/views.py b/api/construct/views.py index 3327947d96..23cce5ae0d 100644 --- a/api/construct/views.py +++ b/api/construct/views.py @@ -65,13 +65,14 @@ def get_lab_research(request): def update_lab_research(request): request_data = json.loads(request.body) result = Researches.update_lab_research_and_fractions(request_data["research"], True) - Log.log( - result["old_data"]["pk"], - 220002, - request.user.doctorprofile, - {"old_data": result["old_data"], "new_data": result["new_data"]}, - ) - return JsonResponse(result) + if result["ok"]: + Log.log( + result["old_data"]["pk"], + 220002, + request.user.doctorprofile, + {"old_data": result["old_data"], "new_data": result["new_data"]}, + ) + return JsonResponse({"ok": result["ok"], "message": result["message"]}) @login_required @@ -79,13 +80,14 @@ def update_lab_research(request): def create_lab_research(request): request_data = json.loads(request.body) result = Researches.create_lab_research_and_fractions(request_data["research"], True) - Log.log( - result["log_data"]["pk"], - 220003, - request.user.doctorprofile, - result["log_data"], - ) - return JsonResponse(result) + if result["ok"]: + Log.log( + result["log_data"]["pk"], + 220003, + request.user.doctorprofile, + result["log_data"], + ) + return JsonResponse({"ok": result["ok"], "pk": result["pk"], "message": result["message"]}) @login_required diff --git a/directory/models.py b/directory/models.py index c3f4d3b16a..9547056179 100644 --- a/directory/models.py +++ b/directory/models.py @@ -754,8 +754,8 @@ def update_lab_research_and_fractions(research_data, need_log_data: bool = False if need_log_data: new_log_data["fractions"][new_fraction.pk] = Fractions.as_json(new_fraction) if need_log_data: - return {"ok": True, "old_data": old_log_data, "new_data": new_log_data} - return {"ok": True} + return {"ok": True, "old_data": old_log_data, "new_data": new_log_data, "message": ""} + return {"ok": True, "message": ""} @staticmethod def create_lab_service(service_data): @@ -781,7 +781,7 @@ def create_lab_research_and_fractions(research_data, need_log_data: bool = False service_data = Researches.normalize_research_data(research_data) internal_code_is_duplicated = Researches.check_duplicated_internal_code(service_data["internal_code"]) if internal_code_is_duplicated: - return {"ok": False, "message": "Такой внутренний код уже есть"} + return {"ok": False, "pk": None, "message": "Такой внутренний код уже есть"} new_service = Researches.create_lab_service(service_data) if need_log_data: log_data = new_service.as_json_lab_full() diff --git a/l2-frontend/src/construct/ResearchDetail.vue b/l2-frontend/src/construct/ResearchDetail.vue index a2080a9446..3b93dda291 100644 --- a/l2-frontend/src/construct/ResearchDetail.vue +++ b/l2-frontend/src/construct/ResearchDetail.vue @@ -568,14 +568,14 @@ const updateResearch = async () => { const researchValidate = validateResearch(); if (researchValidate.ok) { await store.dispatch(actions.INC_LOADING); - const { ok } = await api('construct/laboratory/update-research', { research: research.value }); + const { ok, message } = await api('construct/laboratory/update-research', { research: research.value }); await store.dispatch(actions.DEC_LOADING); if (ok) { root.$emit('msg', 'ok', 'Обновлено'); await getResearch(); emit('updateResearch'); } else { - root.$emit('msg', 'error', 'Ошибка'); + root.$emit('msg', 'error', message); } } else { root.$emit('msg', 'error', researchValidate.message); @@ -586,7 +586,7 @@ const createResearch = async () => { const researchValidate = validateResearch(); if (researchValidate.ok) { await store.dispatch(actions.INC_LOADING); - const { ok, pk } = await api('construct/laboratory/create-research', { research: research.value }); + const { ok, pk, message } = await api('construct/laboratory/create-research', { research: research.value }); await store.dispatch(actions.DEC_LOADING); if (ok) { research.value.pk = pk; @@ -594,7 +594,7 @@ const createResearch = async () => { await getResearch(); emit('updateResearch'); } else { - root.$emit('msg', 'error', 'Ошибка'); + root.$emit('msg', 'error', message); } } else { root.$emit('msg', 'error', researchValidate.message);