forked from erp-dev/erp
feat: change segment_size to decimal in Product model
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from decimal import Decimal
|
||||
from typing import Any, List
|
||||
|
||||
from pydantic import BaseModel, Field, computed_field
|
||||
@@ -13,7 +14,7 @@ class Product(BaseModel):
|
||||
rowid: str
|
||||
name: str
|
||||
pieces: int | None
|
||||
segment_size: int | None
|
||||
segment_size: Decimal | None
|
||||
unit: str | None
|
||||
color: str | None
|
||||
width: str | None = None
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from typing import Any
|
||||
|
||||
from .mappings import customer_type_map, fabric_type_map, product_type_map
|
||||
@@ -26,8 +27,16 @@ def pick_product(fields: dict[str, Any]) -> Product:
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
def _to_decimal(value):
|
||||
if value in ("", None):
|
||||
return None
|
||||
try:
|
||||
return Decimal(str(value))
|
||||
except (InvalidOperation, TypeError, ValueError):
|
||||
return None
|
||||
|
||||
data["pieces"] = _to_int(data.get("pieces"))
|
||||
data["segment_size"] = _to_int(data.get("segment_size"))
|
||||
data["segment_size"] = _to_decimal(data.get("segment_size"))
|
||||
|
||||
return Product(**data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user