feat(mappings): strict validation + silent CSV skip for missing CODMAT
Add Pydantic validators and service-level checks that reject empty SKU/CODMAT on create/edit (400). CSV import now silently skips rows without CODMAT and counts them in skipped_no_codmat instead of treating them as errors. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ from fastapi import APIRouter, Query, Request, UploadFile, File
|
||||
from fastapi.responses import StreamingResponse, HTMLResponse, JSONResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from fastapi import HTTPException
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, validator
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
import io
|
||||
@@ -21,6 +21,12 @@ class MappingCreate(BaseModel):
|
||||
cantitate_roa: float = 1
|
||||
procent_pret: float = 100
|
||||
|
||||
@validator('sku', 'codmat')
|
||||
def not_empty(cls, v):
|
||||
if not v or not v.strip():
|
||||
raise ValueError('nu poate fi gol')
|
||||
return v.strip()
|
||||
|
||||
class MappingUpdate(BaseModel):
|
||||
cantitate_roa: Optional[float] = None
|
||||
procent_pret: Optional[float] = None
|
||||
@@ -32,6 +38,12 @@ class MappingEdit(BaseModel):
|
||||
cantitate_roa: float = 1
|
||||
procent_pret: float = 100
|
||||
|
||||
@validator('new_sku', 'new_codmat')
|
||||
def not_empty(cls, v):
|
||||
if not v or not v.strip():
|
||||
raise ValueError('nu poate fi gol')
|
||||
return v.strip()
|
||||
|
||||
class MappingLine(BaseModel):
|
||||
codmat: str
|
||||
cantitate_roa: float = 1
|
||||
|
||||
Reference in New Issue
Block a user