26 lines
784 B
Python
26 lines
784 B
Python
# backend/app/modules/opening_balances/schema.py
|
|
from pydantic import BaseModel, field_validator
|
|
|
|
class OpeningBalanceCreate(BaseModel):
|
|
fiscal_year: int
|
|
account_id: int
|
|
opening_debit: float = 0
|
|
opening_credit: float = 0
|
|
|
|
@field_validator("fiscal_year")
|
|
@classmethod
|
|
def validate_year(cls, v: int):
|
|
if v < 2000 or v > 2100:
|
|
raise ValueError("会计年度不正确")
|
|
return v
|
|
|
|
@field_validator("opening_credit")
|
|
@classmethod
|
|
def validate_balance(cls, v, info):
|
|
debit = info.data.get("opening_debit", 0)
|
|
if debit > 0 and v > 0:
|
|
raise ValueError("借方和贷方不能同时输入金额")
|
|
if debit < 0 or v < 0:
|
|
raise ValueError("金额不能为负数")
|
|
return v
|