fix(directories): PATCH ЮЛ с прежним чужим филиалом — не 422 (I-1)
`office_for_create` применяется к `regional_office_id` только при фактической смене филиала: тело с тем же значением — no-op (Review Focus 1), правка `name` в том же запросе проходит. Тест на ЮЛ в ГК своего филиала с чужим `regional_office_id`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vJkmBGKKqMoEMzvsXG3y2
This commit is contained in:
parent
347b46e32c
commit
462a30fcf6
@ -293,8 +293,10 @@ class LegalEntityService:
|
|||||||
if field not in data.model_fields_set:
|
if field not in data.model_fields_set:
|
||||||
continue
|
continue
|
||||||
value = getattr(data, field)
|
value = getattr(data, field)
|
||||||
|
if value == getattr(entity, field):
|
||||||
|
continue # то же значение — не изменение (Review Focus 1), даже если филиал ЮЛ чужой для пользователя
|
||||||
if field == "regional_office_id":
|
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):
|
if value != getattr(entity, field):
|
||||||
changes[field] = value
|
changes[field] = value
|
||||||
if "entity_type" in changes:
|
if "entity_type" in changes:
|
||||||
|
|||||||
@ -533,3 +533,33 @@ async def test_failed_move_rolls_back_everything(
|
|||||||
assert reloaded_member.valid_to is None
|
assert reloaded_member.valid_to is None
|
||||||
assert await _history_count(seeded) == 0
|
assert await _history_count(seeded) == 0
|
||||||
assert not await _events(seeded, AuditAction.LEGAL_ENTITY_CHANGE, AuditAction.MEMBERSHIP_CHANGE)
|
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user