diff --git a/app/pipeline/column_constants.py b/app/pipeline/column_constants.py index 690d829..2cc77b4 100644 --- a/app/pipeline/column_constants.py +++ b/app/pipeline/column_constants.py @@ -72,6 +72,7 @@ COL_EIO_ADDRESS_ONE_LINE = _index(167) # ЕИО и ценные бумаги. COL_EIO_INN = _index(163) COL_EIO_REG_PLACE_ONE_LINE = _index(178) +COL_EIO_REG_PLACE_STRUCTURED = _index(179) COL_CP_ISSUER_INN = _index(202) # Блоки схемы. diff --git a/app/pipeline/mapping.py b/app/pipeline/mapping.py index d9c9549..1eaf5b0 100644 --- a/app/pipeline/mapping.py +++ b/app/pipeline/mapping.py @@ -23,6 +23,7 @@ from .column_constants import ( COL_EIO_ADDRESS_ONE_LINE, COL_EIO_INN, COL_EIO_REG_PLACE_ONE_LINE, + COL_EIO_REG_PLACE_STRUCTURED, COL_EMPLOYEE_SIGN, COL_ESP_SIGN, COL_EXTRA_CODES, @@ -143,6 +144,10 @@ _PARTICIPANT_ADDRESS_BASE_PATHS = ( "УчастникФЛИП.СведФЛИП.АдрРег", "УчастникИНБОЮЛ.СведИНБОЮЛ.МестоДеятельностьИНБОЮЛ", ) +_ONE_LINE_STRUCTURED_PAIRS = ( + (COL_REG_PLACE_ONE_LINE, COL_REG_PLACE_STRUCTURED), + (COL_EIO_REG_PLACE_ONE_LINE, COL_EIO_REG_PLACE_STRUCTURED), +) def _bank_bik_candidate_keys(bank_block: str) -> tuple[str, ...]: @@ -454,6 +459,7 @@ def build_fixed_row_by_index( # группа не очистила их компоненты до проверки резидентства. _rule_address_one_line(row) _apply_structured_group_rules(row) + _apply_one_line_structured_pairs(row) if not is_continuation: _apply_business_rules( row, @@ -515,6 +521,13 @@ def _apply_structured_group_rules(row: dict[int, str]) -> None: _set(row, rule.structured_column, separator.join(values)) +def _apply_one_line_structured_pairs(row: dict[int, str]) -> None: + """Оставляет только однострочное значение, если заполнены обе версии поля.""" + for one_line_column, structured_column in _ONE_LINE_STRUCTURED_PAIRS: + if _get(row, one_line_column): + _set(row, structured_column, "") + + def _merge_fields( operation_fields: dict[str, str], participant_fields: dict[str, str], diff --git a/tests/unit/test_mapping.py b/tests/unit/test_mapping.py index 3f61f7f..71583d3 100644 --- a/tests/unit/test_mapping.py +++ b/tests/unit/test_mapping.py @@ -947,6 +947,59 @@ def test_col153_uses_only_legal_entity_registration_address_components() -> None assert row[153] == "675520, 643, 10, Благовещенский р-н, Чигири с, Зеленая ул, 1" +def test_col153_is_cleared_when_registration_address_one_line_exists() -> None: + row = build_fixed_row_by_index( + file_name="f.xml", + record_id="R1", + operation_index=1, + operation_fields={}, + participant_fields={ + "УчастникЮЛ.СведЮЛ.АдрРегЮЛ.АдресСтрока": "Москва, Тверская, 1", + "УчастникЮЛ.СведЮЛ.АдрРегЮЛ.Индекс": "123456", + "УчастникЮЛ.СведЮЛ.АдрРегЮЛ.КодОКСМ": "643", + "УчастникЮЛ.СведЮЛ.АдрРегЮЛ.Пункт": "Москва", + }, + ) + + assert row[152] == "Москва, Тверская, 1" + assert row[153] == "" + + +def test_col179_is_cleared_when_eio_registration_one_line_exists() -> None: + row = build_fixed_row_by_index( + file_name="f.xml", + record_id="R1", + operation_index=1, + operation_fields={}, + participant_fields={ + "УчастникЮЛ.СведЕИО.ЮЛЕИО.АдресСтрока": "Москва, Арбат, 1", + "УчастникЮЛ.СведЕИО.ЮЛЕИО.АдрРегЮЛ.Индекс": "123456", + "УчастникЮЛ.СведЕИО.ЮЛЕИО.АдрРегЮЛ.КодОКСМ": "643", + "УчастникЮЛ.СведЕИО.ЮЛЕИО.АдрРегЮЛ.Пункт": "Москва", + }, + ) + + assert row[178] == "Москва, Арбат, 1" + assert row[179] == "" + + +def test_col179_keeps_structured_eio_registration_without_one_line() -> None: + row = build_fixed_row_by_index( + file_name="f.xml", + record_id="R1", + operation_index=1, + operation_fields={}, + participant_fields={ + "УчастникЮЛ.СведЕИО.ЮЛЕИО.АдрРегЮЛ.Индекс": "123456", + "УчастникЮЛ.СведЕИО.ЮЛЕИО.АдрРегЮЛ.КодОКСМ": "643", + "УчастникЮЛ.СведЕИО.ЮЛЕИО.АдрРегЮЛ.Пункт": "Москва", + }, + ) + + assert row[178] == "" + assert row[179] == "123456, 643, Москва" + + def test_cash_columns_cleared_for_cashless_transfer_type_1() -> None: row = build_fixed_row_by_index( file_name="f.xml",