PUT …/goodwill {rows: [...]} вместо построчного PUT …/goodwill/{head}/{sub}: все строки
проверяются до записи, ошибка любой (NOT_FOUND, INVALID_SHARE, COMMENT_REQUIRED,
MONEY_OUT_OF_RANGE, DUPLICATE_ROW) несёт ключ пары и откатывает пакет; неизменённые
строки не перезаписываются и аудит не пишут (DOC-259025 §5.1 п. 4).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
2.5 KiB
Python
90 lines
2.5 KiB
Python
"""Контракт гудвилла: денежные суммы в рублях, nullable расчёты."""
|
|
|
|
import datetime
|
|
from decimal import Decimal
|
|
from typing import Annotated, Literal
|
|
from uuid import UUID
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, PlainSerializer
|
|
|
|
from src.schemas.consolidations import RefOut
|
|
from src.schemas.corrections import Money
|
|
|
|
Share = Annotated[Decimal, PlainSerializer(lambda v: format(v, ".2f"), return_type=str, when_used="json")]
|
|
|
|
|
|
GoodwillSign = Literal["all", "positive", "negative", "zero"]
|
|
|
|
|
|
class WarningOut(BaseModel):
|
|
code: str
|
|
message: str
|
|
|
|
|
|
class GoodwillRowOut(BaseModel):
|
|
head_legal_entity: RefOut
|
|
subsidiary_legal_entity: RefOut
|
|
ownership_share: Share | None
|
|
financial_investment_amount: Money | None
|
|
charter_capital_amount: Money | None
|
|
additional_capital_amount: Money | None
|
|
participation_amount: Money | None
|
|
goodwill_amount: Money | None
|
|
include_in_kfo: bool
|
|
comment: str | None
|
|
has_investments: bool
|
|
warnings: list[WarningOut]
|
|
updated_by: RefOut | None
|
|
updated_at: datetime.datetime | None
|
|
|
|
|
|
class GoodwillTotalsOut(BaseModel):
|
|
financial_investment_amount: Money
|
|
charter_capital_amount: Money
|
|
participation_amount: Money
|
|
goodwill_amount: Money
|
|
goodwill_in_kfo_amount: Money
|
|
|
|
|
|
class GoodwillGroupOut(BaseModel):
|
|
"""Итог «Всего» блока одной ГО."""
|
|
|
|
head_legal_entity: RefOut
|
|
totals: GoodwillTotalsOut
|
|
|
|
|
|
class GoodwillTableOut(BaseModel):
|
|
version_id: UUID
|
|
goodwill_enabled: bool
|
|
editable: bool
|
|
read_only_reason: Literal["VERSION_NOT_EDITABLE", "LOCK_REQUIRED", "LOCKED_BY_OTHER"] | None
|
|
rows: list[GoodwillRowOut]
|
|
groups: list[GoodwillGroupOut]
|
|
totals: GoodwillTotalsOut
|
|
|
|
|
|
class GoodwillRowIn(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
ownership_share: str | None
|
|
include_in_kfo: bool
|
|
comment: str | None = Field(default=None, max_length=1000)
|
|
|
|
|
|
class GoodwillRowKeyIn(GoodwillRowIn):
|
|
"""Строка пакетного сохранения: пара ГО → ДО и ручной ввод."""
|
|
|
|
head_legal_entity_id: UUID
|
|
subsidiary_legal_entity_id: UUID
|
|
|
|
|
|
class GoodwillBatchIn(BaseModel):
|
|
"""Пакет строк таблицы гудвилла; сохраняется целиком или не сохраняется."""
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
rows: list[GoodwillRowKeyIn] = Field(min_length=1)
|
|
|
|
|
|
class GoodwillSettingsIn(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
goodwill_enabled: bool
|