Skip to content

Commit

Permalink
Merge pull request #3694 from mikhailprivalov/unit-to-fraction
Browse files Browse the repository at this point in the history
Скрипт - импорт тестов
  • Loading branch information
urchinpro authored Apr 10, 2024
2 parents a44d205 + 962118c commit a56daff
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions directory/management/commands/import_fractions_in_research.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from django.core.management.base import BaseCommand
from django.db.models import Q
from openpyxl.workbook import Workbook

from appconf.manager import SettingManager
from directory.models import Researches, Fractions, Unit
from openpyxl import load_workbook

from external_system.models import FsliRefbookTest


class Command(BaseCommand):
def add_arguments(self, parser):
Expand Down Expand Up @@ -34,7 +37,7 @@ def handle(self, *args, **kwargs):
code = cells.index("Код")
starts = True
else:
research_nmy_code = cells[research].split(' - ')[0]
research_nmy_code = cells[research].split(' - ')[0].strip()
if research_nmy_code != "None":
fraction_fsli_code = cells[fsli].split(' ')[0]
current_research = Researches.objects.filter(code=research_nmy_code).first()
Expand All @@ -49,19 +52,29 @@ def handle(self, *args, **kwargs):
relation_id = fraction.relation_id
sort_weight = fraction.sort_weight
if need_add_fractions:
unit_string = cells[unit].strip() if cells[unit] != "None" else ""
unit_id = None
unit_db = Unit.objects.filter(short_title=cells[unit].strip()).first()
unit_db = None
if unit_string:
unit_db = Unit.objects.filter(Q(short_title__iexact=unit_string) | Q(short_title__icontains=unit_string) | Q(title__icontains=unit_string)).first()
else:
fsli_test = FsliRefbookTest.objects.filter(code_fsli=fraction_fsli_code).first()
if fsli_test and fsli_test.unit:
unit_db = Unit.objects.filter(
Q(short_title__iexact=fsli_test.unit) | Q(short_title__icontains=fsli_test.unit) | Q(title__icontains=fsli_test.unit)
).first()
if unit_db:
unit_id = unit_db.pk
if relation_id is not None:
new_fraction = Fractions(
research_id=current_research.pk,
relation_id=relation_id,
title=cells[title],
title=cells[title].strip(),
unit_id=unit_id,
units=unit_string,
fsli=fraction_fsli_code,
sort_weight=sort_weight + 1,
external_code=cells[code],
external_code=cells[code].strip(),
)
new_fraction.save()
self.stdout.write(f'Услуге: {current_research.title} добавлена фракция: {new_fraction.title}')
Expand Down

0 comments on commit a56daff

Please sign in to comment.