forked from erp-dev/erp
feat: change segment_size to decimal in Product model
This commit is contained in:
@@ -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