Skip to content

Commit

Permalink
Merge pull request #4106 from mikhailprivalov/constructor-lab-fsli-du…
Browse files Browse the repository at this point in the history
…plicate-fix

Дублирование ФСЛИ - fix
  • Loading branch information
urchinpro authored Jul 17, 2024
2 parents 09179d1 + 3794022 commit c1c9643
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions directory/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.auth.models import Group
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models, transaction
from django.db.models import Q
from jsonfield import JSONField

from laboratory.settings import DEATH_RESEARCH_PK, EXCLUDE_TYPE_RESEARCH
Expand Down Expand Up @@ -745,13 +746,19 @@ def update_lab_research_and_fractions(research_data, need_log_data: bool = False
fraction_data = Fractions.normalize_fraction_data(fraction)
if service_fractions:
current_fraction = service_fractions.filter(pk=fraction["id"]).first()
fsli_is_duplicated = Fractions.check_duplicated_fsli_code(current_fraction.pk, fraction_data["fsli"])
if not fsli_is_duplicated["ok"]:
return {"ok": False, "message": f"В анализе {fsli_is_duplicated['research_title']} есть такой же код ФСЛИ ({fraction_data['fsli']})"}
if current_fraction:
if need_log_data:
old_log_data["fractions"][current_fraction.pk] = Fractions.as_json(current_fraction)
Fractions.update_fraction(current_fraction, fraction_data)
if need_log_data:
new_log_data["fractions"][current_fraction.pk] = Fractions.as_json(current_fraction)
else:
fsli_is_duplicated = Fractions.check_duplicated_fsli_code(-1, fraction_data["fsli"])
if not fsli_is_duplicated["ok"]:
return {"ok": False, "message": f"В анализе {fsli_is_duplicated['research_title']} есть такой же код ФСЛИ ({fraction_data['fsli']})"}
new_fraction = Fractions.create_fraction(fraction_data, service.pk, relation.pk)
if need_log_data:
new_log_data["fractions"][new_fraction.pk] = Fractions.as_json(new_fraction)
Expand Down Expand Up @@ -792,6 +799,9 @@ def create_lab_research_and_fractions(research_data, need_log_data: bool = False
relation = ReleationsFT.get_or_create_relation(tube)
for fraction in tube["fractions"]:
fraction_data = Fractions.normalize_fraction_data(fraction)
fsli_is_duplicated = Fractions.check_duplicated_fsli_code(-1, fraction_data["fsli"])
if not fsli_is_duplicated["ok"]:
return {"ok": False, "pk": new_service.pk, "message": f"В анализе {fsli_is_duplicated['research_title']} есть такой же код ФСЛИ ({fraction_data['fsli']})"}
new_fraction = Fractions.create_fraction(fraction_data, new_service.pk, relation.pk)
log_data["fractions"][new_fraction.pk] = Fractions.as_json(new_fraction)
if need_log_data:
Expand Down Expand Up @@ -1485,6 +1495,14 @@ def create_fraction(fraction_data, service_pk, relation_pk):
new_fraction.save()
return new_fraction

@staticmethod
def check_duplicated_fsli_code(fraction_id: int, fsli_code):
fractions = Fractions.objects.filter(fsli=fsli_code).select_related('research').exclude(Q(pk=fraction_id) | Q(fsli=None))
if fractions.exists():
first_duplicated: Fractions = fractions.first()
return {"ok": False, "fraction_title": first_duplicated.title, "research_title": first_duplicated.research.title}
return {"ok": True}


class Absorption(models.Model):
"""
Expand Down
5 changes: 5 additions & 0 deletions l2-frontend/src/construct/ResearchDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ const updateResearch = async () => {
await getResearch();
emit('updateResearch');
} else {
await getResearch();
root.$emit('msg', 'error', message);
}
} else {
Expand All @@ -586,6 +587,10 @@ const createResearch = async () => {
await getResearch();
emit('updateResearch');
} else {
if (pk) {
research.value.pk = pk;
await getResearch();
}
root.$emit('msg', 'error', message);
}
} else {
Expand Down

0 comments on commit c1c9643

Please sign in to comment.