- Added CustomerConsistencyService to compare and sync customer data. - Introduced new API endpoints for data consistency checks and field synchronization. - Enhanced customer detail page with alert for discrepancies and modal for manual syncing. - Updated vTiger and e-conomic services to support fetching and updating customer data. - Added configuration options for enabling/disabling sync operations and automatic checks. - Implemented data normalization and error handling for robust comparisons. - Documented the new system and its features in DATA_CONSISTENCY_SYSTEM.md.
108 lines
2.5 KiB
Python
108 lines
2.5 KiB
Python
"""
|
|
Pydantic Models and Schemas
|
|
"""
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
|
|
class CustomerBase(BaseModel):
|
|
"""Base customer schema"""
|
|
name: str
|
|
email: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
address: Optional[str] = None
|
|
|
|
|
|
class CustomerCreate(CustomerBase):
|
|
"""Schema for creating a customer"""
|
|
pass
|
|
|
|
|
|
class CustomerUpdate(BaseModel):
|
|
"""Schema for updating a customer"""
|
|
name: Optional[str] = None
|
|
email: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
address: Optional[str] = None
|
|
cvr_number: Optional[str] = None
|
|
city: Optional[str] = None
|
|
postal_code: Optional[str] = None
|
|
country: Optional[str] = None
|
|
website: Optional[str] = None
|
|
mobile_phone: Optional[str] = None
|
|
invoice_email: Optional[str] = None
|
|
is_active: Optional[bool] = None
|
|
|
|
|
|
class Customer(CustomerBase):
|
|
"""Full customer schema"""
|
|
id: int
|
|
created_at: str # Changed from datetime to str for serialization
|
|
updated_at: Optional[str] = None # Changed from datetime to str for serialization
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class HardwareBase(BaseModel):
|
|
"""Base hardware schema"""
|
|
serial_number: str
|
|
model: str
|
|
customer_id: int
|
|
|
|
|
|
class HardwareCreate(HardwareBase):
|
|
"""Schema for creating hardware"""
|
|
pass
|
|
|
|
|
|
class Hardware(HardwareBase):
|
|
"""Full hardware schema"""
|
|
id: int
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class VendorBase(BaseModel):
|
|
"""Base vendor schema"""
|
|
name: str
|
|
cvr_number: Optional[str] = None
|
|
domain: Optional[str] = None
|
|
email: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
contact_person: Optional[str] = None
|
|
category: Optional[str] = None
|
|
notes: Optional[str] = None
|
|
|
|
|
|
class VendorCreate(VendorBase):
|
|
"""Schema for creating a vendor"""
|
|
pass
|
|
|
|
|
|
class VendorUpdate(BaseModel):
|
|
"""Schema for updating a vendor"""
|
|
name: Optional[str] = None
|
|
cvr_number: Optional[str] = None
|
|
domain: Optional[str] = None
|
|
email: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
contact_person: Optional[str] = None
|
|
category: Optional[str] = None
|
|
notes: Optional[str] = None
|
|
is_active: Optional[bool] = None
|
|
|
|
|
|
class Vendor(VendorBase):
|
|
"""Full vendor schema"""
|
|
id: int
|
|
is_active: bool = True
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|