25 lines
756 B
Python
25 lines
756 B
Python
from pydantic import BaseModel, field_validator
|
|
from typing import Optional
|
|
|
|
|
|
class LigneDocument(BaseModel):
|
|
article_code: str
|
|
quantite: float
|
|
prix_unitaire_ht: Optional[float] = None
|
|
remise_pourcentage: Optional[float] = 0.0
|
|
|
|
@field_validator("article_code", mode="before")
|
|
def strip_insecables(cls, v):
|
|
return v.replace("\xa0", "").strip()
|
|
|
|
@field_validator("quantite")
|
|
def validate_quantite(cls, v):
|
|
if v <= 0:
|
|
raise ValueError("La quantité doit être positive")
|
|
return v
|
|
|
|
@field_validator("remise_pourcentage")
|
|
def validate_remise(cls, v):
|
|
if v is not None and (v < 0 or v > 100):
|
|
raise ValueError("La remise doit être entre 0 et 100")
|
|
return v
|