From 5d16915badd13ccd67140da887f876d7da59429d Mon Sep 17 00:00:00 2001 From: Raykov-MS Date: Tue, 30 Jun 2026 17:24:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F=20location=5Fform=20=D1=8D=D1=82=D0=BE?= =?UTF-8?q?=20=D0=B8=20=D0=B5=D1=81=D1=82=D1=8C=20placement=5Ftype,=20?= =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20location=5Fform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/alembic/versions/sql/0002_functions.sql | 22 +++++++-------------- api/requirements-dev.txt | 1 + api/src/api/v1/vsp.py | 6 +++--- api/src/db/models/vsp.py | 1 - api/src/domain/schemas.py | 4 +--- api/src/repository/vsp_repository.py | 14 ++++++------- api/src/services/vsp_service.py | 14 ++++++------- api/tests/integration/test_vsp.py | 10 +++++----- 8 files changed, 30 insertions(+), 42 deletions(-) diff --git a/api/alembic/versions/sql/0002_functions.sql b/api/alembic/versions/sql/0002_functions.sql index c19ea53..119d335 100644 --- a/api/alembic/versions/sql/0002_functions.sql +++ b/api/alembic/versions/sql/0002_functions.sql @@ -1123,9 +1123,9 @@ END; $function$ ; --- DROP FUNCTION v3.add_vsp(int4, varchar, varchar, varchar, date, varchar, int4, numeric, date, bool, bool, varchar, int4, varchar, text, varchar, varchar, date); +-- DROP FUNCTION v3.add_vsp(int4, varchar, varchar, varchar, date, varchar, int4, numeric, date, bool, bool, varchar, int4, varchar, text, varchar, date); -CREATE OR REPLACE FUNCTION v3.add_vsp(p_branch_id integer, p_reg_number character varying DEFAULT NULL::character varying, p_address character varying DEFAULT NULL::character varying, p_format character varying DEFAULT NULL::character varying, p_opened_at date DEFAULT NULL::date, p_placement_type character varying DEFAULT NULL::character varying, p_staff_count integer DEFAULT NULL::integer, p_total_area numeric DEFAULT NULL::numeric, p_closed_at date DEFAULT NULL::date, p_is_active boolean DEFAULT true, p_is_deleted boolean DEFAULT false, p_system_code character varying DEFAULT NULL::character varying, p_created_by integer DEFAULT NULL::integer, p_vsp_type character varying DEFAULT NULL::character varying, p_notes text DEFAULT NULL::text, p_location_form character varying DEFAULT NULL::character varying, p_rent_contract_num character varying DEFAULT NULL::character varying, p_rent_end_date date DEFAULT NULL::date) +CREATE OR REPLACE FUNCTION v3.add_vsp(p_branch_id integer, p_reg_number character varying DEFAULT NULL::character varying, p_address character varying DEFAULT NULL::character varying, p_format character varying DEFAULT NULL::character varying, p_opened_at date DEFAULT NULL::date, p_placement_type character varying DEFAULT NULL::character varying, p_staff_count integer DEFAULT NULL::integer, p_total_area numeric DEFAULT NULL::numeric, p_closed_at date DEFAULT NULL::date, p_is_active boolean DEFAULT true, p_is_deleted boolean DEFAULT false, p_system_code character varying DEFAULT NULL::character varying, p_created_by integer DEFAULT NULL::integer, p_vsp_type character varying DEFAULT NULL::character varying, p_notes text DEFAULT NULL::text, p_rent_contract_num character varying DEFAULT NULL::character varying, p_rent_end_date date DEFAULT NULL::date) RETURNS integer LANGUAGE plpgsql AS $function$ @@ -1153,12 +1153,12 @@ BEGIN (branch_id, reg_number, address, format, opened_at, placement_type, staff_count, total_area, closed_at, is_active, is_deleted, system_code, created_by, - vsp_type, notes, location_form, rent_contract_num, rent_end_date) + vsp_type, notes, rent_contract_num, rent_end_date) VALUES (p_branch_id, p_reg_number, p_address, p_format, p_opened_at, p_placement_type, p_staff_count, p_total_area, p_closed_at, p_is_active, p_is_deleted, p_system_code, p_created_by, - p_vsp_type, p_notes, p_location_form, p_rent_contract_num, p_rent_end_date) + p_vsp_type, p_notes, p_rent_contract_num, p_rent_end_date) RETURNING id INTO v_id; PERFORM v3.log_event( @@ -1182,7 +1182,6 @@ BEGIN 'created_by', p_created_by, 'vsp_type', p_vsp_type, 'notes', p_notes, - 'location_form', p_location_form, 'rent_contract_num', p_rent_contract_num, 'rent_end_date', v3._diff_val(p_rent_end_date), 'user_email', v_actor_email, @@ -2747,9 +2746,9 @@ END; $function$ ; --- DROP FUNCTION v3.upd_vsp(int4, int4, varchar, varchar, varchar, date, varchar, int4, numeric, date, bool, bool, varchar, int4, varchar, text, varchar, varchar, date); +-- DROP FUNCTION v3.upd_vsp(int4, int4, varchar, varchar, varchar, date, varchar, int4, numeric, date, bool, bool, varchar, int4, varchar, text, varchar, date); -CREATE OR REPLACE FUNCTION v3.upd_vsp(p_vsp_id integer, p_branch_id integer DEFAULT NULL::integer, p_reg_number character varying DEFAULT NULL::character varying, p_address character varying DEFAULT NULL::character varying, p_format character varying DEFAULT NULL::character varying, p_opened_at date DEFAULT NULL::date, p_placement_type character varying DEFAULT NULL::character varying, p_staff_count integer DEFAULT NULL::integer, p_total_area numeric DEFAULT NULL::numeric, p_closed_at date DEFAULT NULL::date, p_is_active boolean DEFAULT NULL::boolean, p_is_deleted boolean DEFAULT NULL::boolean, p_system_code character varying DEFAULT NULL::character varying, p_updated_by integer DEFAULT NULL::integer, p_vsp_type character varying DEFAULT NULL::character varying, p_notes text DEFAULT NULL::text, p_location_form character varying DEFAULT NULL::character varying, p_rent_contract_num character varying DEFAULT NULL::character varying, p_rent_end_date date DEFAULT NULL::date) +CREATE OR REPLACE FUNCTION v3.upd_vsp(p_vsp_id integer, p_branch_id integer DEFAULT NULL::integer, p_reg_number character varying DEFAULT NULL::character varying, p_address character varying DEFAULT NULL::character varying, p_format character varying DEFAULT NULL::character varying, p_opened_at date DEFAULT NULL::date, p_placement_type character varying DEFAULT NULL::character varying, p_staff_count integer DEFAULT NULL::integer, p_total_area numeric DEFAULT NULL::numeric, p_closed_at date DEFAULT NULL::date, p_is_active boolean DEFAULT NULL::boolean, p_is_deleted boolean DEFAULT NULL::boolean, p_system_code character varying DEFAULT NULL::character varying, p_updated_by integer DEFAULT NULL::integer, p_vsp_type character varying DEFAULT NULL::character varying, p_notes text DEFAULT NULL::text, p_rent_contract_num character varying DEFAULT NULL::character varying, p_rent_end_date date DEFAULT NULL::date) RETURNS void LANGUAGE plpgsql AS $function$ @@ -2767,7 +2766,7 @@ BEGIN SELECT v.branch_id, v.reg_number, v.address, v.format, v.opened_at, v.placement_type, v.staff_count, v.total_area, v.closed_at, v.is_active, v.is_deleted, v.system_code, - v.vsp_type, v.notes, v.location_form, v.rent_contract_num, v.rent_end_date + v.vsp_type, v.notes, v.rent_contract_num, v.rent_end_date INTO v_old FROM v3.vsp v WHERE v.id = p_vsp_id; @@ -2900,13 +2899,6 @@ BEGIN 'after', v3._diff_val(p_notes))); END IF; - IF p_location_form IS NOT NULL AND p_location_form IS DISTINCT FROM v_old.location_form THEN - UPDATE v3.vsp SET location_form = p_location_form WHERE id = p_vsp_id; - v_changes := v_changes || jsonb_build_object('location_form', - jsonb_build_object('before', v3._diff_val(v_old.location_form), - 'after', v3._diff_val(p_location_form))); - END IF; - IF p_rent_contract_num IS NOT NULL AND p_rent_contract_num IS DISTINCT FROM v_old.rent_contract_num THEN UPDATE v3.vsp SET rent_contract_num = p_rent_contract_num WHERE id = p_vsp_id; v_changes := v_changes || jsonb_build_object('rent_contract_num', diff --git a/api/requirements-dev.txt b/api/requirements-dev.txt index bc6fc87..faa293a 100644 --- a/api/requirements-dev.txt +++ b/api/requirements-dev.txt @@ -14,3 +14,4 @@ aiosqlite==0.20.0 asyncpg==0.30.0 pytest==8.3.2 pytest-asyncio==0.24.0 +openpyxl==3.1.5 diff --git a/api/src/api/v1/vsp.py b/api/src/api/v1/vsp.py index 1cd34c6..4ab76da 100644 --- a/api/src/api/v1/vsp.py +++ b/api/src/api/v1/vsp.py @@ -27,7 +27,7 @@ async def get_vsp( ssp_id: int | None = None, open_date_start: date | None = None, open_date_end: date | None = None, - location_form: str | None = None, + placement_type: str | None = None, staff_count_min: int | None = None, staff_count_max: int | None = None, db: AsyncSession = Depends(get_db), @@ -42,7 +42,7 @@ async def get_vsp( ssp_id=ssp_id, open_date_start=open_date_start, open_date_end=open_date_end, - location_form=location_form, + placement_type=placement_type, staff_count_min=staff_count_min, staff_count_max=staff_count_max, load_org_unit=True, @@ -89,7 +89,7 @@ async def export_info( ssp_ids=body.ssp_ids, open_date_start=body.open_date_start, open_date_end=body.open_date_end, - location_form=body.location_form, + placement_type=body.placement_type, staff_count_min=body.staff_count_min, staff_count_max=body.staff_count_max, ) diff --git a/api/src/db/models/vsp.py b/api/src/db/models/vsp.py index 5866718..a907fa5 100644 --- a/api/src/db/models/vsp.py +++ b/api/src/db/models/vsp.py @@ -45,7 +45,6 @@ class Vsp(Base): ) vsp_type: Mapped[str | None] = mapped_column(String(100), nullable=True) notes: Mapped[str | None] = mapped_column(Text, nullable=True) - location_form: Mapped[str | None] = mapped_column(String, nullable=True) rent_contract_num: Mapped[str | None] = mapped_column(String, nullable=True) rent_end_date : Mapped[date | None]= mapped_column(Date, nullable=True) diff --git a/api/src/domain/schemas.py b/api/src/domain/schemas.py index ce441d3..6b2dea1 100644 --- a/api/src/domain/schemas.py +++ b/api/src/domain/schemas.py @@ -492,7 +492,6 @@ class VSPBase(BaseModel): notes: Optional[str] = Field(None, description="Примечания") placement_type: Optional[str] = Field(None, description="Тип размещения") staff_count: Optional[int] = Field(None, description="Штатная численность") - location_form: Optional[str] = Field(None, description="Форма расположения") area: Optional[float] = Field( None, description="Арендная площадь", @@ -542,7 +541,6 @@ class VSPEditBase(BaseModel): notes: Optional[str] = Field(None, description="Примечания") placement_type: Optional[str] = Field(None, description="Тип размещения") staff_count: Optional[int] = Field(None, description="Штатная численность") - location_form: Optional[str] = Field(None, description="Форма расположения") total_area: Optional[float] = Field( None, description="Арендная площадь", @@ -613,7 +611,7 @@ class VSPExportRequest(BaseModel): ssp_ids: Optional[List[int]] = None open_date_start: Optional[date] = None open_date_end: Optional[date] = None - location_form: Optional[str] = None + placement_type: Optional[str] = None staff_count_min: Optional[int] = None staff_count_max: Optional[int] = None diff --git a/api/src/repository/vsp_repository.py b/api/src/repository/vsp_repository.py index 51ef4a0..a6b1b94 100644 --- a/api/src/repository/vsp_repository.py +++ b/api/src/repository/vsp_repository.py @@ -36,7 +36,7 @@ class VSPRepository: ssp_ids: list[int] | None = None, open_date_start: date | None = None, open_date_end: date | None = None, - location_form: str | None = None, + placement_type: str | None = None, staff_count_min: int | None = None, staff_count_max: int | None = None, is_active: bool | None = True, @@ -53,7 +53,7 @@ class VSPRepository: filters = [ ("registration_number", registration_number), ("address", address), - ("location_form", location_form), + ("placement_type", placement_type), ("open_date_start", open_date_start), ("open_date_end", open_date_end), ("staff_count_min", staff_count_min), @@ -67,8 +67,8 @@ class VSPRepository: queries.append(Vsp.reg_number.ilike(f"%{value}%")) case ("address", str(value)) if value: queries.append(Vsp.address.ilike(f"%{value}%")) - case ("location_form", str(value)) if value: - queries.append(Vsp.location_form.ilike(f"%{value}%")) + case ("placement_type", str(value)) if value: + queries.append(Vsp.placement_type.ilike(f"%{value}%")) case ("open_date_start", value) if value is not None: queries.append(Vsp.opened_at >= value) case ("open_date_end", value) if value is not None: @@ -125,7 +125,7 @@ class VSPRepository: :p_opened_at, :p_placement_type, :p_staff_count, :p_total_area, :p_closed_at, :p_is_active, :p_is_deleted, :p_system_code, :p_created_by, :p_vsp_type, :p_notes, - :p_location_form, :p_rent_contract_num, :p_rent_end_date + :p_rent_contract_num, :p_rent_end_date ) """), { @@ -144,7 +144,6 @@ class VSPRepository: "p_created_by": created_by, "p_vsp_type": data.get("vsp_type"), "p_notes": data.get("notes"), - "p_location_form": data.get("location_form"), "p_rent_contract_num": data.get("rent_contract_num"), "p_rent_end_date": data.get("rent_end_date"), } @@ -178,7 +177,6 @@ class VSPRepository: "placement_type": "p_placement_type", "staff_count": "p_staff_count", "notes": "p_notes", - "location_form": "p_location_form", "total_area": "p_total_area", "rent_contract_num": "p_rent_contract_num", "rent_end_date": "p_rent_end_date", @@ -198,7 +196,7 @@ class VSPRepository: :p_format, :p_opened_at, :p_placement_type, :p_staff_count, :p_total_area, :p_closed_at, :p_is_active, :p_is_deleted, :p_system_code, :p_updated_by, :p_vsp_type, :p_notes, - :p_location_form, :p_rent_contract_num, :p_rent_end_date + :p_rent_contract_num, :p_rent_end_date ) """), params, diff --git a/api/src/services/vsp_service.py b/api/src/services/vsp_service.py index d84dd40..822759d 100644 --- a/api/src/services/vsp_service.py +++ b/api/src/services/vsp_service.py @@ -20,7 +20,7 @@ _info_close_sync_lock = asyncio.Lock() class VSPService: EXECUTOR_EDITABLE_FIELDS = { - "location_form", + "placement_type", "staff_count", "total_area", "rent_contract_num", @@ -54,7 +54,7 @@ class VSPService: ssp_ids: list[int] | None = None, open_date_start: date | None = None, open_date_end: date | None = None, - location_form: str | None = None, + placement_type: str | None = None, staff_count_min: int | None = None, staff_count_max: int | None = None, is_active: bool | None = None, @@ -84,7 +84,7 @@ class VSPService: ssp_ids=effective_ssp_ids, open_date_start=open_date_start, open_date_end=open_date_end, - location_form=location_form, + placement_type=placement_type, staff_count_min=staff_count_min, staff_count_max=staff_count_max, is_active=is_active, @@ -154,7 +154,7 @@ class VSPService: ssp_ids: list[int] | None = None, open_date_start: date | None = None, open_date_end: date | None = None, - location_form: str | None = None, + placement_type: str | None = None, staff_count_min: int | None = None, staff_count_max: int | None = None, ) -> tuple[io.BytesIO, str]: @@ -165,7 +165,7 @@ class VSPService: ssp_ids=ssp_ids, open_date_start=open_date_start, open_date_end=open_date_end, - location_form=location_form, + placement_type=placement_type, staff_count_min=staff_count_min, staff_count_max=staff_count_max, is_active=None, @@ -188,7 +188,7 @@ class VSPService: "open_date", "close_date", "notes", - "location_form", + "placement_type", "staff_count", "area", "rent_contract_num", @@ -215,7 +215,7 @@ class VSPService: item.opened_at.isoformat() if item.opened_at else None, item.closed_at.isoformat() if item.closed_at else None, item.notes or None, - item.location_form or None, + item.placement_type or None, item.staff_count if item.staff_count is not None else None, float(item.total_area) if item.total_area is not None else None, item.rent_contract_num or None, diff --git a/api/tests/integration/test_vsp.py b/api/tests/integration/test_vsp.py index 2dc5559..7fd80f6 100644 --- a/api/tests/integration/test_vsp.py +++ b/api/tests/integration/test_vsp.py @@ -40,10 +40,10 @@ def test_vsp_dropdown_smoke(client, admin_tokens, auth_headers): @pytest.mark.parametrize( "params, count", [ - ([("ssp_id", 2)], 1), + ([("ssp_id", 2)], 2), ([("form_id", 1)], 0), - ([("form_id", 2)], 1), - ([("ssp_id", 2), ("form_id", 1)], 1), + ([("form_id", 2)], 2), + ([("ssp_id", 2), ("form_id", 1)], 2), ] ) def test_vsp_dropdown_with_filter(client, admin_tokens, auth_headers, params, count): @@ -110,7 +110,7 @@ def test_vsp_create_with_all_fields(client, admin_tokens, auth_headers): "close_date": "2025-12-31", "approved_format": "Стандарт", "notes": "Тестовое примечание", - "location_form": "Встроенное", + "placement_type": "Аренда", "staff_count": 10, "area": 150.5, "rent_contract_num": "Д-123/24", @@ -127,7 +127,7 @@ def test_vsp_create_with_all_fields(client, admin_tokens, auth_headers): assert payload["result"]["open_date"] == "2024-01-15" assert payload["result"]["close_date"] == "2025-12-31" assert payload["result"]["approved_format"] == "Стандарт" - assert payload["result"]["location_form"] == "Встроенное" + assert payload["result"]["placement_type"] == "Аренда" assert payload["result"]["staff_count"] == 10 assert payload["result"]["area"] == 150.5 assert payload["result"]["rent_contract_num"] == "Д-123/24"