1
0
forked from erp-dev/erp

feat: refactor flower.utils to sub package, added some sync api in package, added plate_order sync result model but relation of plate_order was not query (do it next step)

This commit is contained in:
2025-12-17 17:37:39 +08:00
parent 51fad953c3
commit 98d797221a
19 changed files with 1422 additions and 403 deletions

View File

@@ -0,0 +1,39 @@
from __future__ import annotations
from typing import Any
from .mappings import customer_type_map, fabric_type_map, product_type_map
from .models import Customer, Fabric, Product
def pick_customer(fields: dict[str, Any]) -> Customer:
"""从字段字典中提取客户信息"""
data = {k: fields.get(v, "") for k, v in customer_type_map.items()}
return Customer(**data)
def pick_product(fields: dict[str, Any]) -> Product:
"""从字段字典中提取产品信息"""
data = {k: fields.get(v, "") for k, v in product_type_map.items()}
def _to_int(value):
if value in ("", None):
return None
try:
return int(value)
except (TypeError, ValueError):
return None
data["pieces"] = _to_int(data.get("pieces"))
data["segment_size"] = _to_int(data.get("segment_size"))
return Product(**data)
def pick_fabric(fields: dict[str, Any]) -> Fabric:
"""从字段字典中提取面料信息"""
data = {k: fields.get(v, "") for k, v in fabric_type_map.items()}
return Fabric(**data)