forked from erp-dev/erp
fix: query param of api_man
This commit is contained in:
@@ -139,6 +139,7 @@ def _map_unit(unit_label: str | None) -> int:
|
||||
'米': basic_models.ProductUnitEnum.METER,
|
||||
'码': basic_models.ProductUnitEnum.YARD,
|
||||
'公斤': basic_models.ProductUnitEnum.KG,
|
||||
'段': basic_models.ProductUnitEnum.SEGMENT,
|
||||
}
|
||||
return mapping.get(unit_label, basic_models.ProductUnitEnum.METER)
|
||||
|
||||
@@ -152,6 +153,19 @@ def _ensure_decimal(value: str | None):
|
||||
return None
|
||||
|
||||
|
||||
def _ensure_int(value):
|
||||
if value is None:
|
||||
return None
|
||||
try:
|
||||
return int(value)
|
||||
except (TypeError, ValueError, InvalidOperation):
|
||||
# 有些值可能是 Decimal 或字符串数字
|
||||
try:
|
||||
return int(Decimal(str(value)))
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _run_fetch(page: int, page_size: int):
|
||||
return asyncio.run(fetch_products_from_mingdaoyun(page=page, page_size=page_size))
|
||||
|
||||
@@ -175,6 +189,12 @@ def _upsert_product(product_data, merchant, category):
|
||||
width_decimal = _ensure_decimal(product_data.width)
|
||||
if width_decimal is not None:
|
||||
defaults['width_size'] = width_decimal
|
||||
pieces_int = _ensure_int(product_data.pieces)
|
||||
if pieces_int is not None:
|
||||
defaults['pieces'] = pieces_int
|
||||
segment_int = _ensure_int(product_data.segment_size)
|
||||
if segment_int is not None:
|
||||
defaults['segment_size'] = segment_int
|
||||
|
||||
product_obj, created = basic_models.Product.objects.get_or_create(
|
||||
merchant=merchant,
|
||||
@@ -387,4 +407,3 @@ def sync_mdy_customers(self, page_size: int = 300, max_pages: int | None = None,
|
||||
}
|
||||
logger.info('明道云客户同步完成: %s', payload)
|
||||
return payload
|
||||
|
||||
|
||||
Reference in New Issue
Block a user