Срез 1: справочники (API), импорт из ЕЦП CRM, policy видимости, администрирование #6

Merged
aep merged 51 commits from feat/5-slice-1-directories into main 2026-10-05 10:00:05 +03:00
2 changed files with 33 additions and 1 deletions
Showing only changes of commit 462a30fcf6 - Show all commits

View File

@ -293,8 +293,10 @@ class LegalEntityService:
if field not in data.model_fields_set:
continue
value = getattr(data, field)
if value == getattr(entity, field):
continue # то же значение — не изменение (Review Focus 1), даже если филиал ЮЛ чужой для пользователя
if field == "regional_office_id":
value = office_for_create(self._scope, value)
value = office_for_create(self._scope, value) # policy — только для фактической смены филиала
if value != getattr(entity, field):
changes[field] = value
if "entity_type" in changes:

View File

@ -533,3 +533,33 @@ async def test_failed_move_rolls_back_everything(
assert reloaded_member.valid_to is None
assert await _history_count(seeded) == 0
assert not await _events(seeded, AuditAction.LEGAL_ENTITY_CHANGE, AuditAction.MEMBERSHIP_CHANGE)
@pytest.mark.integration
async def test_branch_patch_with_unchanged_foreign_office_is_not_rejected(
auth_client: AuthClientFactory, seeded: AsyncSession
) -> None:
"""I-1 (Review Focus 1): ЮЛ в ГК своего филиала с чужим `regional_office_id`; форма шлёт тот же филиал — не 422."""
rostov, krasnodar = await _office(seeded, ROSTOV), await _office(seeded, KRASNODAR)
group = await make_company_group(seeded, name="ГК Ростов", office=rostov)
entity = await make_legal_entity(seeded, name="ООО Старое", group=group, office=krasnodar) # как создал бы ГО
client = await auth_client("ka_rf@armka.local")
same_office_only = await client.patch(f"{ENTITIES}/{entity.id}", json={"regional_office_id": str(krasnodar.id)})
assert same_office_only.status_code == HTTP_OK, same_office_only.text
assert same_office_only.json()["regional_office_id"] == str(krasnodar.id)
assert await _history_count(seeded) == 0
assert not await _events(seeded, AuditAction.LEGAL_ENTITY_CHANGE)
renamed = await client.patch(
f"{ENTITIES}/{entity.id}", json={"name": "ООО Новое", "regional_office_id": str(krasnodar.id)}
)
assert renamed.status_code == HTTP_OK, renamed.text
assert (renamed.json()["name"], renamed.json()["regional_office_id"]) == ("ООО Новое", str(krasnodar.id))
assert await _history_count(seeded) == 1
(event,) = await _events(seeded, AuditAction.LEGAL_ENTITY_CHANGE)
assert (event.before_value, event.after_value) == ({"name": "ООО Старое"}, {"name": "ООО Новое"})
to_foreign = await client.patch(f"{ENTITIES}/{entity.id}", json={"regional_office_id": None})
assert to_foreign.status_code == HTTP_OK # явный null у филиала — свой филиал (это изменение)
assert to_foreign.json()["regional_office_id"] == str(rostov.id)